Rotating my player smoothly

Hi all,

I want to rotate my character smoothly from GetAxis input. At the moment the rotation axis seems to only have about 16 points of rotation, so there is small snapping between these points as my character adjusts his trajectory in movement.

Here is my code at the moment:

//        Get players input axis'
        xSpeed = Input.GetAxis("Horizontal");
        zSpeed = Input.GetAxis("Vertical");



//         Get the player direction vector
        Vector3 velocityAxis = new Vector3(xSpeed, 0, zSpeed);
   
       
   
//         Rotate the movement vector based on the camera - makes player movement relative to the camera view.
        velocityAxis = Quaternion.AngleAxis (Camera.main.transform.eulerAngles.y, Vector3.up) * velocityAxis;
       
//        Rotate the player's model to show direction
        if (velocityAxis.magnitude > 0)
        {
            transform.rotation = Quaternion.LookRotation (velocityAxis);
        }

Can anyone help?

Big thanks!

Try :

//rotate along y axis 
transform.Rotate(0,xSpeed * Time.deltaTime,0);

He just runs in one direction now, whichever way is pushed.

Use Mathf.LerpAngle.

Excuse me but I’m a beginner. Could you help with how that would work in this script?

transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(velocityAxis), Time.time * speed);

Paste it in your last if, you can also use Quaternion.Lerp for better performance.

Fantastic!! Thanks so much. It didn’t work at first, but then I changed Time.time for Time.deltaTime and now my player is moving around the level like a dream. Cheers mate.