< Back to Game Dev, Unity

Rotating things in Unity

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.

 

Be Sociable, Share!

Leave a Reply

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