Phaser API Documentation

  Version: 
worldConstraint(body, [length], [stiffness], [options])

Description:

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.

A world constraint has only one body, you should specify a pointA position in the constraint options parameter to attach the constraint to the world.

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.

Parameters:

name type arguments Default description
body MatterJS.BodyType

The Matter 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.

Returns:
Description:

A Matter JS Constraint.

Type:
  • MatterJS.ConstraintType
Since: 3.0.0