Skip to main content

Class: Physics

physics/physics.Physics

Handles physics for bodies added to the engine.

Raycasting can only check against objects in the phsyics engine's collisions space.

At the start of each update call the static G_CONF variable is set to the instances CONFIG variable. This allows for easy access to the physics config from other parts of the physics system.

Implements

Constructors

constructor

โ€ข new Physics(gravity?)

Create an Physics instance.

Parameters

NameTypeDescription
gravity?vec2The gravitional force applied to objects in the system

Defined in

src/physics/physics.ts:169

Properties

CONFIG

โ€ข CONFIG: Object

Type declaration

NameType
ACUMMULATE_IMPULSEboolean
CACHED_CONTACTS_TOLERANCEnumber
CONSTRAINT_ITERATIONSnumber
EPA_MAX_ITERATIONSnumber
EPA_TOLERANCEnumber
POINT_SIZEnumber
POSITION_DAMPINGnumber
POSITION_ITERATIONSnumber
POSITION_SCALEnumber
POSITION_SLOPnumber
POSITION_WARMINGnumber
RESTITUTION_THRESHOLDnumber
VELOCITY_ITERATIONSnumber
WARM_IMPULSEboolean

Defined in

src/physics/physics.ts:113


broadphaseTime

โ€ข broadphaseTime: number = 0

The time in ms that the last broadphase collision detection step took.

Defined in

src/physics/physics.ts:132


collisionSolveTime

โ€ข collisionSolveTime: number = 0

The time in ms that the last collision solving steps took.

Defined in

src/physics/physics.ts:142


collisionsSpace

โ€ข collisionsSpace: CollisionsSpace

Defined in

src/physics/physics.ts:119


constraintSpace

โ€ข constraintSpace: ConstraintSpace

Defined in

src/physics/physics.ts:120


constraintTime

โ€ข constraintTime: number = 0

The time in ms that the last constraint solving steps took.

Defined in

src/physics/physics.ts:147


debug

โ€ข debug: boolean = false

Enable/disable debug tools.

Defined in

src/physics/physics.ts:162


dynamicsSpace

โ€ข dynamicsSpace: DynamicsSpace

Defined in

src/physics/physics.ts:118


dynamicsTime

โ€ข dynamicsTime: number = 0

The time in ms that the last dynamics solving steps took.

Defined in

src/physics/physics.ts:152


fluidTime

โ€ข fluidTime: number = 0

The time in ms that the last fluid solving steps took.

Defined in

src/physics/physics.ts:157


fluids

โ€ข fluids: Fluid[] = []

Defined in

src/physics/physics.ts:122


gravity

โ€ข Private gravity: vec2

Defined in

src/physics/physics.ts:115


narrowphaseTime

โ€ข narrowphaseTime: number = 0

The time in ms that the last narrowphase collision detection step took.

Defined in

src/physics/physics.ts:137


physicsTime

โ€ข physicsTime: number = 0

The amount of time in ms that the last physics step took.

Defined in

src/physics/physics.ts:127


G_CONF

โ–ช Static G_CONF: Object

Type declaration

NameType
ACUMMULATE_IMPULSEboolean
CACHED_CONTACTS_TOLERANCEnumber
CONSTRAINT_ITERATIONSnumber
EPA_MAX_ITERATIONSnumber
EPA_TOLERANCEnumber
POINT_SIZEnumber
POSITION_DAMPINGnumber
POSITION_ITERATIONSnumber
POSITION_SCALEnumber
POSITION_SLOPnumber
POSITION_WARMINGnumber
RESTITUTION_THRESHOLDnumber
VELOCITY_ITERATIONSnumber
WARM_IMPULSEboolean

Defined in

src/physics/physics.ts:111

Methods

addBodies

โ–ธ addBodies(...bodies): void

Adds the given bodies to the world's dynamics and collisions spaces.

Parameters

NameTypeDescription
...bodiesRigidBody[]The bodies to add

Returns

void

Defined in

src/physics/physics.ts:383


addBody

โ–ธ addBody(body): void

Adds a {@link Rigidbody} to the world's dynamics and collisions spaces.

Parameters

NameTypeDescription
bodyRigidBodyThe body to add

Returns

void

Defined in

src/physics/physics.ts:373


addCollisionObj

โ–ธ addCollisionObj(c): void

Adds a CollisionObject to the world's collisions space.

Parameters

NameTypeDescription
cCollisionObjectThe collision object to add

Returns

void

Defined in

src/physics/physics.ts:355


addConstraint

โ–ธ addConstraint(constraint): void

Adds a Constraint to the world's constraint space.

Parameters

NameTypeDescription
constraintConstraintThe constraint to add

Returns

void

Defined in

src/physics/physics.ts:441


addDynamicsObj

โ–ธ addDynamicsObj(obj): void

Adds a RigidBody to the world's dynamics space.

Parameters

NameTypeDescription
objRigidBodyThe object to add

Returns

void

Defined in

src/physics/physics.ts:364


addFluid

โ–ธ addFluid(fluid): void

Adds the given fluid to the physics world.

Parameters

NameTypeDescription
fluidFluidThe fluid to add

Returns

void

Defined in

src/physics/physics.ts:466


drawDebug

โ–ธ drawDebug(): void

Returns

void

Defined in

src/physics/physics.ts:273


getGravity

โ–ธ getGravity(): vec2

Gets the gravity vector the physics world is using.

Returns

vec2

The gravity in use

Defined in

src/physics/physics.ts:513


pick

โ–ธ pick(point): CollisionObject[]

Point pick objects.

NOTE: Picking only checks objects in the CollisionsSpace.

Parameters

NameTypeDescription
pointvec2The point to pick objects at

Returns

CollisionObject[]

Defined in

src/physics/physics.ts:311


raycast

โ–ธ raycast(ray): CollisionObject[]

raycast objects.

NOTE: Raycast only checks objects in the CollisionsSpace.

Parameters

NameTypeDescription
rayRayThe ray to cast

Returns

CollisionObject[]

Defined in

src/physics/physics.ts:335


removeAllBodies

โ–ธ removeAllBodies(): void

Removes all bodies from the world's dynamics and collision spaces.

Returns

void

Defined in

src/physics/physics.ts:431


removeAllConstraints

โ–ธ removeAllConstraints(): void

Removes all constraints from the world.

Returns

void

Defined in

src/physics/physics.ts:457


removeAllFluids

โ–ธ removeAllFluids(): void

Removes all fluids from the world.

Returns

void

Defined in

src/physics/physics.ts:491


removeBodies

โ–ธ removeBodies(...bodies): void

Removes the given bodies from the world's dynamics and collision spaces.

Parameters

NameTypeDescription
...bodiesRigidBody[]The bodies to remove

Returns

void

Defined in

src/physics/physics.ts:422


removeBody

โ–ธ removeBody(body): void

Removes a {@link Rigidbody} from the world's dynamics and collisions spaces.

Parameters

NameTypeDescription
bodyRigidBodyThe body to remove

Returns

void

Defined in

src/physics/physics.ts:412


removeCollisionObj

โ–ธ removeCollisionObj(c): void

Removes a CollisionObject from the world's collisions space.

Parameters

NameTypeDescription
cCollisionObjectThe collision object to remove

Returns

void

Defined in

src/physics/physics.ts:394


removeConstraint

โ–ธ removeConstraint(constraint): void

Removes a Constraint from the world's constraint space.

Parameters

NameTypeDescription
constraintConstraintThe constraint to remove

Returns

void

Defined in

src/physics/physics.ts:450


removeDynamicsObj

โ–ธ removeDynamicsObj(obj): void

Removes a RigidBody from the world's dynamics space.

Parameters

NameTypeDescription
objRigidBodyThe object to remove

Returns

void

Defined in

src/physics/physics.ts:403


removeFluid

โ–ธ removeFluid(fluid): void

Removes the given fluid from the physics world.

Parameters

NameTypeDescription
fluidFluidThe fluid to remove

Returns

void

Defined in

src/physics/physics.ts:480


setGravity

โ–ธ setGravity(gravity): void

Sets the gravity to use in the physics world.

Parameters

NameTypeDescription
gravityvec2The new gravity to use

Returns

void

Defined in

src/physics/physics.ts:502


update

โ–ธ update(ts): void

Steps the physics world forward by the given delta time.

Order of updates is very important.

Parameters

NameTypeDescription
tsTimeStepThe TimeStep for this update.

Returns

void

Implementation of

System.update

Defined in

src/physics/physics.ts:195