Hey, I’ve been having some trouble with a quaterion.slerp code. I want the movement of my object to rotate based on the wasd key press. It works, for the most part. However, my object keeps rotating 90 degrees on the z-axis on play?
I thought it was the model having the wrong axis forward, since it was imported from Blender, but that doesn’t seem to have solved my problem. The code I used is below. I’m still a beginner at this stuff, so I’m wondering if it’s something I did wrong?
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, 0f, Input.GetAxis("Vertical") * moveSpeed);
moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(moveDirection), turnSpeed);
controller.Move(moveDirection * Time.deltaTime);