Skip to content

PhysicsWorld

Defined in: physics/src/PhysicsWorld.ts:36

Central Rapier2D wrapper. All public API values are in pixels. Pixel-to-meter conversion is handled internally.

new PhysicsWorld(config?): PhysicsWorld

Defined in: physics/src/PhysicsWorld.ts:56

PhysicsConfig

PhysicsWorld

readonly _colliderComponents: Map<number, ColliderComponent>

Defined in: physics/src/PhysicsWorld.ts:46

Internal

Map from collider handle to ColliderComponent.


readonly bodyMap: Map<number, Entity>

Defined in: physics/src/PhysicsWorld.ts:41

Map from Rapier body handle to Entity.


readonly colliderMap: Map<number, Entity>

Defined in: physics/src/PhysicsWorld.ts:43

Map from Rapier collider handle to Entity.


readonly pixelsPerMeter: number

Defined in: physics/src/PhysicsWorld.ts:38

Pixels per meter conversion factor.

createBody(entity, config): number

Defined in: physics/src/PhysicsWorld.ts:131

Create a rigid body and register it. Returns the Rapier handle.

Entity

RigidBodyConfig

number


createCollider(entity, bodyHandle, config, component): number

Defined in: physics/src/PhysicsWorld.ts:170

Create a collider attached to a body. Returns the Rapier collider handle.

Entity

number

ColliderConfig

ColliderComponent

number


destroy(): void

Defined in: physics/src/PhysicsWorld.ts:458

Destroy the physics world and free resources.

void


getBody(handle): RigidBody | undefined

Defined in: physics/src/PhysicsWorld.ts:304

Get a Rapier rigid body by handle.

number

RigidBody | undefined


getCollider(handle): Collider | undefined

Defined in: physics/src/PhysicsWorld.ts:313

Get a Rapier collider by handle.

number

Collider | undefined


processCollisionEvents(): void

Defined in: physics/src/PhysicsWorld.ts:84

Drain collision events and dispatch to ColliderComponents.

void


queryOverlapping(colliderHandle): Entity[]

Defined in: physics/src/PhysicsWorld.ts:360

Return all entities whose colliders currently overlap the given collider.

number

Entity[]


raycast(origin, direction, maxDistance, options?): RaycastHit | null

Defined in: physics/src/PhysicsWorld.ts:322

Cast a ray and return the first hit. All values in pixels.

Vec2Like

Vec2Like

number

number

RaycastHit | null


removeBody(handle): void

Defined in: physics/src/PhysicsWorld.ts:286

Remove a rigid body and all its colliders from the world.

number

void


setGravity(x, y): void

Defined in: physics/src/PhysicsWorld.ts:126

Set gravity in pixels/s².

number

number

void


snapshot(): object

Defined in: physics/src/PhysicsWorld.ts:377

Inspector-facing snapshot of the current rigid bodies and active contacts.

object

bodies: object[]

contacts: object[]


step(dt): void

Defined in: physics/src/PhysicsWorld.ts:78

Step the physics simulation. dt is in seconds.

number

void


toMeters(pixels): number

Defined in: physics/src/PhysicsWorld.ts:68

Convert pixels to meters.

number

number


toPixels(meters): number

Defined in: physics/src/PhysicsWorld.ts:73

Convert meters to pixels.

number

number