- Home /

# Use Lerp to rotate object

```
void Update () {
transform.Translate (Vector3.right * speed * Time.deltaTime);
if (Input.GetKeyDown (KeyCode.W))
{
transform.localEulerAngles = new Vector3(0,0,90);
}
if (Input.GetKeyDown (KeyCode.D))
{
transform.localEulerAngles = new Vector3(0,0,0);
}
if (Input.GetKeyDown (KeyCode.S))
{
transform.localEulerAngles = new Vector3(0,0,-90);
}
if (Input.GetKeyDown (KeyCode.A))
{
transform.localEulerAngles = new Vector3(0,0,180);
}
}
```

with this simple arrangement i am able to rotate the object but how can i rotate it smoothly.

I can not find lerp function which accepts current rotation and future rotation and some float.

please help.

**Answer** by Baste
·
Dec 06, 2014 at 12:11 PM

I'd go with Quaternion.RotateTowards, as it's nice and compact. Example for W:

```
if (Input.GetKeyDown (KeyCode.W))
{
Quaternion currentRotation = transform.rotation;
Quaternion wantedRotation = Quaternion.Euler(0,0,90);
transform.rotation = Quaternion.RotateTowards(currentRotation, wantedRotation, Time.deltaTime * rotateSpeed);
}
```

Where rotateSpeed is a float variable just like speed. This will work for the majority of cases- lerping takes quite a bit of extra maths to get right if the distance you're going to rotate varies.

**Answer** by b1gry4n
·
Dec 06, 2014 at 11:32 AM

use transform.rotation : http://docs.unity3d.com/ScriptReference/Transform-rotation.html

convert to quaternion (or replace current euler values) : http://docs.unity3d.com/ScriptReference/Quaternion.Euler.html

slerp : http://docs.unity3d.com/ScriptReference/Quaternion.Slerp.html

how to correctly lerp : http://www.blueraja.com/blog/404/how-to-use-unity-3ds-linear-interpolation-vector3-lerp-correctly

difference between lerp and slerp : https://www.youtube.com/watch?v=uNHIPVOnt-Y#t=30

### Your answer

### Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.