When the unit rotates exactly 180 degrees Mathf.Lerp
seems to provide the wrong results. I noticed this in both the MoveAction
and ShootAction
.
In the case of the MoveAction
, the unit will walk backward for a moment and then quickly rotate to face the target direction.
In the case of the ShootAction
, at least in my implementation, the unit doesn’t move for the first half of the shoot state timer. At the halfway point the unit immediately snaps to the target direction for the second half of the shoot state timer.
After some research, I found that Mathf.Slerp
may be more appropriate for smoothing rotation. I changed my implementations to use Mathf.Slerp
and this appears to have corrected the issue with rotating precisely 180 degrees.
I just wanted to call out this quirk in case there is good reason to use Mathf.Slerp
for interpolation of rotation in general as opposed to Mathf.Lerp
.
I found these two diagrams that make sense to me. However, as a beginner, I’m not sure if this accurately represents the difference between these two functions in the context of rotation interpolation.
Mathf.Lerp:
Mathf.Slerp:
We should be able to reproduce this issue by placing a unit on a grid position such as (0, 1)
, facing (0, 2)
, then attempting to move the unit to (0, 0)
.