- Home /
Clamp issue
This is the code-snippet that has issues: float sensitivity = 3.0; float looker = -Input.GetAxis("Mouse Y") * sensitivity; if (looker != 0) { var clampedX = Mathf.Clamp(cam.transform.eulerAngles.x + looker,-89,70); cam.transform.eulerAngles = new Vector3(clampedX, cam.transform.eulerAngles.y, 0); }
While the variable cam is a Camera
So the issue here is that if i now move the camera down with this script it's working normaly, but when I try to look up, the Mathf.Clamp does sh*t, and moves the camera back to x=70. Can you tell me what I did wrong here? Thanks in advance!
Answer by M1ngXU · Feb 14 at 05:56 PM
the eulerAngles of a transform are always between 0 and 360, so ...x + looker
won't get far below 0. you should substract 180 first or something similar ...
Your answer
Follow this Question
Related Questions
Bizzare problem with limiting camera veritcal rotation 2 Answers
How to Math.f Clamp this 0 Answers
I can't figure out how to clamp it 2 Answers
Clamping RotateAround 1 Answer
Rotating and orbiting an game object with a stop angle 0 Answers