Spring

Follows its input like a weight on a spring, overshooting and bouncing before it settles.

Parameters

NameTypeDescription
ValueoutputFloatThe position of the weight on its way to the input.
InputFloatThe value the spring pulls towards.
SpeedFloatHow stiff the spring is, as the number of times per second it would swing back and forth if nothing slowed it down.
BouncinessFloatHow much the value overshoots and keeps swinging, from 0 for no overshoot at all to 1 for a long wobble.

Spring makes a value follow its input the way a weight hanging on a spring follows your hand. When the input moves, the value picks up speed, shoots past the target, swings back and settles down. The movement feels physical, which is why it suits things that should react with some life to them: a menu that pops into place, an object that snaps to the cursor with a wobble.

The speed sets how quickly the spring reacts. Higher is stiffer and snappier, lower is slower and lazier. Bounciness sets how much it overshoots. At 0 the value glides to the target without going past it. Higher values swing past it further and for longer. Even at 1 the swinging dies out eventually, so the value always comes to rest at the input in the end.

After a hiccup of more than a tenth of a second the spring only moves as much as it would in a tenth of a second, so a stall does not make it jump.

Keywords: bounce, physics, overshoot, wobble, elastic, damping, oscillate