Show:

Matter.Constraint

The Matter.Constraint module contains methods for creating and manipulating constraints. Constraints 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.

See the included usage examples.

Methods

Matter.Constraint.create

(options)
Constraint

Creates a new constraint. All properties have default values, and many are pre-calculated automatically based on other properties. See the properties section below for detailed information on what you can pass via the options object.

Parameters

Returns

Constraint

constraint

Matter.Constraint.postSolveAll

(bodies)
private

Performs body updates required after solving constraints.

Parameters

Matter.Constraint.solve

(constraint, timeScale)
private

Solves a distance constraint with Gauss-Siedel method.

Parameters

Matter.Constraint.solveAll

(constraints, timeScale)
private

Solves all constraints in a list of collisions.

Parameters

Item Index

Properties

The following properties are specified for objects created by <span class="prefix">Matter.</span>.create and for objects passed to it via the options argument.

Properties

The following properties are specified for objects created by Matter.Constraint.create and for objects passed to it via the options argument.

Constraint.bodyA

Body

The first possible Body that this constraint is attached to.

Default: null

Constraint.bodyB

Body

The second possible Body that this constraint is attached to.

Default: null

Constraint.id

Number

An integer Number uniquely identifying number generated in Composite.create by Common.nextId.

Constraint.label

String

An arbitrary String name to help the user identify and manage bodies.

Default: "Constraint"

Constraint.length

Number

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

Constraint.pointA

Vector

A Vector that specifies the offset of the constraint from center of the constraint.bodyA if defined, otherwise a world-space position.

Default: { x: 0, y: 0 }

Constraint.pointB

Vector

A Vector that specifies the offset of the constraint from center of the constraint.bodyA if defined, otherwise a world-space position.

Default: { x: 0, y: 0 }

Constraint.render

Object

An Object that defines the rendering properties to be consumed by the module Matter.Render.

A Number that defines the line width to use when rendering the constraint outline. A value of 0 means no outline will be rendered.

Default: 2

A String that defines the stroke style to use when rendering the constraint outline. It is the same as when using a canvas, so it accepts CSS style property values.

Default: a random colour

A flag that indicates if the constraint should be rendered.

Default: true

Constraint.stiffness

Number

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 like a soft spring.

Default: 1

Constraint.type

String

A String denoting the type of object.

Default: "constraint"

0.11.0