Question by
voltage · Sep 21, 2016 at 05:00 PM ·
camerarotationmathf.clampclamped rotation
How to Properly Mathf.Clamp an X Rotation for Camera?
I've been at this longer than I care to admit. It's pretty frustrating. I got the code to work, however it would teleport back to max value when going down. (That's because I can't go under 0 on rotation, it turns into 360 instead). How do I fix this?!?
//Clamps didn't work because Rot X would turn into 360 instead of -40f.
behaveList[1].transform.localEulerAngles = new Vector3(
Mathf.Clamp(behaveList[1].transform.localEulerAngles.x,
-40f, 40f), 0, 0);
//Motion
if (Input.GetAxis("Mouse Y") > .1f)
{
behaveList[1].transform.Rotate(new Vector3(70, 0, 0) * Time.deltaTime, Space.Self);
}
if (Input.GetAxis("Mouse Y") < -.1f)
{
behaveList[1].transform.Rotate(new Vector3(-70f, 0, 0) * Time.deltaTime, Space.Self);
}
Comment
Your answer
Follow this Question
Related Questions
Clamping a camera with weird results 0 Answers
How can I use Mathf.Clamp? 1 Answer
Smooth Camera Mouse Clamp, Damp 0 Answers
Need help clamping rotations to a range 0 Answers
Camera X Rotation Problems 0 Answers