I want to cap the rotation on my camera
Hello, I have attached my camera to my player so that the camera is following my player. I then created a c# script to rotate the camera according to my Mouse Y axis. After that i tried to cap the rotation to specific angles to prevent a 360° rotation. But it wont work. Here´s my code:
void Update() {
float rotX = -Input.GetAxis("Mouse Y") * 5;
if (rotX < 0 && transform.rotation.eulerAngles.x > -30) {
transform.Rotate(rotX, 0, 0);
}
if (rotX > 0 && transform.rotation.eulerAngles.x < 30)
{
transform.Rotate(rotX, 0, 0);
}
}
Comment
Best Answer
Answer by SirPizza13104 · Jan 22, 2017 at 12:34 PM
Maybe you will find an answer here. Hope it helps.
it works :D thanks this is my code now:
private float rotationX = 0f;
private float sensitivityX = 2f;
void Update() {
lockedRotation();
}
void lockedRotation()
{
rotationX += -Input.GetAxis("$$anonymous$$ouse Y") * sensitivityX;
rotationX = $$anonymous$$athf.Clamp(rotationX, -90, 90);
transform.localEulerAngles = new Vector3(rotationX, transform.localEulerAngles.y, transform.localEulerAngles.z);
}