Example #1
0
        /// <summary>
        /// Handles following the target. During its computation disables character collider,
        /// to remove bumping.
        /// </summary>
        /// <param name="cam">PickerCamera which calls this update</param>
        public override void Update(PickerCamera cam)
        {
            Collider c = cam.Target.GetComponent <Collider>();

            // Ignore collision for target on CharacterController.Move() or for assigning rotation
            if (c != null)
            {
                c.enabled = false;
            }

            Quaternion lookRotation = Quaternion.LookRotation(cam.Target.transform.forward, Vector3.up);

            // Rotate Camera
            m_AngleXAdditionDeg = lookRotation.eulerAngles.x;
            m_AngleYAdditionDeg = lookRotation.eulerAngles.y;
            base.Update(cam);
            // Rotate forward
            if (cam.MoveEnabled && Input.GetKey(KeyCode.E))
            {
                cam.transform.rotation = Quaternion.Lerp(cam.transform.rotation, lookRotation, Time.deltaTime * 5.0f);
                m_AngleXDeg            = 0.0f;
                m_AngleYDeg            = 0.0f;
            }
            position = cam.Target.transform.position + (cam.Target.transform.forward - Vector3.up) * 0.25f;

            MoveCamera(cam);

            // Enable collision for others
            if (c != null)
            {
                c.enabled = true;
            }
        }
 public override short PanningInput()
 {
     if (PickerCamera.MouseButtonDown(2))
     {
         return(InputStart);
     }
     else if (Input.GetMouseButton(2))
     {
         return(InputNow);
     }
     else if (Input.GetMouseButtonUp(2))
     {
         return(InputEnd);
     }
     else
     {
         return(InputNone);
     }
 }
Example #3
0
 // Update is called once per frame
 public override void Update(PickerCamera cam)
 {
     base.Update(cam);
     cam.transform.position = cam.Target.transform.position;
     cam.transform.rotation = cam.Target.transform.rotation;
 }
Example #4
0
        /// <summary>
        /// Enables movement
        /// above terrain in the same altitude using WASD, allows using mouse
        /// scroll to zoom and look towards target using R.
        /// </summary>
        /// <param name="cam">PickerCamera which called the update</param>
        public override void Update(PickerCamera cam)
        {
            // share position and rotation with another states
            m_AngleXDeg = cam.transform.rotation.eulerAngles.x;
            if (m_AngleXDeg > 90.0f)
            {
                m_AngleXDeg -= 360.0f;
            }
            m_AngleYDeg = cam.transform.rotation.eulerAngles.y;
            position    = cam.transform.position;

            // Rotate Camera
            base.Update(cam);

            // Handle movement
            float x  = 0;
            float y  = 0;
            float up = cam.MoveEnabled && Input.GetKey(KeyCode.Space) ? climbSpeedM : 0;

            if (cam.MoveEnabled)
            {
                x = Input.GetAxis("Horizontal");
                y = Input.GetAxis("Vertical");
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    up = -up;
                }
            }
            float scroll = Input.GetAxis("Mouse ScrollWheel");

            if (PickerCamera.MouseOverGui() || !cam.MoveEnabled)
            {
                scroll = 0.0f;
            }

            // Move camera in XZ
            if (cam.MoveEnabled)
            {
                Ray        ray = cam.Camera.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                // Change position only in xz
                if (scroll > 0.0f && Physics.Raycast(ray, out hit, 30000.0f, LayerMask.GetMask(Utility.Constants.LAYER_TERRAIN)))
                {
                    float zoomSpeed = (hit.point - ray.origin).magnitude;
                    zoomSpeed = Mathf.Min(Mathf.Max(350.0f, zoomSpeed), 1000.0f);
                    position += ((cam.transform.right.xz().ToVector3xz() * x + cam.transform.forward.xz().ToVector3xz() * y) * flySpeedM + scroll * (hit.point - ray.origin).normalized * zoomSpeed + cam.transform.up * up) * Time.deltaTime;
                }
                else
                {
                    position += ((cam.transform.right.xz().ToVector3xz() * x + cam.transform.forward.xz().ToVector3xz() * y) * flySpeedM + scroll * cam.transform.forward * zoomSpeedM + cam.transform.up * up) * Time.deltaTime;
                }
            }

            // Rotate towards target
            if (cam.Target != null)
            {
                if (cam.MoveEnabled && Input.GetKeyDown(KeyCode.R))
                {
                    Vector3 newDir = cam.Target.transform.position - position;
                    position = -(newDir).normalized * Mathf.Min(followDistanceM, newDir.magnitude) + cam.Target.transform.position;
                    cam.transform.rotation = Quaternion.LookRotation(newDir);
                    m_AngleXDeg            = cam.transform.rotation.eulerAngles.x;
                    m_AngleYDeg            = cam.transform.rotation.eulerAngles.y;
                }
            }
            MoveCamera(cam);
        }