Frame-rate-independent exponential damping toward a target.
After total elapsed time t_total (in seconds), the result
satisfies
result = current + (target - current) * (1 - exp(-lambda * t_total))
regardless of how t_total was split across dt calls. Same
algorithm as THREE.MathUtils.damp in Three.js.
lambda is the decay rate in 1/seconds — higher = snappier
convergence. A rule of thumb: lambda = 5 reaches ≈ 99% of the
target in one second; lambda = 10 reaches ≈ 99% in ~0.5 s.
Use this — NOT lerp(current, target, alpha) per frame — whenever
the smoothing should feel the same regardless of frame rate
(camera follow, value tracking, input smoothing).
Parameters
current: number
the current value (carries forward across frames)
target: number
the value to approach
lambda: number
decay rate in 1/seconds. Higher = snappier.
dt: number
delta time in seconds (note: melonJS engine dt is in ms; divide by 1000)
Frame-rate-independent exponential damping toward a target.
After total elapsed time
t_total(in seconds), the result satisfiesresult = current + (target - current) * (1 - exp(-lambda * t_total))regardless of howt_totalwas split acrossdtcalls. Same algorithm asTHREE.MathUtils.dampin Three.js.lambdais the decay rate in1/seconds— higher = snappier convergence. A rule of thumb:lambda = 5reaches ≈ 99% of the target in one second;lambda = 10reaches ≈ 99% in ~0.5 s.Use this — NOT
lerp(current, target, alpha)per frame — whenever the smoothing should feel the same regardless of frame rate (camera follow, value tracking, input smoothing).