Prevent delta from becoming infinity or nan when duration is 0

This commit is contained in:
Sollace 2024-02-24 16:22:41 +00:00
parent f9711b9043
commit 0ba987159f
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB

View file

@ -31,6 +31,13 @@ public class Lerp {
if (MathHelper.approximatelyEquals(end, newTarget)) { if (MathHelper.approximatelyEquals(end, newTarget)) {
return false; return false;
} }
if (changeDuration == 0) {
start = newTarget;
end = newTarget;
finished = true;
return false;
}
start = getValue(); start = getValue();
startTime = Util.getMeasuringTimeMs(); startTime = Util.getMeasuringTimeMs();
end = newTarget; end = newTarget;
@ -66,6 +73,9 @@ public class Lerp {
} }
private float getDelta() { private float getDelta() {
if (duration == 0) {
return 1;
}
return MathHelper.clamp((float)(Util.getMeasuringTimeMs() - startTime) / (float)duration, 0, 1); return MathHelper.clamp((float)(Util.getMeasuringTimeMs() - startTime) / (float)duration, 0, 1);
} }
} }