# How can I slowly rotate a sprite to face its movement direction?

I’m just starting out with all of this & this is a super basic question, but I haven’t been able to find a solution that works anywhere.

I have a 2d sprite which moves around using the in-built physics system & I need it to face the direction it’s moving, but I need it to rotate around slowly not just turn instantly.

Here’s the script as it stands in case that helps:

``````public float movespeed;

private Rigidbody2D rb2d;

void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}

void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(moveHorizontal, moveVertical);
}
``````

Thanks in advance for the help

Try this :

``````IEnumerator Rotator()
{
Quaternion targetRotation = Quaternion.LookRotation(movementDirection);
Quaternion currentRotation = transform.rotation;
for (float i = 0; i < 1.0f; i += Time.deltaTime / timeToRotate)
{
transform.rotation = Quaternion.Lerp(currentRotation,targetRotation,i);
yield return null;
}
}
``````

Here timeToRotate is total time in which you want to rotate sprite to movement direction