- Home /
Object Rotation Limit! (JavaScript)
I already have this code for an object which is able to rotate on its y and z axis.
var speed = 20;
function Update () {
if (Input.GetKey(KeyCode.A))
transform.Rotate(Vector3.forward * speed * Time.deltaTime);
if (Input.GetKey(KeyCode.D))
transform.Rotate(-Vector3.forward * speed * Time.deltaTime);
if (Input.GetKey(KeyCode.W))
transform.Rotate(Vector3.up * speed * Time.deltaTime);
if (Input.GetKey(KeyCode.S))
transform.Rotate(-Vector3.up * speed * Time.deltaTime);
}
Is it possible for me to limit the rotation of the object for each axis, so that the player cannot rotate more than 40 degrees in each angle?
Thanks in advance.
Comment
Best Answer
Answer by abkrivo · Jan 26, 2013 at 05:41 PM
Never mind! I just used the Rotation Constraint preset script that came with Unity!
Where is that script located? I need the same thing as you.
@rockyada In an object menu, select: Add Component>Rotation Constraint. Then, just change the values. That's all.