I’m trying to rotate the player character towards the direction they are moving smoothly. I’m rotating the player once to align to the ground and another time to face the movement direction. This works correctly, but when I use Quaternion.Slerp, the rotation is “choppy” and does not work as intented.
All Lerps should have the following form : initial value, end value, a timer going from 0 to 1.
No multiplying the timer with delta time and changing the initial value every frame and other bullshit like that, that unfortunately Unity also likes to teach in its tutorials.
The third term of any Slerp/Lerp needs to go from 0 to 1 smoothly (or from 1 to 0).
That’s how Slerp/Lerp works. If you don’t “get” this, focus on it until you do.
NOW… armed with that knowledge, reason about what term you’re passing in:
and you can see it doesn’t make sense because it does not go from 0 to 1.
Slerp/Lerp is completely stateless. Nothing you have done before matters. Every computation is 3 values in, one value out. ALWAYS.
So, going back to my first post: make something that smoothly goes from 0 to 1, using the technique above.
Take the output of that thing (eg, the “current quantity”) and use it in your Slerp/Lerp.
EDIT: looking at your problem space, Slerp/Lerp isn’t going to be useful. You already know the direction TO face (that’s the “desired”), now track the direction you ARE facing (that’s the “current”) and go implement the code contained in the gist above. Be sure you use Mathf.MoveTowardsAngle(), as already noted in the example code provided above.
I see that the code you linked is for angles / floats, while I am trying to rotate a quaternion. Is there a quaternion equivalent (RotateTowards maybe?), or do I need to use angles instead?
EDIT: Also while I don’t doubt that using Slerps in the way you described is not ideal, I think the issue lies elsewhere. I just copy pasted the code in another project and it appears to work.
EDIT 2: just kidding it still doesn’t work, only in a different way.