- Home /
Question by
calmcarrots · Jun 08, 2014 at 04:38 AM ·
rotationsmooth3rd person controller
Player not facing the direction of its movement.
So I am making a 3rd person controller and my player is not smoothly rotating to the direction it is walking in. I want it to be smoothly rotated so it doesnt snap but my player is just not facing the direction it is supposed to face. Here is my code:
if (moveDirection != Vector3.zero)
{
Quaternion rotationDirection = Quaternion.LookRotation(moveDirection);
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, Mathf.Lerp(transform.rotation.y, rotationDirection.eulerAngles.y, 20f * Time.deltaTime), transform.eulerAngles.z);
}
Comment
Best Answer
Answer by robertbu · Jun 08, 2014 at 03:48 PM
You are mixing some things here. transform.rotation is a Quaternion. The values are not angles. Change line 4 to:
transform.rotation = Quaternion.RotateTowards(transform.rotation, rotationDirection, Time.deltaTime * speed);
For an eased rotation, change Quaternion.RotateTowards, to Quaternion.Slerp and adjust speed.
Your answer
Follow this Question
Related Questions
How can I rotate the third person camera Smoothly? 0 Answers
3rd person controller , movement issues 1 Answer
Rotate smoothly an object when key is up 0 Answers
Smooth reset rotation problem 1 Answer