Hello! I am trying to create FPS character scripts from scratch so I can have better control over how the character moves. The movement script worked better than I initially thought it would, though now I have hit a wall. While trying to program the camera movement, I found that the camera can rotate forever on it’s X axis. I tried using a clamp, but I haven’t worked much with rotations, so this is new territory. I’ve looked all over this forum and over Stack Overflow and am having trouble fitting the clamp methods into the context of the script I have. It may be something simple and I may just be ignorant of how to go about it, but any help is greatly appreciated!
Here is the script:
public class CharacterCam : MonoBehaviour
{
public GameObject playerCam;
public float Sensetivity = 10.0f;
public float MaxCameraRotation;
public float MinCameraRotation;
private Vector3 rotatePlayerDir;
private Vector3 rotateCamDir;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update()
{
rotatePlayerDir = new Vector3(0, Input.GetAxis("Mouse X"));
rotatePlayerDir = rotatePlayerDir * Sensetivity;
rotateCamDir = new Vector3(Input.GetAxis("Mouse Y"), 0);
rotateCamDir = rotateCamDir * Sensetivity * -1.0f;
transform.Rotate(rotatePlayerDir * Time.deltaTime);
playerCam.transform.Rotate(rotateCamDir * Time.deltaTime);
}
}
I’ve tried many different things, but none have given me any results other than completely limiting the X rotation altogether.