Spring animation
Physics-based spring animations, decay/inertia, and rubberband boundary constraints for Unity.
on this page
com.bluecadet.spring drives values toward targets with a damped harmonic oscillator (SpringValue<T>), decays velocity to rest for momentum-based motion (DecayValue<T>), and applies iOS-style elastic resistance at boundaries (Rubberband). Per-type math is Burst-compiled for float, Vector2, and Vector3.
Requirements
- Unity 6000.3+
com.unity.burst1.8.27com.unity.mathematics1.3.3
Install
OpenUPM is the recommended path:
openupm add com.bluecadet.springThe scoped registry (https://package.openupm.com, scope com.bluecadet) only needs adding once per project.
To install from a Git URL instead, point at the release tag, which follows the com.bluecadet.spring@<version> format:
{
"dependencies": {
"com.bluecadet.spring": "https://github.com/bluecadet/unity-packages.git?path=Packages/com.bluecadet.spring#com.bluecadet.spring@<version>"
}
}Pick a version from Releases — every released tag is listed there. The openupm add form above always takes the latest.
Quick start
A basic spring
using Bluecadet.Spring;
// Create once (e.g. in Awake), hold as a field
_spring = Spring.Create(0f)
.WithDamping(26f)
.WithStiffness(170f)
.Bind(x => transform.localPosition = new Vector3(x, 0, 0));
// Animate to a target (velocity is preserved mid-flight)
_spring.To(1f);
// Release when done (e.g. OnDestroy)
Spring.Release(_spring);A decay
_decay = Spring.CreateDecay(Vector2.zero)
.WithFriction(8f)
.Bind(v => scrollView.velocity = v);
// Trigger on swipe
_decay.Play(swipeVelocity);
Spring.Release(_decay);A rubberband clamp
using Bluecadet.Spring;
// Resist a value past its bounds (e.g. during drag)
float constrained = Rubberband.Apply(value, min: 0f, max: 100f, resistance: 0.55f);
// Snap back to bounds on release
if (Rubberband.IsOutOfBounds(position, 0f, 100f))
_spring.To(Rubberband.Clamp(position, 0f, 100f));Next
- Springs and decay — builder options, binding, events, and lifetime for
SpringValue<T>andDecayValue<T>. - Rubberband — the static
RubberbandAPI and a worked drag/release example.