Engine

The physics engine

Constructor

new Engine(World, options)

Parameters:
NameTypeDescription
WorldWorld

World the physics engine should run on

optionsObject

Physics options

Properties
NameTypeAttributesDefaultDescription
substepsnumber<optional>
3

Number of substeps per tick

velocityIterationsnumber<optional>
2

Number of velocity solver iterations per tick

positionIterationsnumber<optional>
3

Number of position solver iterations per tick

constraintIterationsnumber<optional>
1

Number of constraint solver iterations per tick

overlapMarginnumber<optional>
0.01

Amount of overlap required for a collision to register

slopnumber<optional>
1

Amount of acceptable penetration

positionDampennumber<optional>
0.9

How much the position impulse is multiplied by. Decrease if unstable.

Methods

update(deltaopt)

Ticks the engine one frame

Parameters:
NameTypeAttributesDescription
deltanumber<optional>

Engine tick duration, in seconds

collides(bodyA, bodyB) → {boolean}

Checks if bodyA and bodyB are colliding

Parameters:
NameTypeDescription
bodyACollisionShape

1st body to check

bodyBCollisionShape

2nd body to check

Returns:

If the bodies are colliding

Type: 
boolean

cleansePair(pair) → {boolean}

Deletes the collision pair

Parameters:
NameTypeDescription
pairObject

Pair to delete

Returns:

If pair was successfully removed, meaning they are no longer colliding

Type: 
boolean

solveVelocity()

Solves velocity constriants on current collision pairs Also clears collision pairs that are no longer valid (they haven't collided this frame)

preSolvePosition()

Prepares contacts for position solver

solvePosition()

Solves position intersections between bodies based on their collision pairs

postSolvePosition()

Cleans up after position solver