コード例 #1
0
        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();
        }
        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();
        }
コード例 #3
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();
        }
コード例 #4
0
        public override void UpdateCamera()
        {
            // Get Input
            EasyUnityInput.AppendInput();
            InputValues input = Input.ProcessedInput;

            Input.ClearInput();

            // Handle the rotating to follow the target from behind.
            FollowRotation.UpdateRotation();

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

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

            Target.AddWorldSpaceOffset(screenShakeOffset);

            Vector3 target = Target.GetTarget();

            // 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();
        }
コード例 #5
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();
        }