Skip to content

Spring Types

Underneath every Spring Component sits one of six spring types. They are plain C# classes, not MonoBehaviours, and each one is an array of independent one-dimensional springs plus the methods to talk to them.

You meet them in two situations: when a component’s own API does not expose something you need, and when you write your own component and have to declare the springs it will run.

TypeDimensionsNotes
SpringFloat1The one everything else is built from
SpringVector22
SpringVector33Position and scale use this
SpringVector44
SpringColor4A SpringVector4 that speaks in Color and handles the conversion for you
SpringRotation9Special, see below

Each dimension is a separate spring with its own force, drag, velocity and clamping, which is why you can make a position spring that is stiff on Y and loose on X.

Two position springs chasing the same targets. With one Force for every axis the cube travels in straight lines; with Force 40 on X and 400 on Y it reaches each new height first and drifts across after, so its path curves

Rotation cannot be sprung by treating a quaternion as four numbers, so this type does something else: an axis-angle representation plus extra dimensions that keep track of overshoot past 180 degrees in the same direction, added velocity, and a few other cases. Nine dimensions in total, not all in play at once.

The implementation is the least obvious thing in the asset, and you do not need to understand it. It answers to the same methods as every other spring. Two differences are worth knowing. Rotation springs have no clamping and no per-axis force or drag, they take a single unified force and drag and that is it. And they have an Axis Restriction setting in the Inspector, which locks the spring to X, Y or Z only, which is what you want for a wheel, a lever or anything in a 2D game.

Every type answers to the same family of methods:

SpringVector3 spring = new SpringVector3();
spring.SetCurrentValue(transform.position); // where it is
spring.SetTarget(destination); // where it is going
spring.AddVelocity(Vector3.up * 8f); // shove it
spring.SetUnifiedForce(200f); // one force for all axes
spring.SetUnifiedDrag(12f);
spring.SetUnifiedForceAndDragEnabled(false); // or one per axis, once unified is off
spring.SetForce(new Vector3(200f, 60f, 200f));
spring.SetDrag(new Vector3(12f, 6f, 12f));
spring.SetClampingEnabled(true); // clamping, which is off until you turn it on
spring.SetMinValues(Vector3.zero);
spring.SetMaxValues(Vector3.one * 10f);
spring.SetClampCurrentValues(true, true, true);
spring.StopSpringOnClamp(true, true, true);

Two switches are easy to miss here, because without them the lines after them change nothing. Every new spring starts with unified Force and Drag, and while unified is on the per axis values are ignored, so SetForce with a Vector3 needs SetUnifiedForceAndDragEnabled(false) first. And bounds only apply once clamping is enabled. In the Inspector these are the Unified force & drag and Clamping Enabled checkboxes on each spring; a component’s API sets the bounds but has no switch for clamping, so tick it there.

StopSpringOnClamp is the other one worth knowing. With it on, a spring that hits a bound stops there instead of pressing against it, and the OnClampingApplied event fires so you can react. It is how you build something that falls, lands, and stays landed.

The same fall twice, towards a target far below the floor. Without clamping the cube drops straight through and out of view; with a minimum height and Stop Spring On Clamp it lands on the floor and stays there until its target moves back up

The full method list, per component, is on the API reference.