diff --git a/Robust.Client/UserInterface/Controls/ScrollBar.cs b/Robust.Client/UserInterface/Controls/ScrollBar.cs index 790d576921..dfbca18e48 100644 --- a/Robust.Client/UserInterface/Controls/ScrollBar.cs +++ b/Robust.Client/UserInterface/Controls/ScrollBar.cs @@ -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; } } diff --git a/Robust.Client/UserInterface/CustomControls/DropDownDebugConsole.xaml.cs b/Robust.Client/UserInterface/CustomControls/DropDownDebugConsole.xaml.cs index e3135163ae..a1ac6382bf 100644 --- a/Robust.Client/UserInterface/CustomControls/DropDownDebugConsole.xaml.cs +++ b/Robust.Client/UserInterface/CustomControls/DropDownDebugConsole.xaml.cs @@ -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(); diff --git a/Robust.Client/UserInterface/UIAnimations.cs b/Robust.Client/UserInterface/UIAnimations.cs new file mode 100644 index 0000000000..7f85c28d37 --- /dev/null +++ b/Robust.Client/UserInterface/UIAnimations.cs @@ -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)); + } +}