Show:
API

Matter.Collision

The Matter.Collision module contains methods for detecting collisions between a given pair of bodies.

For efficient detection between a list of bodies, see Matter.Detector and Matter.Query.

See Matter.Engine for collision events.

Methods

Matter.Collision._findSupports

(bodyA, bodyB, normal, direction)
Object private

Finds supporting vertices given two bodies along a given direction using hill-climbing.

Parameters

Returns

[vector]

Matter.Collision._overlapAxes

(result, verticesA, verticesB, axes)
private

Find the overlap between two sets of vertices.

Parameters

Matter.Collision._projectToAxis

(projection, vertices, axis)
private

Projects vertices on an axis and returns an interval.

Parameters

Matter.Collision.collides

(bodyA, bodyB, [pairs])
Collision | Null

Detect collision between two bodies.

Parameters

  • bodyA Body
  • bodyB Body
  • [pairs] Pairs optional

    Optionally reuse collision records from existing pairs.

Returns

Collision | Null

A collision record if detected, otherwise null

Matter.Collision.create

(bodyA, bodyB)
Collision

Creates a new collision record.

Parameters

  • bodyA Body

    The first body part represented by the collision record

  • bodyB Body

    The second body part represented by the collision record

Returns

Collision

A new collision record

Properties / Options

The following properties are specified for objects created by Matter.Collision.create and may be passed to it as options.

Collision.bodyA

Body

The first body part represented by the collision (see also collision.parentA).

Collision.bodyB

Body

The second body part represented by the collision (see also collision.parentB).

Collision.collided

Boolean

A flag that indicates if the bodies were colliding when the collision was last updated.

Default: false

Collision.depth

Number

A Number that represents the minimum separating distance between the bodies along the collision normal.

Default: 0

Collision.normal

Vector

A normalised Vector that represents the direction between the bodies that provides the minimum separating distance.

Default: { x: 0, y: 0 }

Collision.pair

Pair | Null

A reference to the pair using this collision record, if there is one.

Default: null

Collision.parentA

Body

The first body represented by the collision (i.e. collision.bodyA.parent).

Collision.parentB

Body

The second body represented by the collision (i.e. collision.bodyB.parent).

A Vector that represents the direction and depth of the collision.

Default: { x: 0, y: 0 }

An array of body vertices that represent the support points in the collision. These are the deepest vertices (along the collision normal) of each body that are contained by the other body's vertices.

Default: []

Collision.tangent

Vector

A normalised Vector that is the tangent direction to the collision normal.

Default: { x: 0, y: 0 }

0.18.0