Reputation: 1353
In unity3d, how can I set rotation angle constraints to a sphere along the x and y axis'? For example, if I want the sphere to only rotate up along the x axis 90 degrees, how can I prevent it from going any further than that? I am using a character controller to control my sphere. It can only rotate +/- a certain angle.
Upvotes: 2
Views: 553
Reputation: 298
Before assigning your angles you'll just have to clamp them.
Use
angle = Mathf.Clamp(angle , min , max)
Then you can assign the angle to your transform.localEulerAngles
Upvotes: 1
Reputation: 679
You can access angles that are written in inspector like this:
transform.eulerAngles = new Vector3(x, y, z);
If you want rotation on one axis to be constant just make value of rotation literal.
Upvotes: 3