Skip to main content

Class: RigidBody

Defined in: physics/rigid-body.ts:78

A rigid body participating in a PhysicsWorld simulation. Stores the body's shape, transform, motion state, and mass properties.

Constructors

Constructor

new RigidBody(options): RigidBody

Defined in: physics/rigid-body.ts:129

Creates a new RigidBody instance.

Parameters

options

RigidBodyOptions

The options for the body.

Returns

RigidBody

Properties

angle

angle: number

Defined in: physics/rigid-body.ts:81


angularDrag

readonly angularDrag: number

Defined in: physics/rigid-body.ts:107


angularVelocity

angularVelocity: number

Defined in: physics/rigid-body.ts:85


friction

readonly friction: number

Defined in: physics/rigid-body.ts:105


id

readonly id: number

Defined in: physics/rigid-body.ts:87


inertia

readonly inertia: number

Defined in: physics/rigid-body.ts:99


inverseInertia

readonly inverseInertia: number

Defined in: physics/rigid-body.ts:101


inverseMass

readonly inverseMass: number

Defined in: physics/rigid-body.ts:97


isSensor

readonly isSensor: boolean

Defined in: physics/rigid-body.ts:93


isStatic

readonly isStatic: boolean

Defined in: physics/rigid-body.ts:91


mass

readonly mass: number

Defined in: physics/rigid-body.ts:95


position

position: Vector2

Defined in: physics/rigid-body.ts:79


restitution

readonly restitution: number

Defined in: physics/rigid-body.ts:103


shape

readonly shape: Shape

Defined in: physics/rigid-body.ts:89


userData?

optional userData?: unknown

Defined in: physics/rigid-body.ts:113

Arbitrary data associated with this body by the consumer (e.g. an ECS entity id). Not read or written by the physics simulation itself.


velocity

velocity: Vector2

Defined in: physics/rigid-body.ts:83

Accessors

aabb

Get Signature

get aabb(): Rect

Defined in: physics/rigid-body.ts:179

The conservative axis-aligned bounding box of the body, used for broad-phase collision detection.

Returns

Rect

Methods

applyImpulse()

applyImpulse(impulse, contactPoint): void

Defined in: physics/rigid-body.ts:204

Applies a linear and angular impulse to the body at a world-space contact point relative to its center of mass.

Parameters

impulse

Vector2

The impulse to apply.

contactPoint

Vector2

The point at which to apply the impulse, relative to the body's center of mass.

Returns

void


applyTorque()

applyTorque(torque, deltaTimeInSeconds): void

Defined in: physics/rigid-body.ts:220

Applies a torque to the body, changing its angular velocity by torque * inverseInertia * deltaTimeInSeconds. Unlike applyImpulse, which is an instantaneous change, this represents a torque acting continuously over deltaTimeInSeconds, so it must be called every step to sustain a continuous spin (the same way gravity is integrated). Has no effect on static bodies, whose inverseInertia is always zero.

Parameters

torque

number

The torque to apply, in N·m.

deltaTimeInSeconds

number

The duration the torque acts over.

Returns

void