Problem:
- In FMath::CriticallyDampedSmoothing() a factor of InTargetValueRate * InSmoothingTime is applied 2 times when it only needs to be applied once. This creates unexpected behaviour when nonzero values of InTargetValueRate are input.
- The first time it is applied when creating AdjustedTarget:
// Target velocity turns into an offset to the positionT AdjustedTarget = InTargetValue + InTargetValueRate * InSmoothingTime;
- It is then applied a second time when creating X0:
T X0 = InOutValue - AdjustedTarget;// Target velocity turns into an offset to the positionX0 -= InTargetValueRate * InSmoothingTime;
- This means that X0 has this factor applied twice since X0 already includes AdjustedTarget
Solution:
- This line seems unneeded:
X0 -= InTargetValueRate * InSmoothingTime;
Reasoning:
- FMath::SpringDamperSmoothing() has a critically damped case with very similar code except it does not have this extra line
- When providing the same values to FMath::SpringDamperSmoothing() and FMath::CriticallyDampedSmoothing() (where InTargetValueRate is nonzero and the SpringDamperSmoothing had a damping factor of 1) I found:
- FMath::SpringDamperSmoothing() behaved as expected
- FMath::CriticallyDampedSmoothing() behaved unexpectedly
[Attachment Removed]