- 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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Quaternion.Slerp problem... 1 Answer

Make Quaternion Slerp happen over a 1 second period 3 Answers

Copy rotation of targetObject to current object with an influence in the range from 0-1. 0 Answers

Transition current camera rotation to 0,0,0 1 Answer

This can't be impossible or? Rotate (flip) smoothly from one point to endpoint on mouseclick. 3 Answers