Skip to content

RigidBodyComponent

Defined in: physics/src/RigidBodyComponent.ts:26

Wraps a Rapier rigid body. All public API values are in pixels.

Component ordering: Transform must be added before RigidBodyComponent.

  • Component

new RigidBodyComponent(config): RigidBodyComponent

Defined in: physics/src/RigidBodyComponent.ts:51

RigidBodyConfig

RigidBodyComponent

Component.constructor

_bodyHandle: number = -1

Defined in: physics/src/RigidBodyComponent.ts:34

Internal

Rapier body handle, set during onAdd.


_currPosition: Vec2 = Vec2.ZERO

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

Internal

Current authoritative position (post physics step).


_currRotation: number = 0

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

Internal

Current authoritative rotation (post physics step).


_prevPosition: Vec2 = Vec2.ZERO

Defined in: physics/src/RigidBodyComponent.ts:37

Internal

Previous position for interpolation.


_prevRotation: number = 0

Defined in: physics/src/RigidBodyComponent.ts:39

Internal

Previous rotation for interpolation.


_teleported: boolean = false

Defined in: physics/src/RigidBodyComponent.ts:45

Internal

If true, skip interpolation on next frame (teleport).


enabled: boolean

Defined in: core/dist/index.d.ts:542

Whether this component is active. Disabled components are skipped by ComponentUpdateSystem.

Component.enabled


entity: Entity

Defined in: core/dist/index.d.ts:540

Back-reference to the owning entity. Set by the engine when the component is added to an entity. Do not set manually.

Component.entity


syncRotation: boolean

Defined in: physics/src/RigidBodyComponent.ts:31

If false, physics will not write rotation back to Transform.


readonly type: BodyType

Defined in: physics/src/RigidBodyComponent.ts:28

Body type (dynamic, static, kinematic).

get context(): EngineContext

Defined in: core/dist/index.d.ts:554

Access the EngineContext from the entity’s scene. Throws if the entity is not in a scene.

EngineContext

Component.context


get scene(): Scene

Defined in: core/dist/index.d.ts:549

Access the entity’s scene. Throws if the entity is not in a scene. Prefer this over this.entity.scene! in component methods.

Scene

Component.scene

_runCleanups(): void

Defined in: core/dist/index.d.ts:584

Internal

Run and clear all registered cleanups. Called by Entity.remove() and Entity._performDestroy() before onRemove/onDestroy.

void

Component._runCleanups


protected addCleanup(fn): void

Defined in: core/dist/index.d.ts:578

Register a cleanup function to run when this component is removed or destroyed.

() => void

void

Component.addCleanup


afterRestore(data): void

Defined in: physics/src/RigidBodyComponent.ts:237

Restore runtime state (velocities) after the Rapier body has been created.

unknown

void

Component.afterRestore


applyForce(force): void

Defined in: physics/src/RigidBodyComponent.ts:92

Apply a force (in pixels) at the center of mass.

Vec2Like

void


applyImpulse(impulse): void

Defined in: physics/src/RigidBodyComponent.ts:105

Apply an impulse (in pixels) at the center of mass.

Vec2Like

void


applyTorque(torque): void

Defined in: physics/src/RigidBodyComponent.ts:154

Apply torque.

number

void


optional fixedUpdate(dt): void

Defined in: core/dist/index.d.ts:594

Called every fixed timestep by the built-in ComponentUpdateSystem.

number

void

Component.fixedUpdate


getAngularVelocity(): number

Defined in: physics/src/RigidBodyComponent.ts:168

Get angular velocity in radians/s.

number


getVelocity(): Vec2

Defined in: physics/src/RigidBodyComponent.ts:143

Get linear velocity in pixels/s.

Vec2


protected listen<T>(entity, token, handler): void

Defined in: core/dist/index.d.ts:574

Subscribe to events on any entity, auto-unsubscribe on removal.

T

Entity

EventToken<T>

(data) => void

void

Component.listen


protected listenScene<T>(token, handler): void

Defined in: core/dist/index.d.ts:576

Subscribe to scene-level bubbled events, auto-unsubscribe on removal.

T

EventToken<T>

(data, entity) => void

void

Component.listenScene


lockRotations(locked): void

Defined in: physics/src/RigidBodyComponent.ts:182

Lock or unlock rotations at runtime.

boolean

void


onAdd(): void

Defined in: physics/src/RigidBodyComponent.ts:58

Called when the component is added to an entity.

void

Component.onAdd


onDestroy(): void

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

Called when the component is destroyed (entity destroyed or component removed).

void

Component.onDestroy


optional onRemove(): void

Defined in: core/dist/index.d.ts:588

Called when the component is removed from an entity.

void

Component.onRemove


serialize(): RigidBodyData

Defined in: physics/src/RigidBodyComponent.ts:206

Serialize the component into a plain data object.

RigidBodyData

Component.serialize


protected service<T>(key): T

Defined in: core/dist/index.d.ts:564

Lazy proxy-based service resolution. Can be used at field-declaration time:

readonly camera = this.service(CameraKey);

The actual resolution is deferred until first property access.

T extends object

ServiceKey<T>

T

Component.service


setAngularVelocity(v): void

Defined in: physics/src/RigidBodyComponent.ts:161

Set angular velocity in radians/s.

number

void


setEnabledTranslations(enableX, enableY): void

Defined in: physics/src/RigidBodyComponent.ts:175

Set which translation axes are enabled at runtime.

boolean

boolean

void


setPosition(x, y): void

Defined in: physics/src/RigidBodyComponent.ts:189

Teleport to a position in pixels. Skips interpolation on next frame.

number

number

void


setVelocity(velocity): void

Defined in: physics/src/RigidBodyComponent.ts:118

Set linear velocity in pixels/s.

Vec2Like

void


setVelocityX(vx): void

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

Set only the X component of velocity (px/s), preserving Y.

number

void


setVelocityY(vy): void

Defined in: physics/src/RigidBodyComponent.ts:137

Set only the Y component of velocity (px/s), preserving X.

number

void


protected sibling<C>(cls): C

Defined in: core/dist/index.d.ts:572

Lazy proxy-based sibling component resolution. Can be used at field-declaration time:

readonly anim = this.sibling(AnimatedSpriteComponent);

The actual resolution is deferred until first property access.

C extends Component

ComponentClass<C>

C

Component.sibling


optional update(dt): void

Defined in: core/dist/index.d.ts:592

Called every frame by the built-in ComponentUpdateSystem.

number

void

Component.update


protected use<T>(key): T

Defined in: core/dist/index.d.ts:556

Resolve a service by key, cached after first lookup.

T

ServiceKey<T>

T

Component.use


static fromSnapshot(data): RigidBodyComponent

Defined in: physics/src/RigidBodyComponent.ts:223

Create a RigidBodyComponent from a serialized snapshot.

RigidBodyData

RigidBodyComponent