- Home /
Question by
mentalshark · Mar 31, 2014 at 11:25 PM ·
rotationangleclamplimit
How do I limit the vertical rotation of a camera?
I have been having issues trying to limit the rotation of my camera on the x axis. I want to learn how to code my own first person view script and do not want to use unity's pre built assets. I have looked into Mathf.Clamp but couldn't get that to work, so I tried to use euler angles. I just want the camera to only be able to look up a certain amount of degrees, and the same when you look down. Can someone please help. (javascript please.)
pragma strict
var YMouseSpeed : float = 10; var min : float = 0; var max : float = 90; var angle : float = 0;
function Update () {
transform.Rotate(Vector3(Input.GetAxis("Mouse Y") * Time.deltaTime * YMouseSpeed * -10, 0, 0));
if (angle < min)
angle = min;
if (angle > max)
angle = max;
transform.eulerAngles.x = angle;
}
Comment
Your answer
Follow this Question
Related Questions
Align GameObject to Terrain angle 2 Answers
Clamp rotation of a GameObject 1 Answer
limiting rotation to solid angle 5 Answers
How to clamp Lookat? 2 Answers