Phaser API Documentation

spring(bodyA, bodyB, [length], [stiffness], [options])


This method is an alias for Factory.constraint.

Constraints (or joints) are used for specifying that a fixed distance must be maintained between two bodies, or a body and a fixed world-space position.

The stiffness of constraints can be modified to create springs or elastic.

To simulate a revolute constraint (or pin joint) set length: 0 and a high stiffness value (e.g. 0.7 or above).

If the constraint is unstable, try lowering the stiffness value and / or increasing constraintIterations within the Matter Config.

For compound bodies, constraints must be applied to the parent body and not one of its parts.


name type arguments Default description
bodyA MatterJS.BodyType

The first possible Body that this constraint is attached to.

bodyB MatterJS.BodyType

The second possible Body that this constraint is attached to.

length number <optional>

A Number that specifies the target resting length of the constraint. If not given it is calculated automatically in Constraint.create from initial positions of the constraint.bodyA and constraint.bodyB.

stiffness number <optional> 1

A Number that specifies the stiffness of the constraint, i.e. the rate at which it returns to its resting constraint.length. A value of 1 means the constraint should be very stiff. A value of 0.2 means the constraint acts as a soft spring.

options Phaser.Types.Physics.Matter.MatterConstraintConfig <optional>

An optional Constraint configuration object that is used to set initial Constraint properties on creation.


A Matter JS Constraint.

  • MatterJS.ConstraintType
Since: 3.0.0