Fix framerate dependent UI animations

This commit is contained in:
PJB3005
2025-08-30 17:37:36 +02:00
parent b61003e2a0
commit c2c8af16d0
3 changed files with 15 additions and 2 deletions
@@ -74,7 +74,7 @@ namespace Robust.Client.UserInterface.Controls
else
{
_updating = true;
Value = MathHelper.Lerp(Value, ValueTarget, Math.Min(args.DeltaSeconds * 15, 1));
Value = UIAnimations.LerpAnimate(Value, ValueTarget, args.DeltaSeconds, 15);
_updating = false;
}
}
@@ -71,7 +71,7 @@ namespace Robust.Client.UserInterface.CustomControls
}
else
{
_curAnchorOffset = MathHelper.Lerp(_curAnchorOffset, targetOffset, args.DeltaSeconds * 20);
_curAnchorOffset = UIAnimations.LerpAnimate(_curAnchorOffset, targetOffset, args.DeltaSeconds, 20);
}
UpdateAnchorOffset();
@@ -0,0 +1,13 @@
using System;
using Robust.Shared.Maths;
namespace Robust.Client.UserInterface;
internal static class UIAnimations
{
// From https://blog.pkh.me/p/41-fixing-the-iterative-damping-interpolation-in-video-games.html
public static float LerpAnimate(float a, float b, float dt, float rate)
{
return MathHelper.Lerp(a, b, 1f - MathF.Exp(-dt * rate));
}
}