Class: PhysicsBody
A rigid body model added to a node to enable physics simulation.
Param
Implements
Constructors
new PhysicsBody()
new PhysicsBody(
options
):PhysicsBody
Parameters
• options: PhysicsBodyOptions
Returns
Source
Properties
EDGE_LOOP_DEFAULT_THICKNESS
private
readonly
EDGE_LOOP_DEFAULT_THICKNESS:50
=50
Source
_allowsRotation
private
_allowsRotation:boolean
=true
Source
_body?
optional
_body:Body
Source
_isDynamic
private
_isDynamic:boolean
=true
Source
_node?
optional
_node:M2Node
Source
_physics?
private
optional
_physics:Physics
Source
needsInitialization
needsInitialization:
boolean
=true
Source
options
options:
PhysicsBodyOptions
Source
previousInertia
private
previousInertia:number
=NaN
Source
Accessors
allowsRotation
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
.
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
boolean
Source
physics/src/PhysicsBody.ts:436
angularVelocity
get
angularVelocity():number
Body angular velocity.
set
angularVelocity(angularVelocity
):void
Body angular velocity.
Parameters
• angularVelocity: number
Returns
number
Source
physics/src/PhysicsBody.ts:473
area
get
area():number
The area of the body's convex hull.
Remarks
This is a read-only property.
Returns
number
Source
physics/src/PhysicsBody.ts:461
body
get
body():Body
set
body(body
):void
Parameters
• body: Body
Returns
Body
Source
physics/src/PhysicsBody.ts:339
categoryBitMask
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.
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
number
Source
physics/src/PhysicsBody.ts:481
collisionBitMask
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).
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
number
Source
physics/src/PhysicsBody.ts:493
damping
get
damping():number
Friction due to air forces on the body, in the range [0, 1].
set
damping(damping
):void
Friction due to air forces on the body, in the range [0, 1].
Parameters
• damping: number
Returns
number
Source
physics/src/PhysicsBody.ts:420
density
get
density():number
Body density (mass per unit area)
Remarks
Mass will automatically be calculated when density is set.
set
density(density
):void
Body density (mass per unit area)
Remarks
Mass will automatically be calculated when density is set.
Parameters
• density: number
Returns
number
Source
physics/src/PhysicsBody.ts:448
friction
get
friction():number
Friction of the body, in the range [0, 1].
set
friction(friction
):void
Friction of the body, in the range [0, 1].
Parameters
• friction: number
Returns
number
Source
physics/src/PhysicsBody.ts:412
isDynamic
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.
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
boolean
Source
physics/src/PhysicsBody.ts:388
mass
get
mass():number
The mass of the body.
Remarks
Density will automatically be calculated when mass is set.
set
mass(mass
):void
The mass of the body.
Remarks
Density will automatically be calculated when mass is set.
Parameters
• mass: number
Returns
number
Source
physics/src/PhysicsBody.ts:444
node
get
node():M2Node
set
node(node
):void
Parameters
• node: M2Node
Returns
M2Node
Source
physics/src/PhysicsBody.ts:367
physics
get
physics():Physics
set
physics(physics
):void
Parameters
• physics: Physics
Returns
Source
physics/src/PhysicsBody.ts:328
resting
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.
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
boolean
Source
physics/src/PhysicsBody.ts:396
restitution
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.
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
number
Source
physics/src/PhysicsBody.ts:404
speed
get
speed():number
Body speed.
Remarks
If speed is set, the direction will be maintained when velocity is updated.
set
speed(speed
):void
Body speed.
Remarks
If speed is set, the direction will be maintained when velocity is updated.
Parameters
• speed: number
Returns
number
Source
physics/src/PhysicsBody.ts:465
velocity
get
velocity():Vector
The velocity of the body.
set
velocity(velocity
):void
The velocity of the body.
Parameters
• velocity: Vector
Returns
Source
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
.
Source
physics/src/PhysicsBody.ts:114
createCircleBody()
private
createCircleBody(options
):Body
Parameters
• options: PhysicsBodyOptions
Returns
Body
Source
physics/src/PhysicsBody.ts:134
createEdgeLoopBody()
private
createEdgeLoopBody(options
):Body
Parameters
• options: PhysicsBodyOptions
Returns
Body
Source
physics/src/PhysicsBody.ts:192
createRectBody()
private
createRectBody(options
):Body
Parameters
• options: PhysicsBodyOptions
Returns
Body
Source
physics/src/PhysicsBody.ts:162
initialize()
initialize(
physics
):void
Parameters
• physics: Physics
Returns
void