- Matter.Constraint
- Methods
- Item Index
- Properties
- Constraint.bodyA
- Constraint.bodyB
- Constraint.damping
- Constraint.id
- Constraint.label
- Constraint.length
- Constraint.plugin
- Constraint.pointA
- Constraint.pointB
- Constraint.render
- Constraint.render.anchors
- Constraint.render.lineWidth
- Constraint.render.strokeStyle
- Constraint.render.type
- Constraint.render.visible
- Constraint.stiffness
- Constraint.type
Matter.Constraint
Defined in: src/constraint/Constraint.js:1
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)
Creates a new constraint. All properties have default values, and many are pre-calculated automatically based on other properties. 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 engine.constraintIterations
. For compound bodies, constraints must be applied to the parent body (not one of its parts). See the properties section below for detailed information on what you can pass via the options
object.
Parameters
options
Object
Returns
Constraintconstraint
@ src/constraint/Constraint.js:28
Matter.Constraint.postSolveAll
(bodies)
private
Performs body updates required after solving constraints.
Parameters
bodies
Body[]
@ src/constraint/Constraint.js:257
Matter.Constraint.preSolveAll
(bodies)
private
Prepares for solving by constraint warming.
Parameters
bodies
Body[]
@ src/constraint/Constraint.js:87
Matter.Constraint.solve
(constraint, timeScale)
private
Solves a distance constraint with Gauss-Siedel method.
Parameters
constraint
Constraint
timeScale
Number
@ src/constraint/Constraint.js:139
Matter.Constraint.solveAll
(constraints, timeScale)
private
Solves all constraints in a list of collisions.
Parameters
constraints
Constraint[]
timeScale
Number
@ src/constraint/Constraint.js:108
Item Index
Methods
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.
- bodyA
- bodyB
- damping
- id
- label
- length
- plugin
- pointA
- pointB
- render
- render.anchors
- render.lineWidth
- render.strokeStyle
- render.type
- render.visible
- stiffness
- type
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
The first possible Body
that this constraint is attached to.
Default: null
@ src/constraint/Constraint.js:384
Constraint.bodyB
The second possible Body
that this constraint is attached to.
Default: null
@ src/constraint/Constraint.js:392
Constraint.damping
A Number
that specifies the damping of the constraint, i.e. the amount of resistance applied to each body based on their velocities to limit the amount of oscillation. Damping will only be apparent when the constraint also has a very low stiffness
. A value of 0.1
means the constraint will apply heavy damping, resulting in little to no oscillation. A value of 0
means the constraint will apply no damping.
Default: 0
@ src/constraint/Constraint.js:426
Constraint.id
An integer Number
uniquely identifying number generated in Composite.create
by Common.nextId
.
@ src/constraint/Constraint.js:309
Constraint.label
An arbitrary String
name to help the user identify and manage bodies.
Default: "Constraint"
@ src/constraint/Constraint.js:325
Constraint.length
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
.
@ src/constraint/Constraint.js:438
Constraint.plugin
An object reserved for storing plugin-specific properties.
@ src/constraint/Constraint.js:446
Constraint.pointA
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 }
@ src/constraint/Constraint.js:400
Constraint.pointB
A Vector
that specifies the offset of the constraint from center of the constraint.bodyB
if defined, otherwise a world-space position.
Default: { x: 0, y: 0 }
@ src/constraint/Constraint.js:408
Constraint.render
An Object
that defines the rendering properties to be consumed by the module Matter.Render
.
@ src/constraint/Constraint.js:333
Constraint.render.anchors
A Boolean
that defines if the constraint's anchor points should be rendered.
Default: true
@ src/constraint/Constraint.js:376
Constraint.render.lineWidth
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
@ src/constraint/Constraint.js:348
Constraint.render.strokeStyle
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
@ src/constraint/Constraint.js:357
Constraint.render.type
A String
that defines the constraint rendering type. The possible values are 'line', 'pin', 'spring'. An appropriate render type will be automatically chosen unless one is given in options.
Default: 'line'
@ src/constraint/Constraint.js:366
Constraint.render.visible
A flag that indicates if the constraint should be rendered.
Default: true
@ src/constraint/Constraint.js:340
Constraint.stiffness
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
@ src/constraint/Constraint.js:416
Constraint.type
A String
denoting the type of object.
Default: "constraint"