# Rotate Object Smoothly

hi, i am trying to rotate object to 90 degrees smoothly on swipe
here in my code its rotate instantly, how do i rotate object smoothly at given speed.

``````void Update()
{
if (fingerDown == false && Input.GetMouseButtonDown(0))
{
startPos = Input.mousePosition;
fingerDown = true;
}

if (fingerDown)
{
if (Input.mousePosition.x >= startPos.x + pixelDistToMove)
{
startPos = Input.mousePosition;
Vector3 rotationToAdd = new Vector3(0, 0, 90);
transform.Rotate(rotationToAdd);
fingerDown = false;
}

if (Input.mousePosition.x <= startPos.x - pixelDistToMove)
{
startPos = Input.mousePosition;
Vector3 rotationToAdd = new Vector3(0, 0, -90);
transform.Rotate(rotationToAdd);
fingerDown = false;
}

}

if (fingerDown && Input.GetMouseButtonUp(0))
{
fingerDown = false;
}
}
``````

@Humansquirrel

The easiest solution is to use LERP. You can search for this keyword and you will find tutorials and descriptions.

But, you should check out the Unity’s official description about it:

Basically, you will define the start position, the end position and the value, which defines where you are in the “animation”. This value is between 0 and 1, where 0 is the start position and 1 is the end position.

If you want to more control over how it moves or rotates, like you want to rotate very fast at the beggining and near to the end it should slow down or vice-versa, you should check out and use a Tween library (or write one if you want).

For example: Tween | Animation Tools | Unity Asset Store