Class: Factory

Phaser.Physics.Matter. Factory

The Matter Factory is responsible for quickly creating a variety of different types of bodies, constraints and Game Objects and adding them into the physics world.

You access the factory from within a Scene using add:

this.matter.add.rectangle(x, y, width, height);

Use of the Factory is optional. All of the objects it creates can also be created directly via your own code or constructors. It is provided as a means to keep your code concise.


new Factory(world)

Parameters:
Name Type Description
world Phaser.Physics.Matter.World

The Matter World which this Factory adds to.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 21)

Members


scene :Phaser.Scene

The Scene which this Factory's Matter World belongs to.

Type:
Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 58)

sys :Phaser.Scenes.Systems

A reference to the Scene.Systems this Matter Physics instance belongs to.

Type:
Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 67)

world :Phaser.Physics.Matter.World

The Matter World which this Factory adds to.

Type:
Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 49)

Methods


car(x, y, width, height, wheelSize)

Creates a composite with simple car setup of bodies and constraints.

Parameters:
Name Type Description
x number

The horizontal position of the car in the world.

y number

The vertical position of the car in the world.

width number

The width of the car chasis.

height number

The height of the car chasis.

wheelSize number

The radius of the car wheels.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 534)
Returns:

A new composite car body.

Type
MatterJS.CompositeType

chain(composite, xOffsetA, yOffsetA, xOffsetB, yOffsetB [, options])

Chains all bodies in the given composite together using constraints.

Parameters:
Name Type Argument Description
composite MatterJS.CompositeType

The composite in which all bodies will be chained together sequentially.

xOffsetA number

The horizontal offset of the BodyA constraint. This is a percentage based on the body size, not a world position.

yOffsetA number

The vertical offset of the BodyA constraint. This is a percentage based on the body size, not a world position.

xOffsetB number

The horizontal offset of the BodyB constraint. This is a percentage based on the body size, not a world position.

yOffsetB number

The vertical offset of the BodyB constraint. This is a percentage based on the body size, not a world position.

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

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 472)
Returns:

The original composite that was passed to this method.

Type
MatterJS.CompositeType

circle(x, y, radius [, options] [, maxSides])

Creates a new rigid circular Body and adds it to the World.

Parameters:
Name Type Argument Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

radius number

The radius of the circle.

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

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

maxSides number <optional>

The maximum amount of sides to use for the polygon which will approximate this circle.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 124)
Returns:

A Matter JS Body.

Type
MatterJS.BodyType

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

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.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 649)
Returns:

A Matter JS Constraint.

Type
MatterJS.ConstraintType

destroy()

Destroys this Factory.

Since: 3.5.0
Source: src/physics/matter-js/Factory.js (Line 909)

fromJSON(x, y, config [, options] [, addToWorld])

Creates a body using the supplied physics data, as provided by a JSON file.

The data file should be loaded as JSON:

preload ()
{
  this.load.json('ninjas', 'assets/ninjas.json);
}

create ()
{
  const ninjaShapes = this.cache.json.get('ninjas');

  this.matter.add.fromJSON(400, 300, ninjaShapes.shinobi);
}

Do not pass the entire JSON file to this method, but instead pass one of the shapes contained within it.

If you pas in an options object, any settings in there will override those in the config object.

The structure of the JSON file is as follows:

{
  'generator_info': // The name of the application that created the JSON data
  'shapeName': {
    'type': // The type of body
    'label': // Optional body label
    'vertices': // An array, or an array of arrays, containing the vertex data in x/y object pairs
  }
}

At the time of writing, only the Phaser Physics Tracer App exports in this format.

Parameters:
Name Type Argument Default Description
x number

The X coordinate of the body.

y number

The Y coordinate of the body.

config any

The JSON physics data.

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

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

addToWorld boolean <optional>
true

Should the newly created body be immediately added to the World?

Since: 3.22.0
Source: src/physics/matter-js/Factory.js (Line 311)
Returns:

A Matter JS Body.

Type
MatterJS.BodyType

fromPhysicsEditor(x, y, config [, options] [, addToWorld])

Creates a body using data exported from the application PhysicsEditor (https://www.codeandweb.com/physicseditor)

The PhysicsEditor file should be loaded as JSON:

preload ()
{
  this.load.json('vehicles', 'assets/vehicles.json);
}

create ()
{
  const vehicleShapes = this.cache.json.get('vehicles');
  this.matter.add.fromPhysicsEditor(400, 300, vehicleShapes.truck);
}

Do not pass the entire JSON file to this method, but instead pass one of the shapes contained within it.

If you pas in an options object, any settings in there will override those in the PhysicsEditor config object.

Parameters:
Name Type Argument Default Description
x number

The horizontal world location of the body.

y number

The vertical world location of the body.

config any

The JSON data exported from PhysicsEditor.

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

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

addToWorld boolean <optional>
true

Should the newly created body be immediately added to the World?

Since: 3.22.0
Source: src/physics/matter-js/Factory.js (Line 201)
Returns:

A Matter JS Body.

Type
MatterJS.BodyType

fromSVG(x, y, xml [, scale] [, options] [, addToWorld])

Creates a body using the path data from an SVG file.

SVG Parsing requires the pathseg polyfill from https://github.com/progers/pathseg

The SVG file should be loaded as XML, as this method requires the ability to extract the path data from it. I.e.:

preload ()
{
  this.load.xml('face', 'assets/face.svg);
}

create ()
{
  this.matter.add.fromSVG(400, 300, this.cache.xml.get('face'));
}
Parameters:
Name Type Argument Default Description
x number

The X coordinate of the body.

y number

The Y coordinate of the body.

xml object

The SVG Path data.

scale number <optional>
1

Scale the vertices by this amount after creation.

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

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

addToWorld boolean <optional>
true

Should the newly created body be immediately added to the World?

Since: 3.22.0
Source: src/physics/matter-js/Factory.js (Line 248)
Returns:

A Matter JS Body.

Type
MatterJS.BodyType

fromVertices(x, y, vertexSets [, options] [, flagInternal] [, removeCollinear] [, minimumArea])

Creates a body using the supplied vertices (or an array containing multiple sets of vertices) and adds it to the World. If the vertices are convex, they will pass through as supplied. Otherwise, if the vertices are concave, they will be decomposed. Note that this process is not guaranteed to support complex sets of vertices, e.g. ones with holes.

Parameters:
Name Type Argument Default Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

vertexSets string | array

The vertices data. Either a path string or an array of vertices.

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

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

flagInternal boolean <optional>
false

Flag internal edges (coincident part edges)

removeCollinear number <optional>
0.01

Whether Matter.js will discard collinear edges (to improve performance).

minimumArea number <optional>
10

During decomposition discard parts that have an area less than this.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 170)
Returns:

A Matter JS Body.

Type
MatterJS.BodyType

gameObject(gameObject [, options] [, addToWorld])

Takes an existing Game Object and injects all of the Matter Components into it.

This enables you to use component methods such as setVelocity or isSensor directly from this Game Object.

You can also pass in either a Matter Body Configuration object, or a Matter Body instance to link with this Game Object.

Parameters:
Name Type Argument Default Description
gameObject Phaser.GameObjects.GameObject

The Game Object to inject the Matter Components in to.

options Phaser.Types.Physics.Matter.MatterBodyConfig | MatterJS.Body <optional>

A Matter Body configuration object, or an instance of a Matter Body.

addToWorld boolean <optional>
true

Add this Matter Body to the World?

Since: 3.3.0
Source: src/physics/matter-js/Factory.js (Line 886)
Returns:

The Game Object that had the Matter Components injected into it.

Type
Phaser.Physics.Matter.Image | Phaser.Physics.Matter.Sprite | Phaser.GameObjects.GameObject

image(x, y, key [, frame] [, options])

Creates a Matter Physics Image Game Object.

An Image is a light-weight Game Object useful for the display of static images in your game, such as logos, backgrounds, scenery or other non-animated elements. Images can have input events and physics bodies, or be tweened, tinted or scrolled. The main difference between an Image and a Sprite is that you cannot animate an Image as they do not have the Animation component.

Parameters:
Name Type Argument Description
x number

The horizontal position of this Game Object in the world.

y number

The vertical position of this Game Object in the world.

key string

The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.

frame string | number <optional>

An optional frame from the Texture this Game Object is rendering with. Set to null to skip this value.

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

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 801)
Returns:

The Matter Image Game Object.

Type
Phaser.Physics.Matter.Image

imageStack(key, frame, x, y, columns, rows [, columnGap] [, rowGap] [, options])

Create a new composite containing Matter Image objects created in a grid arrangement. This function uses the body bounds to prevent overlaps.

Parameters:
Name Type Argument Default Description
key string

The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.

frame string | number

An optional frame from the Texture this Game Object is rendering with. Set to null to skip this value.

x number

The horizontal position of this composite in the world.

y number

The vertical position of this composite in the world.

columns number

The number of columns in the grid.

rows number

The number of rows in the grid.

columnGap number <optional>
0

The distance between each column.

rowGap number <optional>
0

The distance between each row.

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

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 375)
Returns:

A Matter JS Composite Stack.

Type
MatterJS.CompositeType

joint(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.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 585)
Returns:

A Matter JS Constraint.

Type
MatterJS.ConstraintType

mesh(composite, columns, rows, crossBrace [, options])

Connects bodies in the composite with constraints in a grid pattern, with optional cross braces.

Parameters:
Name Type Argument Description
composite MatterJS.CompositeType

The composite in which all bodies will be chained together.

columns number

The number of columns in the mesh.

rows number

The number of rows in the mesh.

crossBrace boolean

Create cross braces for the mesh as well?

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

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 492)
Returns:

The original composite that was passed to this method.

Type
MatterJS.CompositeType

mouseSpring( [options])

This method is an alias for Factory.pointerConstraint.

A Pointer Constraint is a special type of constraint that allows you to click and drag bodies in a Matter World. It monitors the active Pointers in a Scene, and when one is pressed down it checks to see if that hit any part of any active body in the world. If it did, and the body has input enabled, it will begin to drag it until either released, or you stop it via the stopDrag method.

You can adjust the stiffness, length and other properties of the constraint via the options object on creation.

Parameters:
Name Type Argument Description
options Phaser.Types.Physics.Matter.MatterConstraintConfig <optional>

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 744)
Returns:

A Matter JS Constraint.

Type
MatterJS.ConstraintType

newtonsCradle(x, y, number, size, length)

Creates a composite with a Newton's Cradle setup of bodies and constraints.

Parameters:
Name Type Description
x number

The horizontal position of the start of the cradle.

y number

The vertical position of the start of the cradle.

number number

The number of balls in the cradle.

size number

The radius of each ball in the cradle.

length number

The length of the 'string' the balls hang from.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 511)
Returns:

A Newton's cradle composite.

Type
MatterJS.CompositeType

pointerConstraint( [options])

A Pointer Constraint is a special type of constraint that allows you to click and drag bodies in a Matter World. It monitors the active Pointers in a Scene, and when one is pressed down it checks to see if that hit any part of any active body in the world. If it did, and the body has input enabled, it will begin to drag it until either released, or you stop it via the stopDrag method.

You can adjust the stiffness, length and other properties of the constraint via the options object on creation.

Parameters:
Name Type Argument Description
options Phaser.Types.Physics.Matter.MatterConstraintConfig <optional>

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 768)
Returns:

A Matter JS Constraint.

Type
MatterJS.ConstraintType

polygon(x, y, sides, radius [, options])

Creates a new rigid polygonal Body and adds it to the World.

Parameters:
Name Type Argument Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

sides number

The number of sides the polygon will have.

radius number

The "radius" of the polygon, i.e. the distance from its center to any vertex. This is also the radius of its circumcircle.

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

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 147)
Returns:

A Matter JS Body.

Type
MatterJS.BodyType

pyramid(x, y, columns, rows, columnGap, rowGap, callback)

Create a new composite containing bodies created in the callback in a pyramid arrangement. This function uses the body bounds to prevent overlaps.

Parameters:
Name Type Description
x number

The horizontal position of this composite in the world.

y number

The vertical position of this composite in the world.

columns number

The number of columns in the pyramid.

rows number

The number of rows in the pyramid.

columnGap number

The distance between each column.

rowGap number

The distance between each row.

callback function

The callback function to be invoked.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 446)
Returns:

A Matter JS Composite pyramid.

Type
MatterJS.CompositeType

rectangle(x, y, width, height [, options])

Creates a new rigid rectangular Body and adds it to the World.

Parameters:
Name Type Argument Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

width number

The width of the Body.

height number

The height of the Body.

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

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 77)
Returns:

A Matter JS Body.

Type
MatterJS.BodyType

softBody(x, y, columns, rows, columnGap, rowGap, crossBrace, particleRadius [, particleOptions] [, constraintOptions])

Creates a simple soft body like object.

Parameters:
Name Type Argument Description
x number

The horizontal position of this composite in the world.

y number

The vertical position of this composite in the world.

columns number

The number of columns in the Composite.

rows number

The number of rows in the Composite.

columnGap number

The distance between each column.

rowGap number

The distance between each row.

crossBrace boolean

true to create cross braces between the bodies, or false to create just straight braces.

particleRadius number

The radius of this circlular composite.

particleOptions Phaser.Types.Physics.Matter.MatterBodyConfig <optional>

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

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

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 557)
Returns:

A new composite simple soft body.

Type
MatterJS.CompositeType

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.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 617)
Returns:

A Matter JS Constraint.

Type
MatterJS.ConstraintType

sprite(x, y, key [, frame] [, options])

Creates a Matter Physics Sprite Game Object.

A Sprite Game Object is used for the display of both static and animated images in your game. Sprites can have input events and physics bodies. They can also be tweened, tinted, scrolled and animated.

The main difference between a Sprite and an Image Game Object is that you cannot animate Images. As such, Sprites take a fraction longer to process and have a larger API footprint due to the Animation Component. If you do not require animation then you can safely use Images to replace Sprites in all cases.

Parameters:
Name Type Argument Description
x number

The horizontal position of this Game Object in the world.

y number

The vertical position of this Game Object in the world.

key string

The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.

frame string | number <optional>

An optional frame from the Texture this Game Object is rendering with. Set to null to skip this value.

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

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 854)
Returns:

The Matter Sprite Game Object.

Type
Phaser.Physics.Matter.Sprite

stack(x, y, columns, rows, columnGap, rowGap, callback)

Create a new composite containing bodies created in the callback in a grid arrangement.

This function uses the body bounds to prevent overlaps.

Parameters:
Name Type Description
x number

The horizontal position of this composite in the world.

y number

The vertical position of this composite in the world.

columns number

The number of columns in the grid.

rows number

The number of rows in the grid.

columnGap number

The distance between each column.

rowGap number

The distance between each row.

callback function

The callback that creates the stack.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 419)
Returns:

A new composite containing objects created in the callback.

Type
MatterJS.CompositeType

tileBody(tile [, options])

Creates a wrapper around a Tile that provides access to a corresponding Matter body. A tile can only have one Matter body associated with it. You can either pass in an existing Matter body for the tile or allow the constructor to create the corresponding body for you. If the Tile has a collision group (defined in Tiled), those shapes will be used to create the body. If not, the tile's rectangle bounding box will be used.

The corresponding body will be accessible on the Tile itself via Tile.physics.matterBody.

Note: not all Tiled collision shapes are supported. See Phaser.Physics.Matter.TileBody#setFromTileCollision for more information.

Parameters:
Name Type Argument Description
tile Phaser.Tilemaps.Tile

The target tile that should have a Matter body.

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

Options to be used when creating the Matter body.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 829)
Returns:

The Matter Tile Body Game Object.

Type
Phaser.Physics.Matter.TileBody

trapezoid(x, y, width, height, slope [, options])

Creates a new rigid trapezoidal Body and adds it to the World.

Parameters:
Name Type Argument Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

width number

The width of the trapezoid Body.

height number

The height of the trapezoid Body.

slope number

The slope of the trapezoid. 0 creates a rectangle, while 1 creates a triangle. Positive values make the top side shorter, while negative values make the bottom side shorter.

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

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

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 100)
Returns:

A Matter JS Body.

Type
MatterJS.BodyType

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

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 Argument 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.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 696)
Returns:

A Matter JS Constraint.

Type
MatterJS.ConstraintType