Skip to main content

Class: PhysicsBody

A rigid body model added to a node to enable physics simulation.

Param​

PhysicsBodyOptions

Implements​

Constructors​

new PhysicsBody()​

new PhysicsBody(options): PhysicsBody

Parameters​

• options: PhysicsBodyOptions

Returns​

PhysicsBody

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:23

Properties​

_body?​

optional _body: Body

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:14


_node?​

optional _node: M2Node

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:13


needsInitialization​

needsInitialization: boolean = true

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:16


options​

options: PhysicsBodyOptions

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:15

Accessors​

allowsRotation​

Get Signature​

get allowsRotation(): boolean

Whether or not the body can rotate. Defaults to true.

Remarks​

If true, this sets the Matter.js inertia property to Infinity.

Returns​

boolean

Set Signature​

set allowsRotation(allowsRotation): void

Whether or not the body can rotate. Defaults to true.

Remarks​

If true, this sets the Matter.js inertia property to Infinity.

Parameters​

• allowsRotation: boolean

Returns​

void

Whether or not the body can rotate. Defaults to true.

Remarks​

If true, this sets the Matter.js inertia property to Infinity.

Implementation of​

PhysicsBodyOptions.allowsRotation

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:436


angularVelocity​

Get Signature​

get angularVelocity(): number

Body angular velocity.

Returns​

number

Set Signature​

set angularVelocity(angularVelocity): void

Body angular velocity.

Parameters​

• angularVelocity: number

Returns​

void

Body angular velocity.

Implementation of​

PhysicsBodyOptions.angularVelocity

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:473


area​

Get Signature​

get area(): number

The area of the body's convex hull.

Remarks​

This is a read-only property.

Returns​

number

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:461


body​

Get Signature​

get body(): Body

Returns​

Body

Set Signature​

set body(body): void

Parameters​

• body: Body

Returns​

void

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:339


categoryBitMask​

Get Signature​

get categoryBitMask(): number

A 32-bit mask specifying which categories this physics body belongs to.

Remarks​

There are up to 32 different categories that physics bodies can belong to. Each category is represented by a bit in the mask. For example, if a body belongs to categories 1 and 3, its category bit mask is 0b00000000000000000000000000000101. Along with the collisionBitMask, this property determines which other bodies this physics body can collide with. Default category for all physics bodies is 1.

Returns​

number

Set Signature​

set categoryBitMask(categoryBitMask): void

A 32-bit mask specifying which categories this physics body belongs to.

Remarks​

There are up to 32 different categories that physics bodies can belong to. Each category is represented by a bit in the mask. For example, if a body belongs to categories 1 and 3, its category bit mask is 0b00000000000000000000000000000101. Along with the collisionBitMask, this property determines which other bodies this physics body can collide with. Default category for all physics bodies is 1.

Parameters​

• categoryBitMask: number

Returns​

void

A 32-bit mask specifying which categories this physics body belongs to.

Remarks​

There are up to 32 different categories that physics bodies can belong to. Each category is represented by a bit in the mask. For example, if a body belongs to categories 1 and 3, its category bit mask is 0b00000000000000000000000000000101. Along with the collisionBitMask, this property determines which other bodies this physics body can collide with. Default category for all physics bodies is 1.

Implementation of​

PhysicsBodyOptions.categoryBitMask

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:481


collisionBitMask​

Get Signature​

get collisionBitMask(): number

A 32-bit mask specifying which categories this physics body can collide with.

Remarks​

This value is a bit mask of the other physics body categories that this body can collide with. Default is 0xFFFFFFFF, which means this body can collide with all other categories (e.g., all physics bodies).

Returns​

number

Set Signature​

set collisionBitMask(collisionBitMask): void

A 32-bit mask specifying which categories this physics body can collide with.

Remarks​

This value is a bit mask of the other physics body categories that this body can collide with. Default is 0xFFFFFFFF, which means this body can collide with all other categories (e.g., all physics bodies).

Parameters​

• collisionBitMask: number

Returns​

void

A 32-bit mask specifying which categories this physics body can collide with.

Remarks​

This value is a bit mask of the other physics body categories that this body can collide with. Default is 0xFFFFFFFF, which means this body can collide with all other categories (e.g., all physics bodies).

Implementation of​

PhysicsBodyOptions.collisionBitMask

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:493


damping​

Get Signature​

get damping(): number

Friction due to air forces on the body, in the range [0, 1].

Returns​

number

Set Signature​

set damping(damping): void

Friction due to air forces on the body, in the range [0, 1].

Parameters​

• damping: number

Returns​

void

Friction due to air forces on the body, in the range [0, 1].

Implementation of​

PhysicsBodyOptions.damping

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:420


density​

Get Signature​

get density(): number

Body density (mass per unit area)

Remarks​

Mass will automatically be calculated when density is set.

Returns​

number

Set Signature​

set density(density): void

Body density (mass per unit area)

Remarks​

Mass will automatically be calculated when density is set.

Parameters​

• density: number

Returns​

void

Body density (mass per unit area)

Remarks​

Mass will automatically be calculated when density is set.

Implementation of​

PhysicsBodyOptions.density

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:448


friction​

Get Signature​

get friction(): number

Friction of the body, in the range [0, 1].

Returns​

number

Set Signature​

set friction(friction): void

Friction of the body, in the range [0, 1].

Parameters​

• friction: number

Returns​

void

Friction of the body, in the range [0, 1].

Implementation of​

PhysicsBodyOptions.friction

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:412


isDynamic​

Get Signature​

get isDynamic(): boolean

Whether or not the physics body moves in response to forces. Defaults to true.

Remarks​

Once set, this property cannot be changed. This is negated and mapped to the Matter.js static property.

Returns​

boolean

Set Signature​

set isDynamic(isDynamic): void

Whether or not the physics body moves in response to forces. Defaults to true.

Remarks​

Once set, this property cannot be changed. This is negated and mapped to the Matter.js static property.

Parameters​

• isDynamic: boolean

Returns​

void

Whether or not the physics body moves in response to forces. Defaults to true.

Remarks​

Once set, this property cannot be changed. This is negated and mapped to the Matter.js static property.

Implementation of​

PhysicsBodyOptions.isDynamic

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:388


mass​

Get Signature​

get mass(): number

The mass of the body.

Remarks​

Density will automatically be calculated when mass is set.

Returns​

number

Set Signature​

set mass(mass): void

The mass of the body.

Remarks​

Density will automatically be calculated when mass is set.

Parameters​

• mass: number

Returns​

void

The mass of the body.

Remarks​

Density will automatically be calculated when mass is set.

Implementation of​

PhysicsBodyOptions.mass

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:444


node​

Get Signature​

get node(): M2Node

Returns​

M2Node

Set Signature​

set node(node): void

Parameters​

• node: M2Node

Returns​

void

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:367


physics​

Get Signature​

get physics(): Physics

Returns​

Physics

Set Signature​

set physics(physics): void

Parameters​

• physics: Physics

Returns​

void

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:328


resting​

Get Signature​

get resting(): boolean

Whether or not the physics body currently moves in response to forces. Defaults to false.

Remarks​

Unlike isDynamic, this property can be changed after the body is created. This is mapped to the Matter.js sleeping property.

Returns​

boolean

Set Signature​

set resting(resting): void

Whether or not the physics body currently moves in response to forces. Defaults to false.

Remarks​

Unlike isDynamic, this property can be changed after the body is created. This is mapped to the Matter.js sleeping property.

Parameters​

• resting: boolean

Returns​

void

Whether or not the physics body currently moves in response to forces. Defaults to false.

Remarks​

Unlike isDynamic, this property can be changed after the body is created. This is mapped to the Matter.js sleeping property.

Implementation of​

PhysicsBodyOptions.resting

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:396


restitution​

Get Signature​

get restitution(): number

How elastic (bouncy) the body is.

Remarks​

Range is 0 to 1. 0 means collisions are not elastic at all (no bouncing), 1 means collisions are perfectly elastic. Defaults to 0. This is mapped to the Matter.js restitution property.

Returns​

number

Set Signature​

set restitution(restitution): void

How elastic (bouncy) the body is.

Remarks​

Range is 0 to 1. 0 means collisions are not elastic at all (no bouncing), 1 means collisions are perfectly elastic. Defaults to 0. This is mapped to the Matter.js restitution property.

Parameters​

• restitution: number

Returns​

void

How elastic (bouncy) the body is.

Remarks​

Range is 0 to 1. 0 means collisions are not elastic at all (no bouncing), 1 means collisions are perfectly elastic. Defaults to 0. This is mapped to the Matter.js restitution property.

Implementation of​

PhysicsBodyOptions.restitution

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:404


speed​

Get Signature​

get speed(): number

Body speed.

Remarks​

If speed is set, the direction will be maintained when velocity is updated.

Returns​

number

Set Signature​

set speed(speed): void

Body speed.

Remarks​

If speed is set, the direction will be maintained when velocity is updated.

Parameters​

• speed: number

Returns​

void

Body speed.

Remarks​

If speed is set, the direction will be maintained when velocity is updated.

Implementation of​

PhysicsBodyOptions.speed

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:465


velocity​

Get Signature​

get velocity(): Vector

The velocity of the body.

Returns​

Vector

Set Signature​

set velocity(velocity): void

The velocity of the body.

Parameters​

• velocity: Vector

Returns​

void

The velocity of the body.

Implementation of​

PhysicsBodyOptions.velocity

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:350

Methods​

applyForce()​

applyForce(force, at?): void

Applies a force to the body in a single time step.

Parameters​

• force: Vector

force to apply as a vector.

• at?: Point

the point at which to apply the force, relative to the body's position in scene coordinates.

Returns​

void

Remarks​

if at is not specified, the force is applied at the body's current position.

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:114


initialize()​

initialize(physics): void

Parameters​

• physics: Physics

Returns​

void

Defined in​

m2c2kit/packages/physics/src/PhysicsBody.ts:28