so I want to clamp the rotation so players don’t do summersaults.
The issue is no matter what values I place in the clamp feature of my code, i can never get it to be right.
I must be doing something wrong or not understanding it.
if (turretMode)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
//obtain the forward direction of main camera
Vector3 cameraForward = Camera.main.transform.forward;
//Obtain the center point for the camera from prefab
turretCameraLocation = turretSelected.gameObject.transform.GetChild(0).GetChild(0);
//move camera to the centerpoint
transform.position = turretCameraLocation.position;
//obtain direction of centr point
Vector3 turretCameraForward = turretCameraLocation.forward;
//rotate in the direction the camera is forward
transform.rotation = Quaternion.LookRotation(turretCameraForward, Vector3.up);
//mouse inputs based on sensitivity
yaw += Input.GetAxis("Mouse X") * mouseSensitivity;
pitch -= Input.GetAxis("Mouse Y") * mouseSensitivity;
//WHY WONT YOU WORK?!?!?!?!
pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
//smoothing mouse rotation
currentRotation = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
//rotating camera basd on the rotation from mouse inputs
transform.eulerAngles = currentRotation;
//obtain weapon part within prefab
turretWeapon = turretSelected.gameObject.transform.GetChild(0).GetChild(1).gameObject;
//rotate towards the camera forward direction
turretWeapon.transform.rotation = Quaternion.LookRotation(cameraForward, Vector3.up);
}
}