Player character rotates to only look in 90 degees when stopped

Hey everyone, I really new to unity and am having a problem with getting my player character to continue to face the direction is traveled. It faces the right way when moving, but then snaps 90 degree left, right, forward, or back. I’m attempting to use the Character Controller for scripting this but the rotation has me stuck. Thanks.

public class ChefMovement : MonoBehaviour
{
    public float moveSpeed;
    CharacterController ch;

    // Start is called before the first frame update
    void Start()
    {
        ch = GetComponent<CharacterController>();
        
    }

    // Update is called once per frame
    void Update()
    {
        float x = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
        float z = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
        Vector3 movement = new Vector3(x,0,z);

        ch.Move (movement);

        if (movement != Vector3.zero) {
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), 0.15F);

        }

    
    }
}

205435-rotation-gif.gif

1 Answer

1

I would guess this is just that as you release the move keys, you are briefly still holding just one of them, so the character snaps to that direction. You could try using getaxisraw too, as this will give more accurate controls than getaxis. You could also try lowering the T value at the end of the slerp, as this will make the turn smoother/less immediate.

The T value was the issue. I lowered it all the way to .01f and now its great