API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classPhysicsBody

@codexo/exojs-physics / physics / stable

A rigid body: a world transform plus mass properties aggregated from its colliders. Dynamic bodies integrate under gravity, accumulated forces/torque and contact impulses each fixed sub-step; static bodies never move; kinematic bodies move by their velocity only and stay immovable under contacts. Drive a body with applyForce, applyTorque and applyImpulse, or set linearVelocityX/linearVelocityY/angularVelocity directly; reposition it (teleport, no velocity) with setTransform.

32
props
7
methods
0
events
Import
import { PhysicsBody } from '@codexo/exojs-physics'

A rigid body: a world transform plus mass properties aggregated from its colliders. Dynamic bodies integrate under gravity, accumulated forces/torque and contact impulses each fixed sub-step; static bodies never move; kinematic bodies move by their velocity only and stay immovable under contacts. Drive a body with applyForce, applyTorque and applyImpulse, or set linearVelocityX/linearVelocityY/angularVelocity directly; reposition it (teleport, no velocity) with setTransform.

Constructors1
Methods7
Attach a collider to this body. Accepts a Collider instance or its ColliderOptions (a convenience that constructs the collider for you). When the body is already in a world, the collider is id-allocated, registered, the mass model is recomputed and the world geometry synchronised immediately; on a free-standing body the collider is simply held until world.add(). Returns the collider.
applyForce(forceX: number, forceY: number): this
Accumulate a world-space force at the centre of mass; integrated on the next sub-step and then cleared. No-op on static/kinematic bodies. Returns this.
applyImpulse(impulseX: number, impulseY: number, pointX?: number, pointY?: number): this
Apply an instantaneous world-space impulse at (pointX, pointY) (world space; defaults to the centre of mass), changing velocity immediately. No-op on static/kinematic bodies (infinite mass). Returns this.
applyTorque(torque: number): this
Accumulate a torque; integrated on the next sub-step and then cleared. No-op on static/kinematic bodies (and fixed-rotation bodies). Returns this.
setTransform(position: Readonly<PointLikeStructural type for any object with a 2D `x`/`y` position.>, angle: number): this
Set the body's world transform. Resets the body's cached collider geometry immediately so subsequent queries see the new placement. Returns this.
synchronizeColliders(): void
Refresh every collider's world geometry from the current transform.
wake(): this
Wake the body if it is asleep, resetting its sleep timer. The rest of its island wakes with it on the next step (a contact to an awake body keeps the whole island awake). Returns this.
Properties32
allowSleep: boolean
When false, this body is never put to sleep. Default true.
angularDamping: number
Angular damping applied to the angular velocity each sub-step.
angularVelocity: number
Angular velocity in rad/s.
fixedRotation: boolean
When true, rotational inertia is treated as infinite.
gravityScale: number
Per-body multiplier on world gravity (e.g. 0 to ignore gravity).
inertia: number
Rotational inertia about the centre of mass (0 for static/kinematic or fixed rotation).
invInertia: number
Inverse rotational inertia (0 = no angular response).
invMass: number
Inverse mass (0 = immovable).
isBullet: boolean
When true, the body's colliders are shape-cast along each step's motion (CCD) so it cannot tunnel through thin geometry.
linearDamping: number
Linear damping applied to the velocity each sub-step.
linearVelocityX: number
Linear velocity X in px/s.
linearVelocityY: number
Linear velocity Y in px/s.
mass: number
Total mass (0 for static/kinematic).
angle: number
Rotation in radians.
attached: boolean
true once the body has been added to a world (guards against double-add).
centerOfMassX: number
Centre of mass in body-local space (relative to the body origin).
centerOfMassY: number
Centre of mass in body-local space (relative to the body origin).
destroyed: boolean
true after the owning world has destroyed this body.
id: number
Stable id, assigned when the body joins a world via world.add(); -1 until then.
isMassReady: boolean
true when the body is ready to simulate. Static/kinematic bodies are always ready (infinite-mass semantics); a dynamic body is ready only once it has at least one positive-density collider.
isSleeping: boolean
true when the body is asleep - skipped by the integrator and solver until woken.
previousAngle: number
Rotation in radians at the start of the most recent fixed step; see previousX. Body angles are continuous and unbounded, never wrapped to a range, so this and angle can be blended with a plain lerp.
previousX: number
World X at the start of the most recent fixed step. With x it brackets the last step, which is what an interpolating presentation blends between; a teleport collapses it onto x. Never read by the solver.
previousY: number
World Y at the start of the most recent fixed step; see previousX.
transform: Readonly<Transform>
The body's world transform (read-only; mutate via setTransform).
worldCenterOfMassX: number
World-space centre of mass X (body origin + rotated local centre of mass).
worldCenterOfMassY: number
World-space centre of mass Y.
x: number
World X.
y: number
World Y.
Source