How to stop flipping the Y rotation back to zero?

Hey guys,

I am making a player movement and freelook camera. At the moment when the player stands still you can look around the player, when the player moves you can also change direction of the player movement with the camera.

How ever when you stand still the player Y rotation will be flipped back to zero. What I want is to make the player look forward with his last Y rotation value of the movement. Any idea how not make the Y rotation flipping back to zero when player stands stile, while meantaning the freelook around the player when movement <= 0.1f?

    public class PlayerController : MonoBehaviour
    {
        public float speed;
        public float rotationSpeed;

        private Rigidbody m_Rb;
        private Vector3 m_Movement;
        private Camera m_MainCamera;

        private void Awake()
        {
            m_Rb = GetComponent<Rigidbody>();
            m_MainCamera = Camera.main;
        }

        void FixedUpdate()
        {
            float horizontalInput = Input.GetAxisRaw("Horizontal");
            float verticalInput = Input.GetAxisRaw("Vertical");

            Debug.Log(m_Movement.magnitude);

            m_Movement.Set(horizontalInput, 0, verticalInput);
            m_Movement.Normalize();

            {
                Quaternion camRotation = m_MainCamera.transform.rotation;
                Vector3 targetDirection = camRotation * m_Movement;
                targetDirection.y = 0;

                m_Rb.MovePosition(m_Rb.position + targetDirection.normalized * speed * Time.fixedDeltaTime);
                m_Rb.MoveRotation(Quaternion.Euler(0, camRotation.eulerAngles.y, 0));

                if (m_Movement.magnitude <= 0.1f)
                {
                    m_Rb.MoveRotation(Quaternion.Euler(0, 0, 0));
                }
            }
        }
    }

i also had this problem, this code from my game might help:

note: it only updates the rotation when moving

 private void FixedUpdate()
    {

        move = new Vector2(js.Horizontal, js.Vertical); //js is joystick

        rb.velocity = new Vector2(move.x * ms, move.y * ms);
        if (move != Vector2.zero)  //this is what you need
        {
            transform.up = move;
        }

    }