How to keep player character facing the direction of travel after movement stops?

Hi
I am new to Unity and am currently building a game which the main character walks around the game area fighting enemies. I have managed to get him moving and animating correctly (mostly) but I cannot seem to get him to keep facing the direction of travel after he stops moving. I have been looking through forums and google for a few days now and have tried various different ways to code this but it just will not work and I need any help I can get!
Not sure how to correctly add code to this but here goes…
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
public float speed = 1f;

Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;

void Awake()
{
    anim = GetComponent<Animator>();
    playerRigidbody = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
    float h = Input.GetAxisRaw("Horizontal");
    float v = Input.GetAxisRaw("Vertical");

    Vector3 movement = new Vector3(h, 0.0f, v);
    transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), 0.15F);
   

    transform.Translate(movement * speed * Time.deltaTime, Space.World);

    Move(h, v);
    Animating(h, v);
}

void Move(float h, float v)
{
    movement.Set(h, 0f, v);

    movement = movement.normalized * speed * Time.deltaTime;

    playerRigidbody.MovePosition(transform.position + movement);
}

void Animating(float h, float v)
{
    bool walking = h != 0f || v != 0f;
    anim.SetBool("IsWalking", walking);
}

}

What is happening at the moment when you stop moving? Errors? Spinning on the spot? something else?

I imagine there may be an issue caused when you stop moving the movement vector is zero, which will not be a valid look at vector for the rotation setting you’re doing. I would suggest first just putting your rotation code inside and if statement that checks the magnitude of the movement and only runs the rotation update if the movement magnitude is greater than zero.

If that doesn’t work, please provide more information about what is happening when you stop moving.