A small value-type helper that tracks a float moving toward a target using exponential decay. It stores current value, target, and halflife, updates the current value each frame using MathX.ExponentialDecay, and exposes convenience methods to update and check settled state.
using System;
using Sandbox;
namespace Goo.Animation;
public record struct DecayFloat
{
public float Current;
public float Target;
public float Halflife;
public DecayFloat(float initial, float halflife)
{
Current = initial;
Target = initial;
Halflife = halflife;
}
public void Update(float dt) =>
Current = MathX.ExponentialDecay(Current, Target, Halflife, dt);
public bool IsSettled => MathF.Abs(Target - Current) < 0.0001f;
/// <summary>Advances by dt and returns true while still moving; chain calls with | (not ||) so every damper advances each frame.</summary>
public bool Tick(float dt) { Update(dt); return !IsSettled; }
}