fix(Prediction): InsertCorrection would produce NaN multipliers, spreading through prediction code

This commit is contained in:
mischa 2024-01-07 12:37:12 +01:00
parent febcce9513
commit df918ecf9f

View File

@ -121,7 +121,10 @@ public static void InsertCorrection<T>(
//
double previousDeltaTime = after.timestamp - before.timestamp; // 3.0 - 1.0 = 2.0
double correctedDeltaTime = after.timestamp - corrected.timestamp; // 3.0 - 2.5 = 0.5
double multiplier = correctedDeltaTime / previousDeltaTime; // 0.5 / 2.0 = 0.25
// fix multiplier becoming NaN if previousDeltaTime is 0:
// double multiplier = correctedDeltaTime / previousDeltaTime;
double multiplier = previousDeltaTime != 0 ? correctedDeltaTime / previousDeltaTime : 0; // 0.5 / 2.0 = 0.25
// recalculate 'after.delta' with the multiplier
after.AdjustDeltas((float)multiplier);