public void Init(Transform target = null) { //If there is no target, create a temporary target at 'distance' from the cameras current viewpoint if (this.target) { Destroy(this.target.gameObject); } GameObject go = new GameObject("Cam Target"); go.transform.position = (target) ? target.transform.position : transform.position + (transform.forward * distance); this.target = go.transform; if (this.transform.parent) { this.target.transform.parent = this.transform.parent; } Distance = Vector3.Distance(transform.position, this.target.position); currentDistance = distance; desiredDistance = distance; //be sure to grab the current rotations as starting points. position = transform.position; rotation = transform.rotation; focus = FocusObject.Target; }
public void InitMove(Camera camera, GameObject[] targets) { if (_moveCamera) { Debug.LogWarning("Camera already moving"); return; } if (camera == null) { Debug.LogWarning("need a Camera to work"); return; } if (targets.Length == 0) { Debug.LogWarning("need targets to focus"); return; } _camera = camera; for (int i = 0; i < targets.Length; i++) { FocusObject focusObj = new FocusObject(); focusObj.Obj = targets [i]; focusObj.BoundingBoxPoints = GetBoundingBoxPoints(targets [i]); _targets.Add(focusObj); } _initPos = _camera.transform.position; CalcMove(); }
/// <summary> /// Constructor for camera /// </summary> /// <param name="vp">used to gather information about the size of the window</param> /// <param name="focus">The object you want the camera to focus on</param> /// <param name="zooming">Used to zoom the camera in or out</param> public Camera(Viewport vp, FocusObject focus, Vector2 zooming) { this.focus = focus; this.zooming = zooming; this.vp = vp; Position = new Vector2(0, 0); }
public void interactWithObject(Transform t) { FocusObject interagable = t.GetComponent <FocusObject>(); if (interagable != null) { target_object = t.gameObject; interface_control.enableExitArrow(); interagable.focus(interagable.rotate_when_focus); } }
void hackClick() { RaycastHit hit; if (Physics.Raycast(mouse_ray, out hit)) { FocusObject obj = hit.collider.GetComponent <FocusObject>(); if (obj != null) { obj.hackObject(); object_hacked = obj; } } }
// Called when a portal is triggered. public static void ChangeRoom(Room newRoom, Vector2 newPosition) { if (newRoom != CurrentRoom) { // Clear out the lists because they will be repopulated for the new room. ToUpdate.Clear(); ToDraw.Clear(); InputManager.RegisteredActors.Clear(); CurrentRoom = newRoom; FocusObject.OnCreate(); // This is normally called in the constructor to add the object to lists. } FocusObject.Body.Position = newPosition; }
/* * Camera logic on LateUpdate to only update after all character movement logic has been handled. */ void LateUpdate() { if (Input.GetMouseButtonDown(1)) { focus = FocusObject.This; } if (Input.GetMouseButtonDown(2) || Input.GetMouseButtonUp(1)) { focus = FocusObject.Target; } // If Control and Alt and Middle button? ZOOM! if (Input.GetMouseButton(2) && Input.GetKey(KeyCode.LeftAlt) && Input.GetKey(KeyCode.LeftControl)) { desiredDistance -= Input.GetAxis("Mouse Y") * Time.deltaTime * zoomRate * 0.125f * Mathf.Abs(desiredDistance); } // If middle mouse and left alt are selected? ORBIT else if (Input.GetMouseButton(2) && Input.GetKey(KeyCode.LeftAlt)) { xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f; yDeg -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; //Clamp the vertical axis for the orbit yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit); } // otherwise if middle mouse is selected, we pan by way of transforming the target in screenspace else if (Input.GetMouseButton(2)) { //grab the rotation of the camera so we can move in a psuedo local XY space target.rotation = transform.rotation; xDel += Input.GetAxis("Mouse X") * panSpeed; yDel += Input.GetAxis("Mouse Y") * panSpeed; } // First Person like flying controls else if (Input.GetMouseButton(1)) { target.rotation = transform.rotation; zDel -= Input.GetAxis("Vertical") * moveSpeed; xDel -= Input.GetAxis("Horizontal") * moveSpeed; t_xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f; t_yDeg -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; t_yDeg = ClampAngle(t_yDeg, yMinLimit, yMaxLimit); } ////////Orbit Position // affect the desired Zoom distance if we roll the scrollwheel desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance); //clamp the zoom min/max desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance); // For smoothing of the zoom, lerp distance currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * zoomDampening); switch (focus) { case FocusObject.Target: // apply rotation with lerp. ApplyRotation(); break; case FocusObject.This: // apply target rotation with lerp. ApplyTargetRotation(); break; } // apply the pan with lerp. var xOffset = Mathf.Lerp(0, xDel, Time.deltaTime * zoomDampening); xDel -= xOffset; var yOffset = Mathf.Lerp(0, yDel, Time.deltaTime * zoomDampening); yDel -= yOffset; var zOffset = Mathf.Lerp(0, zDel, Time.deltaTime * zoomDampening); zDel -= zOffset; target.Translate(Vector3.right * -xOffset); target.Translate(Vector3.forward * -zOffset); target.Translate(transform.up * -yOffset, Space.World); // calculate position based on the new currentDistance position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset); transform.position = position; }
/* * Camera logic on LateUpdate to only update after all character movement logic has been handled. */ void LateUpdate() { if (Input.GetMouseButtonDown(2) || Input.GetMouseButtonUp(1)) { focus = FocusObject.Target; } // If Control and Alt and Middle button? ZOOM! if (Input.GetMouseButton(2) && Input.GetKey(KeyCode.LeftAlt) && Input.GetKey(KeyCode.LeftControl)) { desiredDistance -= Input.GetAxis("Mouse Y") * Time.deltaTime * zoomRate * 0.125f * Mathf.Abs(desiredDistance); } // otherwise if middle mouse is selected, we pan by way of transforming the target in screenspace else if (Input.GetMouseButton(2)) { //grab the rotation of the camera so we can move in a psuedo local XY space target.rotation = transform.rotation; xDel += Input.GetAxis("Mouse X") * panSpeed; yDel += Input.GetAxis("Mouse Y") * panSpeed; } ////////Orbit Position // affect the desired Zoom distance if we roll the scrollwheel desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance); //clamp the zoom min/max desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance); // For smoothing of the zoom, lerp distance currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * zoomDampening); switch (focus) { case FocusObject.Target: // apply rotation with lerp. ApplyRotation(); break; case FocusObject.This: // apply target rotation with lerp. ApplyTargetRotation(); break; } // apply the pan with lerp. var xOffset = Mathf.Lerp(0, xDel, Time.deltaTime * zoomDampening); xDel -= xOffset; var yOffset = Mathf.Lerp(0, yDel, Time.deltaTime * zoomDampening); yDel -= yOffset; var zOffset = Mathf.Lerp(0, zDel, Time.deltaTime * zoomDampening); zDel -= zOffset; target.Translate(Vector3.right * -xOffset); target.Translate(Vector3.forward * -zOffset); target.Translate(transform.up * -yOffset, Space.World); Camera.main.orthographicSize = currentDistance; // calculate position based on the new currentDistance position = target.position - (rotation * Vector3.forward * currentDistance * 10 + targetOffset); transform.position = position; }