- Home /
Trying to lock camera's Y axis and it's resetting at 0 degrees
So I'm trying to make a basic controller and I'm using Mathf.Clamp() to try to stop the camera from rotating around in circles and now it's just resetting the rotation of the camera every time it hits 0 and I have no idea why.
GIF: https://gyazo.com/ba2b7093225a039dfca980b089298ce8
Code: float h = horizontalSpeed Input.GetAxis("Mouse X"); //float v = verticalSpeed Input.GetAxis("Mouse Y");
transform.Rotate(0, h, 0);
Vector3 rot = playerCamera.transform.eulerAngles;
float mouseY = Input.GetAxis("Mouse Y") * verticalSpeed;
rot.x = Mathf.Clamp(rot.x + mouseY, -limit, limit);
playerCamera.transform.eulerAngles = rot;
Test some numbers in the place of the limit variables and see what happens. $$anonymous$$aybe they cause the problem?
Answer by Zaeran · Feb 10, 2016 at 01:33 PM
I'm guessing that your 'limit' variable is set to 90, so that you can go from -90 to 90?
After you hit zero, the rotation value doesn't go to -1, it goes to 359. That's why it's clamping you back at 90 each time, because it thinks that it's 270 higher than it should be.