void Start()
 {
     CameraTransform.Position = HoldingPosition.position;
     CameraTransform.LookAt(Target.GetTarget());
     _previousDistance = Target.GetDistanceFromTarget();
 }
コード例 #2
0
        public override void UpdateCamera()
        {
            // Get Input
            EasyUnityInput.AppendInput();
            InputValues input = Input.ProcessedInput;

            Input.ClearInput();

            // Handle Rotating
            Rotation.UpdateAutoRotate();
            Rotation.UpdateSmartFollow();

            if (input.Horizontal.HasValue)
            {
                Rotation.RotateHorizontally(input.Horizontal.Value);
            }
            if (input.Vertical.HasValue)
            {
                Rotation.RotateVertically(input.Vertical.Value);
            }

            Rotation.CheckRotationDegreesEvents();

            // Apply target offset modifications
            Vector3 headbobOffset = Headbob.GetHeadbobModifier(_previousDistance);

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

            Target.AddWorldSpaceOffset(screenShakeOffset);

            Vector3 target = Target.GetTarget();

            // Handle Cursor
            Cursor.SetCursorLock();

            // Hanlde Zooming
            if (input.ZoomIn.HasValue)
            {
                DesiredDistance = Mathf.Max(DesiredDistance + input.ZoomIn.Value, 0);
                DesiredDistance = Mathf.Max(DesiredDistance, MinZoomDistance);
            }
            if (input.ZoomOut.HasValue)
            {
                DesiredDistance = Mathf.Min(DesiredDistance + input.ZoomOut.Value, MaxZoomDistance);
            }

            // Set Camera Position
            float desired    = DesiredDistance;                                                                                 // Where we want the camera to be
            float calculated = ViewCollision.CalculateMaximumDistanceFromTarget(target, Mathf.Max(desired, _previousDistance)); // The maximum distance we calculated we can be based off collision and preference
            float zoom       = Zoom.CalculateDistanceFromTarget(_previousDistance, calculated, desired);                        // Where we want to be for the sake of zooming

            Vector3 zoomDistance = CameraTransform.Forward * zoom;

            CameraTransform.Position = target - zoomDistance; // No buffer if the buffer would zoom us in past 0.

            float actual = Vector3.Distance(CameraTransform.Position, target);

            _previousDistance = actual;
            Target.ClearAdditionalOffsets();
        }