public override void UpdateCamera()
        {
            Vector3 lockTarget = LockTarget.GetTarget();

            Vector3 headbobOffset = Headbob.GetHeadbobModifier(_previousDistance);

            Target.AddWorldSpaceOffset(headbobOffset);
            Vector3 screenShakeOffset = ScreenShake.GetShaking();

            Target.AddWorldSpaceOffset(screenShakeOffset);

            Vector3 target = Target.GetTarget(lockTarget);

            Vector3 direction = lockTarget - target;

            float desired    = DesiredDistance;                                                                      // Where we want the camera to be
            float actual     = Vector3.Distance(CameraTransform.Position, target);                                   // Where the camera physically is right now
            float calculated = ViewCollision.CalculateMaximumDistanceFromTarget(target, Mathf.Max(desired, actual)); // The maximum distance we calculated we can be based off collision and preference
            float zoom       = Zoom.CalculateDistanceFromTarget(actual, calculated, desired);                        // Where we want to be for the sake of zooming

            CameraTransform.Position = target - direction.normalized * zoom;                                         // Set the position of the transform
            CameraTransform.LookAt(target);

            _previousDistance = Vector3.Distance(CameraTransform.Position, target);
            Target.ClearAdditionalOffsets();
            LockTarget.ClearAdditionalOffsets();
        }
        public override void UpdateCamera()
        {
            // Apply target offset modifications
            Vector3 headbobOffset = Headbob.GetHeadbobModifier(_previousDistance);

            Target.AddWorldSpaceOffset(headbobOffset);
            Vector3 screenShakeOffset = ScreenShake.GetShaking();

            Target.AddWorldSpaceOffset(screenShakeOffset);

            // Handle Cursor
            Cursor.SetCursorLock();

            // Get target
            Vector3 target = Target.GetTarget();

            float actualDistance = Target.GetDistanceFromTarget();

            // -- Set camera position and rotation
            CameraTransform.Position = HoldingPosition.position; // First move it to the holding position
            CameraTransform.LookAt(target);                      // Look at the target from the perspective of the holding position. Now we have the proper rotation in the virtual transform.

            // Set Camera Position
            float desiredDistance    = Vector3.Distance(target, HoldingPosition.position);                                                   // The distance between the hold position and the target
            float calculatedDistance = ViewCollision.CalculateMaximumDistanceFromTarget(target, Mathf.Max(desiredDistance, actualDistance)); // The maximum distance we calculated we can be based off collision and preference
            float zoom = Zoom.CalculateDistanceFromTarget(actualDistance, calculatedDistance, desiredDistance);                              // Where we want to be for the sake of zooming

            CameraTransform.Position = target - CameraTransform.Forward * zoom;                                                              // Set the position of the transform

            _previousDistance = Target.GetDistanceFromTarget();
            Target.ClearAdditionalOffsets();
        }
예제 #3
0
        private void UpdateTarget()
        {
            if (!m_target || m_target.IsDead)
            {
                ReleaseTarget();
                return;
            }

            var pos = m_target.transform.position + (Vector3.up * 4f) + (m_target.transform.forward * -6f);

            FreeCamera.transform.position = pos;
            CameraTransform.position      = pos;

            FreeCamera.transform.LookAt(m_target.transform);
            CameraTransform.LookAt(m_target.transform);
        }
 void Start()
 {
     CameraTransform.Position = HoldingPosition.position;
     CameraTransform.LookAt(Target.GetTarget());
     _previousDistance = Target.GetDistanceFromTarget();
 }