public override void UpdateCamera()
        {
            Rotation.UpdateAutoRotate(false, null);
            Rotation.CheckRotationDegreesEvents();

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

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

            Target.AddWorldSpaceOffset(screenShakeOffset);

            // Get target
            Vector3 target = Target.GetTarget();
            float   actual = _previousDistance;

            // Set Camera Position
            float desired    = DesiredDistance;                                                                      // Where we want the camera to be
            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 - CameraTransform.Forward * zoom;                                      // Set the position of the transform

            _previousDistance = Target.GetDistanceFromTarget();
            Target.ClearAdditionalOffsets();
        }
Пример #2
0
        public override void UpdateCamera()
        {
            // Get Input
            EasyUnityInput.AppendInput();
            InputValues input = Input.ProcessedInput;

            Input.ClearInput();

            // Handle Rotating
            Rotation.UpdateAutoRotate(false, null);
            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);

            // 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);
            }

            // Get target
            Vector3 target = Target.GetTarget();
            float   actual = _previousDistance;

            // Set Camera Position
            float desired    = DesiredDistance;                                                                      // Where we want the camera to be
            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 - CameraTransform.Forward * zoom;                                      // Set the position of the transform

            _previousDistance = Target.GetDistanceFromTarget();
            Target.ClearAdditionalOffsets();
        }
Пример #3
0
        public override void UpdateCamera()
        {
            // Get Input
            EasyUnityInput.AppendInput();
            InputValues input = Input.ProcessedInput;

            Input.ClearInput();

            Rotation.UpdateAutoRotate(true, Target.Target);
            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;

            if (canUpdateCameraPosition)
            {
                if (smoothCameraPosition && !splineFollow.followSpline & !cameraWindow.enabled)
                {
                    CameraTransform.Position = Vector3.Lerp(CameraTransform.Position, target - zoomDistance, 0.1f); // No buffer if the buffer would zoom us in past 0.
                }
                else if (splineFollow.followSpline)
                {
                    if (splineFollow.targetSpline != null)
                    {
                        float   percent;
                        Vector3 point1         = splineFollow.targetSpline.GetPoint(0);
                        Vector3 point2         = splineFollow.targetSpline.GetPoint(1);
                        Vector3 targetToFollow = new Vector3(Target.Target.position.x, 0, Target.Target.position.z);

                        point1 = new Vector3(point1.x, 0, point1.z);
                        point2 = new Vector3(point2.x, 0, point2.z);

                        float minDistance = 0;
                        float maxDistance = Vector3.Distance(point1, point2);

                        float distance = Vector3.Distance(targetToFollow, point2);

                        Vector3 targetPos = target - zoomDistance;

                        //Calculate new position based on target X, camera Y and Z
                        percent = Mathf.InverseLerp(maxDistance, minDistance, distance) + splineFollow.targetSpline.compensationConstant;

                        //Update axis for spline follow
                        if (splineFollow.followOnXAxis)
                        {
                            targetPos.x = splineFollow.targetSpline.GetPoint(percent).x;
                        }

                        if (splineFollow.followOnYAxis)
                        {
                            targetPos.y = splineFollow.targetSpline.GetPoint(percent).y;
                        }

                        if (splineFollow.followOnZAxis)
                        {
                            targetPos.z = splineFollow.targetSpline.GetPoint(percent).z;
                        }

                        if (cameraWindow.enabled)
                        {
                            CameraTransform.Position = CurbCamera(targetPos);
                        }
                        else
                        {
                            CameraTransform.Position = targetPos;
                        }
                    }
                }
                else if (cameraWindow.enabled && !splineFollow.followSpline)
                {
                    CameraTransform.Position = CurbCamera(target - zoomDistance);
                }
                else
                {
                    CameraTransform.Position = target - zoomDistance;
                }
            }
            float actual = Vector3.Distance(CameraTransform.Position, target);

            _previousDistance = actual;
            Target.ClearAdditionalOffsets();
        }