How do I make the player rotate towards the moving direction?

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

Here’s how to do it:

You may be able to simply drive transform.forward (or transform.up when in 2D) equal to your movement vector.

Otherwise, use Mathf.Atan2() to derive heading:

Sine/Cosine/Atan2 (sin/cos/atan2) and rotational familiarity and conventions