Rotating things in Unity

Posted on

in

,

The amount of rotation uses something called ‘Quaternion’. Set one up like so:

newRotation = Quaternion.Euler(0,0,90);

The 3 values are x,y,z. In the example, it rotates 90 degress on the z axis.

Then to animate this rotation, in the Update() function:

transform.rotation = Quaternion.Lerp (transform.rotation,newRotation,Time.deltaTime * someSpeedVar);

You can also use ‘Slerp’ instead of ‘Lerp’ if the rotation looks weird, but lerp has better performance.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

About me

Mark Wong is a front end developer with 10+ years experience. Most of his knowledge of HTML5, CSS and Js is self taught.

Calendar

October 2024
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031