using static scr_Models; using UnityEngine; public class scr_CameraController : MonoBehaviour { public scr_PlayerController playerController; // create a reference to the player controller public CameraSettingsModel settings; // create a reference to the player settings model private Vector3 targetRotation; public GameObject yGimbal; private Vector3 yGimbalRotation; private void Update() { CameraRotation(); FollowPlayerCameraTarget(); } private void CameraRotation() { var viewInput = playerController.input_View; // sets the value of viewInput to be equal to input_View from the playerController targetRotation.y += (settings.InvertedX ? -(viewInput.x * settings.SensitivityX) : (viewInput.x * settings.SensitivityX)) * Time.deltaTime; // modifies targetRotation's y axis based on viewInput's x transform.rotation = Quaternion.Euler(targetRotation); // sets the rotation of the camera controller to be equal to targetRotation (must convert targetRotation into a quaternion) yGimbalRotation.x += (settings.InvertedY ? (viewInput.y * settings.SensitivityY) : -(viewInput.y * settings.SensitivityY)) * Time.deltaTime; // modifies yGimbalRotation's x axis based on viewInput's y yGimbalRotation.x = Mathf.Clamp(yGimbalRotation.x, settings.ViewClampYMin, settings.ViewClampYMax); // clamps rotation up and down yGimbal.transform.localRotation = Quaternion.Euler(yGimbalRotation); // rotates the yGimbal based on the yGimbalRotation if (playerController.isAimingMode) { var currentRotation = playerController.transform.rotation; // sets the variable of currentRotation to be based on the playerController's current rotation var newRotation = currentRotation.eulerAngles; // makes newRotation equal to currentRotation; by putting .eulerAngles on a quaternion, you can convert it to a vector3 newRotation.y = targetRotation.y; // makes the y (left and right) of newRotation be equal to the y of targetRotation currentRotation = Quaternion.Lerp(currentRotation, Quaternion.Euler(newRotation), settings.CharacterRotationSmoothDamp); // sets currentRotation to lerp to newRotation playerController.transform.rotation = currentRotation; // rotates the player to face the direction of currentRotation } // if isAimingMode is true, makes the player face the direction that the camera is pointing } private void FollowPlayerCameraTarget() { transform.position = playerController.cameraTarget.position; } // makes the CameraController follow the cameraTarget on the playerController }