Example #1
0
 private void UpdateTilt()
 {
     if (firstPersonCamera != null)
     {
         firstPersonCamera.SetPitch(actualTilt);
     }
 }
Example #2
0
        /**
         * <summary>Sets the tilt of a first-person camera.</summary>
         * <param name = "lookAtPosition">The point in World Space to tilt the camera towards</param>
         * <param name = "isInstant">If True, the camera will be rotated instantly</param>
         */
        public void SetTilt(Vector3 lookAtPosition, bool isInstant)
        {
            if (firstPersonCameraTransform == null || firstPersonCamera == null)
            {
                return;
            }

            if (isInstant)
            {
                Vector3 lookDirection = (lookAtPosition - firstPersonCameraTransform.position).normalized;
                float   angle         = Mathf.Asin(lookDirection.y) * Mathf.Rad2Deg;
                firstPersonCamera.SetPitch(-angle);
            }
            else
            {
                // Base the speed of tilt change on how much horizontal rotation is needed

                Quaternion oldRotation = firstPersonCameraTransform.rotation;
                firstPersonCameraTransform.LookAt(lookAtPosition);
                float targetTilt = firstPersonCameraTransform.localEulerAngles.x;
                firstPersonCameraTransform.rotation = oldRotation;
                if (targetTilt > 180)
                {
                    targetTilt = targetTilt - 360;
                }
                firstPersonCamera.SetPitch(targetTilt, false);
            }
        }