PhysicsWorld
Defined in: physics/src/PhysicsWorld.ts:92
Central Rapier2D wrapper. All public API values are in pixels. Pixel-to-meter conversion is handled internally.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PhysicsWorld(
config?):PhysicsWorld
Defined in: physics/src/PhysicsWorld.ts:126
Parameters
Section titled “Parameters”config?
Section titled “config?”Returns
Section titled “Returns”PhysicsWorld
Properties
Section titled “Properties”_colliderComponents
Section titled “_colliderComponents”
readonly_colliderComponents:Map<number,ColliderComponent>
Defined in: physics/src/PhysicsWorld.ts:102
Internal
Map from collider handle to ColliderComponent.
_jointsByBody
Section titled “_jointsByBody”
readonly_jointsByBody:Map<number,Set<JointRecord>>
Defined in: physics/src/PhysicsWorld.ts:104
Internal
Joint records indexed by each attached body handle.
bodyMap
Section titled “bodyMap”
readonlybodyMap:Map<number,Entity>
Defined in: physics/src/PhysicsWorld.ts:97
Map from Rapier body handle to Entity.
colliderMap
Section titled “colliderMap”
readonlycolliderMap:Map<number,Entity>
Defined in: physics/src/PhysicsWorld.ts:99
Map from Rapier collider handle to Entity.
pixelsPerMeter
Section titled “pixelsPerMeter”
readonlypixelsPerMeter:number
Defined in: physics/src/PhysicsWorld.ts:94
Pixels per meter conversion factor.
Accessors
Section titled “Accessors”elapsed
Section titled “elapsed”Get Signature
Section titled “Get Signature”get elapsed():
number
Defined in: physics/src/PhysicsWorld.ts:151
Total simulated time in seconds — the sum of every step’s dt. Tracks the simulation, not the wall clock, so it respects pause and timeScale.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”_detachJointsForBody()
Section titled “_detachJointsForBody()”_detachJointsForBody(
handle):void
Defined in: physics/src/PhysicsWorld.ts:1168
Internal
Detach every joint touching this body. Called when the body is disabled: a dormant entity may be reused as something else, and a joint is cross-life state the same way momentum and landed contacts are — the next life must not wake up tethered to the old partner. Unlike removal, disabling leaves the body in Rapier, so the joints are freed here.
Parameters
Section titled “Parameters”handle
Section titled “handle”number
Returns
Section titled “Returns”void
_forgetColliderContacts()
Section titled “_forgetColliderContacts()”_forgetColliderContacts(
handle):void
Defined in: physics/src/PhysicsWorld.ts:751
Internal
Drop any landed-rider state naming this collider. Rapier reuses collider handles, so a handle leaving the simulation (removed or disabled) must not stay remembered as “landed” on a one-way platform — the next collider with the same handle would inherit it.
Parameters
Section titled “Parameters”handle
Section titled “handle”number
Returns
Section titled “Returns”void
_removeJoint()
Section titled “_removeJoint()”_removeJoint(
record):void
Defined in: physics/src/PhysicsWorld.ts:1153
Internal
Remove a live joint and unlink its record.
Parameters
Section titled “Parameters”record
Section titled “record”JointRecord
Returns
Section titled “Returns”void
_setContactFilterEnabled()
Section titled “_setContactFilterEnabled()”_setContactFilterEnabled(
handle,enabled):void
Defined in: physics/src/PhysicsWorld.ts:245
Internal
Toggle contact filtering for a live collider — flips Rapier’s
hook flag and the set that decides whether step passes hooks at all.
Parameters
Section titled “Parameters”handle
Section titled “handle”number
enabled
Section titled “enabled”boolean
Returns
Section titled “Returns”void
addJoint()
Section titled “addJoint()”addJoint(
bodyA,bodyB,config):JointHandle
Defined in: physics/src/PhysicsWorld.ts:506
Connect two live rigid bodies with a spring or rope joint. All lengths and anchors are in pixels.
Parameters
Section titled “Parameters”config
Section titled “config”Returns
Section titled “Returns”castShape()
Section titled “castShape()”castShape(
shape,origin,direction,maxDistance,options?):RaycastHit|null
Defined in: physics/src/PhysicsWorld.ts:879
Sweep shape from origin along direction and return the first thing
it would hit, or null if nothing is struck within maxDistance. All
values in pixels.
This is the swept counterpart to queryShape, which only reports what a
shape overlaps where it already stands. Use it to test a move before
committing to it: carrying a rider on a moving platform, spotting a
closing platform before it traps the player, or checking clearance for a
fast fall.
distance is how far the shape travelled, point the world contact
point, and normal the surface normal on the entity that was hit. A
shape already overlapping something at origin reports that hit at
distance: 0. The direction is normalized internally, so any non-zero
vector works; a zero-length direction throws. excludeEntity skips every
collider of that entity — pass the mover when the sweep starts inside its
own collider.
Parameters
Section titled “Parameters”origin
Section titled “origin”Vec2Like
direction
Section titled “direction”Vec2Like
maxDistance
Section titled “maxDistance”number
options?
Section titled “options?”excludeEntity?
Section titled “excludeEntity?”Entity
filterGroups?
Section titled “filterGroups?”number
rotation?
Section titled “rotation?”number
Returns
Section titled “Returns”RaycastHit | null
createBody()
Section titled “createBody()”createBody(
entity,config):number
Defined in: physics/src/PhysicsWorld.ts:464
Create a rigid body and register it. Returns the Rapier handle.
Parameters
Section titled “Parameters”entity
Section titled “entity”Entity
config
Section titled “config”Returns
Section titled “Returns”number
createCollider()
Section titled “createCollider()”createCollider(
entity,bodyHandle,config,component):number
Defined in: physics/src/PhysicsWorld.ts:555
Create a collider attached to a body. Returns the Rapier collider handle.
Parameters
Section titled “Parameters”entity
Section titled “entity”Entity
bodyHandle
Section titled “bodyHandle”number
config
Section titled “config”component
Section titled “component”Returns
Section titled “Returns”number
destroy()
Section titled “destroy()”destroy():
void
Defined in: physics/src/PhysicsWorld.ts:1097
Destroy the physics world and free resources.
Returns
Section titled “Returns”void
getBody()
Section titled “getBody()”getBody(
handle):RigidBody|undefined
Defined in: physics/src/PhysicsWorld.ts:791
Get a Rapier rigid body by handle.
Parameters
Section titled “Parameters”handle
Section titled “handle”number
Returns
Section titled “Returns”RigidBody | undefined
getCollider()
Section titled “getCollider()”getCollider(
handle):Collider|undefined
Defined in: physics/src/PhysicsWorld.ts:800
Get a Rapier collider by handle.
Parameters
Section titled “Parameters”handle
Section titled “handle”number
Returns
Section titled “Returns”Collider | undefined
processCollisionEvents()
Section titled “processCollisionEvents()”processCollisionEvents():
void
Defined in: physics/src/PhysicsWorld.ts:272
Drain collision events and dispatch them to their ColliderComponents.
Draining and dispatching are separate passes. A handler can retire an entity, and a pooled one goes straight back out of its pool as something else, so both sides of every pair are captured with the life they were queued for before any handler runs. Each side is re-checked immediately before its own callback: the first handler can retire the second side’s receiver. A pair naming a life that has ended, or a collider that was removed mid-drain, is dropped rather than delivered against the changed state.
Returns
Section titled “Returns”void
queryOverlapping()
Section titled “queryOverlapping()”queryOverlapping(
colliderHandle):Entity[]
Defined in: physics/src/PhysicsWorld.ts:994
Return all entities whose colliders currently overlap the given collider.
Parameters
Section titled “Parameters”colliderHandle
Section titled “colliderHandle”number
Returns
Section titled “Returns”Entity[]
queryRadius()
Section titled “queryRadius()”queryRadius(
center,radius,options?):Entity[]
Defined in: physics/src/PhysicsWorld.ts:945
Return all entities with a collider overlapping the circle around
center (pixels). Sugar over queryShape with a circle.
Parameters
Section titled “Parameters”center
Section titled “center”Vec2Like
radius
Section titled “radius”number
options?
Section titled “options?”excludeEntity?
Section titled “excludeEntity?”Entity
filterGroups?
Section titled “filterGroups?”number
Returns
Section titled “Returns”Entity[]
queryShape()
Section titled “queryShape()”queryShape(
shape,position,options?):Entity[]
Defined in: physics/src/PhysicsWorld.ts:959
Return all entities with a collider overlapping shape placed at
position (pixels, rotation in radians). excludeEntity skips every
collider of that entity — pass the querying entity for “what’s around
me” queries.
Parameters
Section titled “Parameters”position
Section titled “position”Vec2Like
options?
Section titled “options?”excludeEntity?
Section titled “excludeEntity?”Entity
filterGroups?
Section titled “filterGroups?”number
rotation?
Section titled “rotation?”number
Returns
Section titled “Returns”Entity[]
raycast()
Section titled “raycast()”raycast(
origin,direction,maxDistance,options?):RaycastHit|null
Defined in: physics/src/PhysicsWorld.ts:816
Cast a ray and return the first hit. All values in pixels.
The direction is normalized internally, so any non-zero vector works —
e.g. target.sub(origin). Throws on a zero-length direction.
excludeEntity skips every collider of that entity — pass the caster
when the ray starts inside its own collider.
Parameters
Section titled “Parameters”origin
Section titled “origin”Vec2Like
direction
Section titled “direction”Vec2Like
maxDistance
Section titled “maxDistance”number
options?
Section titled “options?”excludeEntity?
Section titled “excludeEntity?”Entity
filterGroups?
Section titled “filterGroups?”number
Returns
Section titled “Returns”RaycastHit | null
removeBody()
Section titled “removeBody()”removeBody(
handle):void
Defined in: physics/src/PhysicsWorld.ts:695
Remove a rigid body and all its colliders from the world.
Parameters
Section titled “Parameters”handle
Section titled “handle”number
Returns
Section titled “Returns”void
removeCollider()
Section titled “removeCollider()”removeCollider(
handle):void
Defined in: physics/src/PhysicsWorld.ts:731
Remove a single collider from the world, leaving its body (if any) intact. No-ops if the handle is already gone — removing a body already tears down its colliders, so this covers the case where that ran first.
Parameters
Section titled “Parameters”handle
Section titled “handle”number
Returns
Section titled “Returns”void
setColliderShape()
Section titled “setColliderShape()”setColliderShape(
handle,config,options?):void
Defined in: physics/src/PhysicsWorld.ts:767
Replace a live collider’s shape, keeping its handle, body attachment,
collision groups, and event subscriptions. config is the owning
component’s config, already carrying the new shape.
The body keeps its mass unless recomputeMass asks for it back from
density × the new shape.
Parameters
Section titled “Parameters”handle
Section titled “handle”number
config
Section titled “config”options?
Section titled “options?”recomputeMass?
Section titled “recomputeMass?”boolean
Returns
Section titled “Returns”void
setGravity()
Section titled “setGravity()”setGravity(
x,y):void
Defined in: physics/src/PhysicsWorld.ts:459
Set gravity in pixels/s².
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”void
snapshot()
Section titled “snapshot()”snapshot():
object
Defined in: physics/src/PhysicsWorld.ts:1016
Inspector-facing snapshot of the current rigid bodies and active contacts.
Returns
Section titled “Returns”object
bodies
Section titled “bodies”bodies:
object[]
contacts
Section titled “contacts”contacts:
object[]
step()
Section titled “step()”step(
dt):void
Defined in: physics/src/PhysicsWorld.ts:156
Step the physics simulation. dt is in seconds.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
toMeters()
Section titled “toMeters()”toMeters(
pixels):number
Defined in: physics/src/PhysicsWorld.ts:138
Convert pixels to meters.
Parameters
Section titled “Parameters”pixels
Section titled “pixels”number
Returns
Section titled “Returns”number
toPixels()
Section titled “toPixels()”toPixels(
meters):number
Defined in: physics/src/PhysicsWorld.ts:143
Convert meters to pixels.
Parameters
Section titled “Parameters”meters
Section titled “meters”number
Returns
Section titled “Returns”number