Lerp/Slerp vs. MoveTowards/RotateTowards confusion

visiblenoise

New member
(Note: I'm on v2, so I'm sorry if this is something that has been fixed in v3!)

While troubleshooting a MoveTowards ability (with a small angle tolerance) that was taking too long to rotate into, I noticed something I didn't understand in CharacterLocomotion.cs (UpdateRotation(), line 663):
C#:
targetRotation = Quaternion.Slerp(rotation, rotation * Quaternion.Euler(m_DeltaRotation), m_MotorRotationSpeed * m_TimeScale * TimeUtility.DeltaTimeScaled);
My understanding is that it is getting a smoothed targetRotation, before applying it as the new rotation immediately after this line.

My question is, why Slerp() and not RotateTowards()? m_MotorRotationSpeed * m_TimeScale * TimeUtility.DeltaTimeScaled, i.e. the interpolation ratio "t", is basically a fractional constant more often than not, so if I understand Slerp() correctly, this line will never get all the way to the full value represented by m_DeltaRotation, because "t" won't grow to 1. In other words, if I tried to set the same target rotation over several frames, this line would keep getting us closer because the current rotation keeps getting updated, but it won't ever actually get there - like an exponential decay.

Is this a bug? I don't think this is the only place in the code that does this kind of thing.
 
Hello,

Version 2 is no longer supported so for continued support please update to version 3 or email support@opsive.com for paid support. The entire locomotion system has been reworked in version 3.
 
Top