简体   繁体   中英

Rotation angle constraints in Unity3d?

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM