# @ferret/physics: API (continued)

### CollisionMoveIn

*interface* · `packages/physics/src/collision-world.ts:11`

```ts
interface CollisionMoveIn
```

- `body?: string`
- `pos: [number, number, number]`
- `vel: [number, number, number]`
- `ellipsoid: [number, number, number]`
- `offset?: [number, number, number]`

### CollisionMoveOut

*interface* · `packages/physics/src/collision-world.ts:12`

```ts
interface CollisionMoveOut
```

- `pos: [number, number, number]`

### CollisionRayIn

*interface* · `packages/physics/src/collision-world.ts:9`

```ts
interface CollisionRayIn
```

- `origin: [number, number, number]`
- `dir: [number, number, number]`
- `length: number`
- `mask: number`

### CollisionRayOut

*interface* · `packages/physics/src/collision-world.ts:10`

```ts
interface CollisionRayOut
```

- `point: [number, number, number]`
- `normal: [number, number, number]`
- `distance: number`
- `mesh: number`

### CollisionState

*interface* · `packages/physics/src/collision-world.ts:15`

```ts
interface CollisionState
```

the state of a collision world: a headless scene, its meshes and the bodies swept in it

- `scene?: BABYLON.Scene`
- `meshes: BABYLON.Mesh[]`
- `hulls: Map<string, BABYLON.Mesh>`

### CombineRules

*interface* · `packages/physics/src/materials.ts:21`

```ts
interface CombineRules
```

- `friction: CombineRule`
- `restitution: CombineRule`
- `rollingFriction: CombineRule`
- `[property: string]: CombineRule`

### Constraint

*interface* · `packages/physics/src/kernel.ts:166`

```ts
interface Constraint
```

- `readonly id: number`
- `type: ConstraintType`
- `readonly a: Body`
- `readonly b: Body`
- `length: number`
- `stiffness: number`
- `damping: number`
- `maxForce: number`
- `userData?: unknown`
- `force: number` — force over the last step, N: positive in tension (it pulls the two bodies together), negative in compression
- `stretch: number` — present distance less the length, m
- `broken: boolean`
- `anchor?: Vec3`
- `axis?: Vec3`
- `frames?: ConstraintFrames` — ball, hinge, fixed (a rigid-body kernel): the shared point and the axis in each body's own frame, so the joint can be made again between bodies that have moved
- `limits?: [number, number]`

### ConstraintData

*interface* · `packages/physics/src/island-step.ts:19`

```ts
interface ConstraintData
```

- `id: number`
- `type: Constraint['type']`
- `a: number`
- `b: number`
- `length: number`
- `stiffness: number`
- `damping: number`
- `maxForce: number`

### ConstraintDef

*interface* · `packages/physics/src/kernel.ts:146`

```ts
interface ConstraintDef
```

- `type: ConstraintType`
- `a: Body`
- `b: Body`
- `length?: number` — the distance (rod), the longest distance (rope) or the rest length (spring); the present distance when missing
- `stiffness?: number` — N/m (spring)
- `damping?: number` — N·s/m (spring)
- `maxForce?: number` — the constraint breaks when the force on it (N) passes this; never when missing
- `anchor?: Vec3` — ball, hinge, fixed: the shared point in world space (the middle between the bodies when missing)
- `axis?: Vec3` — hinge: the axis in world space (up when missing)
- `limits?: [number, number]` — hinge: the angle from the pose it was made in, radians, from the lower to the upper limit; free when missing
- `userData?: unknown`

### ConstraintFrames

*interface* · `packages/physics/src/kernel.ts:188`

```ts
interface ConstraintFrames
```

a joint's anchor, axis and a perpendicular in the frame of body a and of body b

- `pa: Vec3`
- `ua: Vec3`
- `va: Vec3`
- `pb: Vec3`
- `ub: Vec3`
- `vb: Vec3`

### Contact

*interface* · `packages/physics/src/kernel.ts:70`

```ts
interface Contact
```

One contact between two bodies during a step. `normal` points from b toward a.

- `a: Body`
- `b: Body`
- `point: Vec3`
- `normal: Vec3`
- `depth: number`
- `friction: number` — Mutable before the solve: a hook may change what this contact uses.
- `kineticFriction: number`
- `rollingFriction: number`
- `pivotFriction: number`
- `restitution: number`
- `restitutionThreshold: number` — Speed below which the bounce is a rest.
- `readonly closing: number` — Closing speed along the normal when the contact is made (m/s, positive = approaching); read-only for hooks.
- `anisotropy?: { axis: Vec3; across: number }` — Friction that differs along a direction (skates, a rail): the coefficient across `axis` is `across` times the one along it.
- `sticky?: boolean` — A capability's request that the two bodies leave this contact as one (a perfectly inelastic hit).

### ContactEvent

*interface* · `packages/physics/src/kernel.ts:93`

```ts
interface ContactEvent
```

What happened at one contact over a step, delivered after it.

- `a: Body`
- `b: Body`
- `point: Vec3`
- `normal: Vec3`
- `impulse: number` — Total normal impulse over the step (N·s).
- `speed: number` — Largest closing speed along the normal during the step (m/s).
- `slide: number` — Sliding speed along the surface at the largest impact (m/s).
- `restitution: number` — The restitution the contact was solved with, and whether a capability asked the bodies to stick.
- `sticky: boolean`
- `restitutionThreshold?: number` — the closing speed below which the bounce was a rest at the largest impact (a hook may have changed it)

### DegradeRule

*interface* · `packages/physics/src/budget.ts:33`

```ts
interface DegradeRule
```

One step down: values to set at world scope (`capability`.`key` = `value`; a number may be a share of the tier's own: `of`) and capabilities to switch off.

- `name: string`
- `set?: { capability: string; key: string; value: number }[]`
- `disable?: string[]`

### EventData

*interface* · `packages/physics/src/island-step.ts:20`

```ts
interface EventData
```

- `a: number`
- `b: number`
- `point: Vec3`
- `normal: Vec3`
- `impulse: number`
- `speed: number`
- `slide: number`
- `restitution: number`
- `sticky: boolean`
- `restitutionThreshold?: number`

### FieldForce

*interface* · `packages/physics/src/kernel.ts:114`

```ts
interface FieldForce
```

What a force field may return: a force, a torque, or both.

- `force?: Vec3`
- `torque?: Vec3`

### GovernorOptions

*interface* · `packages/physics/src/budget.ts:41`

```ts
interface GovernorOptions
```

- `tier?: Tier`
- `stepMs?: number` — override the tier's step budget, ms
- `rules?: DegradeRule[]`
- `window?: number` — steps averaged before a decision (default 30)
- `down?: number` — windows over budget in a row before stepping down (default 2) and windows well under it before stepping back up (default 4)
- `up?: number`

### GravityFieldParams

*interface* · `packages/physics/src/field-kernels.ts:71`

```ts
interface GravityFieldParams
```

- `scoped: ScopedSnapshot`
- `zones?: ZonesData`
- `attractors: AttractorData[]`

### GridCell

*interface* · `packages/physics/src/walkers.ts:167`

```ts
interface GridCell
```

a ground made of cells in the support's own frame, each with the tops read off a model (`readGrid` of

- `ground: number[]`
- `solid: number[]`

### HavokConDesc

*interface* · `packages/physics/src/havok-islands.ts:27`

```ts
interface HavokConDesc
```

- `id: number`
- `type: Constraint['type']`
- `a: number`
- `b: number`
- `length: number`
- `stiffness: number`
- `damping: number`
- `maxForce: number`
- `frames?: ConstraintFrames`
- `limits?: [number, number]`
- `anchor?: Vec3`
- `axis?: Vec3`

### HavokDesc

*interface* · `packages/physics/src/havok-islands.ts:20`

```ts
interface HavokDesc
```

what a body is, apart from where it is and how it moves

- `id: number`
- `kind: Body['kind']`
- `shape: Body['shape']`
- `mass: number`
- `material?: string`
- `linearDamping: number`
- `angularDamping: number`
- `gravityScale: number`
- `lock: boolean`
- `noCollide: boolean`
- `entityId?: string`
- `exempt?: string[]`
- `custom?: { com: Vec3; inertia: Vec3 }` — the mass properties were set from outside

### HavokKernelOptions

*interface* · `packages/physics/src/havok-kernel.ts:14`

```ts
interface HavokKernelOptions
```

- `wasmUrl?: string` — where a worker finds Havok's WASM when the step goes to workers (a game's page sets it: `havokKernel` does)
- `materials?: MaterialLibrary`
- `gravity?: Vec3`
- `substeps?: number` — Havok steps per world step; force fields are evaluated before each (1 = once a step)

### HavokOut

*interface* · `packages/physics/src/havok-islands.ts:42`

```ts
interface HavokOut
```

- `need?: number[]` — the ids the worker has no description of (it lost its world): nothing was stepped, ask again with them
- `bodies: Float64Array`
- `events: EventData[]`
- `constraints: { id: number; force: number; stretch: number; broken: boolean }[]`

### HavokStatic

*interface* · `packages/physics/src/havok-islands.ts:26`

```ts
interface HavokStatic extends HavokDesc
```

- `position: Vec3`
- `orientation: Quat`

### HavokStepIn

*interface* · `packages/physics/src/havok-islands.ts:33`

```ts
interface HavokStepIn
```

- `dt: number`
- `gravity: Vec3`
- `substeps: number`
- `state: Float64Array` — the bodies of the piece (the kinematic ones of the world too), by id, HAVOK_IN_STRIDE numbers each
- `descs: HavokDesc[]` — the descriptions of the bodies the worker may not have (or that changed)
- `constraints: HavokConDesc[]`
- `fields: { name: string; params: unknown }[]`

### HavokWorldIn

*interface* · `packages/physics/src/havok-islands.ts:32`

```ts
interface HavokWorldIn
```

what a worker's world is made of: the fixed bodies, the materials, where Havok's WASM is

- `wasmUrl?: string`
- `materials: ReturnType<MaterialLibrary['snapshot']>`
- `statics: HavokStatic[]`
- `substeps: number`

### Island

*interface* · `packages/physics/src/island-step.ts:53`

```ts
interface Island
```

- `bodies: Body[]`
- `constraints: Constraint[]`
- `awake: boolean`

### IslandIn

*interface* · `packages/physics/src/island-step.ts:21`

```ts
interface IslandIn
```

- `dt: number`
- `n: number`
- `iterations: number`
- `restitutionThreshold: number`
- `gravity: Vec3`
- `materials: unknown`
- `kin: BodyData[]` — the fixed bodies and what the dynamic ones are stay in the worker's state; these are the kinematic bodies and this piece's dynamic ones' state
- `state: Float64Array`
- `constraints: ConstraintData[]`
- `fields: { name: string; params: unknown }[]`
- `hooks: { name: string; params: unknown }[]`

### IslandMemo

*interface* · `packages/physics/src/island-step.ts:86`

```ts
interface IslandMemo
```

what the last grouping left, so the next one starts from an almost sorted order (the bodies move a little between steps)

- `order: Body[]`

### IslandOut

*interface* · `packages/physics/src/island-step.ts:31`

```ts
interface IslandOut
```

- `bodies: Float64Array`
- `timers: [number, number][]`
- `events: EventData[]`
- `constraints: { id: number; force: number; stretch: number; broken: boolean }[]`

### Issue

*interface* · `packages/physics/src/materials.ts:31`

```ts
interface Issue
```

- `path: string`
- `message: string`

### KernelCaps

*interface* · `packages/physics/src/kernel.ts:116`

```ts
interface KernelCaps
```

- `friction: boolean` — Static and kinetic friction, restitution with a threshold and combine rules from materials.
- `restitutionCombine: boolean`
- `rollingFriction: boolean`
- `contactImpulses: boolean`
- `constraints: boolean`
- `breakableConstraints: boolean`
- `ccd: 'none' | 'substep' | 'native'` — 'substep' = small steps scaled by speed; 'native' = swept collision.
- `shapes: string[]`
- `contactHooks?: boolean` — `beforeSolve` can change a contact before it is solved; false: hooks see nothing and per-pair changes go through materials
- `rigidBodies?: boolean` — bodies of any shape move, rotate with a full inertia tensor and stack
- `joints?: boolean` — ball, hinge and fixed constraints

### KernelRayHit

*interface* · `packages/physics/src/kernel.ts:111`

```ts
interface KernelRayHit
```

- `body: Body`
- `point: Vec3`
- `normal: Vec3`
- `distance: number`

### LevelConstraint

*interface* · `packages/physics/src/host.ts:171`

```ts
interface LevelConstraint
```

- `id?: string`
- `type: 'rod' | 'rope' | 'spring' | 'ball' | 'hinge' | 'fixed'`
- `a: string`
- `b: string`
- `length?: number`
- `stiffness?: number`
- `damping?: number`
- `maxForce?: number`
- `anchor?: Vec3`
- `axis?: Vec3`
- `limits?: [number, number]`

### LevelFracture

*interface* · `packages/physics/src/host.ts:172`

```ts
interface LevelFracture
```

- `node: string`
- `pieces: string[]`
- `material?: string`
- `toughness?: number`

### LightKernelOptions

*interface* · `packages/physics/src/light-kernel.ts:8`

```ts
interface LightKernelOptions
```

- `materials?: MaterialLibrary`
- `gravity?: Vec3`
- `substeps?: number` — Smallest number of sub-steps per step; fast bodies get more (up to maxSubsteps) so they do not tunnel.
- `maxSubsteps?: number`
- `iterations?: number`
- `restitutionThreshold?: number` — Closing speed below which a bounce is a rest (m/s).

### MediumSample

*interface* · `packages/physics/src/host.ts:153`

```ts
interface MediumSample
```

- `name: string`
- `density: number`
- `viscosity: number`
- `flow: Vec3`

### PendulumDef

*interface* · `packages/physics/src/pendulum.ts:11`

```ts
interface PendulumDef
```

A rigid body hanging from a ball joint, swinging and twisting freely (a lamp on a chain, a sign on a hook, a punching bag): Unreal's PhysicsConstraint with all three
angular motions free and the linear ones locked, the other end fixed to the world. The light kernel's bodies are points without orientation, so this is its own small
integrator of the rigid body about the pivot: angular momentum L = I_p w with I_p = R I_c R^T + m(|r|^2 E - r r^T) (the parallel-axis theorem about the pivot, r = pivot to
centre of mass), gravity and wind as torques about the pivot, the gyroscopic term, the damping of the body (linear damping acts on the centre of mass, whose speed is w x r, so
both dampings slow the rotation) and impulses at a point (the player bumping it). Plain numbers, deterministic, a few dozen flops per sub-step. SI units (metres, kg, s).

- `pivot: Vec3` — world position of the joint
- `com: Vec3` — world position of the centre of mass at rest (below the pivot for a hanging body)
- `mass: number`
- `inertia: number[]` — the inertia tensor about the centre of mass in the world frame of the rest pose, row-major 3x3 (see boxInertia)
- `linearDamping?: number` — 1/s, default 0.03 (Unreal's default for a body)
- `angularDamping?: number` — 1/s, default 1 (the lamps' value)
- `gravity?: number` — m/s^2, default 9.81

### PhysicsConfig

*interface* · `packages/physics/src/host.ts:159`

```ts
interface PhysicsConfig
```

What a `physics` block of a level or a game may hold.

- `capabilities?: string[]`
- `materials?: Record<string, PhysicsMaterial>`
- `pairs?: Array<{ a: string; b: string; values: PhysicsMaterial }>`
- `combine?: Record<string, CombineRule>`
- `gravity?: { vector?: Vec3 }`
- `constraints?: LevelConstraint[]` — links between two bodies of the level, by the names of their nodes (a Physics Constraint of Unreal where the kernel has an equivalent)
- `fractured?: LevelFracture[]` — bodies authored in pieces: when the intact one breaks, its pieces (nodes of the level) take over
- `[capability: string]: unknown`

### PhysicsFields

*interface* · `packages/physics/src/host.ts:144`

```ts
interface PhysicsFields
```

Read access to what capabilities provide: gravity at a point (m/s², a vector) and, later, the medium.

- `gravity?: (p: Vec3, ctx?: ScopeContext) => Vec3`
- `gravityData?: () => GravityFieldParams` — gravity as the plain parameters of its field kernel (the fields that need the weight in a worker read it)
- `medium?: (p: Vec3, ctx?: ScopeContext) => MediumSample` — The medium at a point (air by default): density kg/m³, dynamic viscosity Pa·s, the flow velocity m/s (wind, current).
- `column?: (p: Vec3, height: number, ctx?: ScopeContext) => { fraction: number; medium: MediumSample | null }` — The part of a vertical segment of `height` standing at `p` that is inside a dense medium (water, mud), and that medium.

### PhysicsHostOptions

*interface* · `packages/physics/src/host.ts:156`

```ts
interface PhysicsHostOptions
```

- `kernel?: PhysicsKernel`
- `materials?: MaterialLibrary`
- `capabilities?: Capability[]`

### PhysicsKernel

*interface* · `packages/physics/src/kernel.ts:190`

```ts
interface PhysicsKernel
```

- `readonly name: string`
- `readonly caps: KernelCaps`
- `gravity: Vec3`
- `readonly bodies: readonly Body[]`
- `readonly constraints: readonly Constraint[]`
- `readonly closures?: { fields: number; hooks: number; names: string[] }` — the fields and hooks that are closures: while there are any, the step cannot leave the game's thread
- `step(dt: number): void`
- `addBody(def: BodyDef): Body`
- `removeBody(b: Body): void`
- `addConstraint(def: ConstraintDef): Constraint`
- `removeConstraint(c: Constraint): void`
- `onConstraintBreak(cb: (c: Constraint) => void): () => void` — Called after the step for each constraint whose force passed its limit; the constraint is already removed.
- `applyForce(b: Body, f: Vec3, at?: Vec3): void`
- `applyImpulse(b: Body, j: Vec3, at?: Vec3): void`
- `applyTorque(b: Body, t: Vec3): void`
- `setVelocity(b: Body, v: Vec3): void`
- `setPosition(b: Body, p: Vec3): void`
- `sleep(b: Body): void`
- `wake(b: Body): void`
- `addForceField(fn: (b: Body, h: number) => Vec3 | FieldForce | null, label?: string): () => void` — A force that depends on where a body is (gravity, drag, buoyancy): evaluated at the position of every sub-step, so a fast or orbiting body gets the force it feels where it is, not where it was at the start of the step. Returns newtons, or null for none.
- `addDataField(name: string, params: () => unknown, o?: { local?: () => boolean }): () => void` — The same as a field, by name and plain parameters (field-kernels.ts): `params` is asked once at the start of each step. It can run in a worker where a closure cannot; `local` says, cheaply, when the parameters stand on code and the step must stay in this thread.
- `addDataHook(name: string, params: () => unknown, o?: { local?: () => boolean }): () => void` — The same as `beforeSolve`, by name and plain parameters (a kernel without contact hooks takes none).
- `beforeSolve(cb: (c: Contact) => void, label?: string): () => void` — Called for every contact before it is solved, so a capability can change friction or restitution.
- `onContact(cb: (e: ContactEvent) => void): () => void` — Called after the step with what each contact did.
- `rayCast(origin: Vec3, dir: Vec3, maxDistance: number): KernelRayHit | null`
- `setMassProperties?(b: Body, mass: number, centreOfMass: Vec3, inertia: Vec3): void` — Mass, centre of mass (body space) and principal inertia set from outside (a vessel whose tanks fill); where the kernel can.
- `setSurface?(b: Body, s: { friction: number; kineticFriction: number; restitution: number }): void` — A body's own friction and restitution, over its material's: how a kernel without contact hooks takes a capability's dials.

### PhysicsMaterial

*interface* · `packages/physics/src/materials.ts:6`

```ts
interface PhysicsMaterial
```

Physical materials as data. A value that is not given means "this capability does not apply to it", not a default: a body with
no strength cannot break. The few values a contact cannot do without (friction, restitution) have library defaults, stated here.

- `density?: number`
- `friction?: number`
- `kineticFriction?: number`
- `rollingFriction?: number`
- `pivotFriction?: number`
- `restitution?: number`
- `youngModulus?: number`
- `yieldStrength?: number`
- `tensileStrength?: number`
- `toughness?: number`
- `[property: string]: number | undefined`

### PhysicsOptions

*interface* · `packages/physics/src/physics.ts:53`

```ts
interface PhysicsOptions
```

- `layers?: string[]`

### Piece

*interface* · `packages/physics/src/shapes.ts:122`

```ts
interface Piece
```

- `shape: Shape`
- `position: Vec3`
- `volume: number`

### RayHit

*interface* · `packages/physics/src/physics.ts:26`

```ts
interface RayHit
```

- `point: BABYLON.Vector3`
- `normal: BABYLON.Vector3`
- `distance: number`
- `mesh: BABYLON.AbstractMesh`
- `entity?: Entity`

### RigidBodyParams

*interface* · `packages/physics/src/host.ts:96`

```ts
interface RigidBodyParams
```

- `shape?: 'sphere' | 'box' | 'plane' | 'capsule' | 'cylinder'`
- `radius?: number`
- `height?: number` — capsule and cylinder: the length along y (a capsule's between the centres of its caps)
- `geometry?: Shape` — any shape the kernel has (a hull, a compound, a mesh): wins over `shape`
- `size?: [number, number, number]` — box: full size, like Collider
- `normal?: Vec3`
- `offset?: number`
- `mass?: number` — kg; taken from the material density and the shape when missing
- `material?: string`
- `kind?: BodyKind`
- `linearDamping?: number`
- `angularDamping?: number`
- `gravityScale?: number`
- `velocity?: Vec3`
- `angularVelocity?: Vec3`
- `lockRotation?: boolean`
- `rotate?: boolean` — Turn the node with the body (a rolling ball); off for a body whose node is a model that should stay upright.

### ScopeContext

*interface* · `packages/physics/src/host.ts:44`

```ts
interface ScopeContext
```

Where a value is asked from: an entity, or just a place (a zone covers it).

- `entity?: Entity | string`
- `position?: Vec3`

### ScopedSnapshot

*interface* · `packages/physics/src/field-kernels.ts:55`

```ts
interface ScopedSnapshot
```

a ScopedConfig's values for some keys, plain: what `ScopedConfig.snapshot` gives

- `defaults: Record<string, unknown>`
- `world: Record<string, unknown>`
- `level: Record<string, unknown>`
- `zone: Record<string, Record<string, unknown>>`
- `entity: Record<string, Record<string, unknown>>`

### ShapeSamples

*interface* · `packages/physics/src/shapes.ts:68`

```ts
interface ShapeSamples
```

- `points: Vec3[]` — cell centres inside the shape, body space
- `cell: Vec3` — the cell's edges along x, y, z, m
- `volume: number` — the volume each point stands for, m³ (the shape's volume over the count, so the sum is exact where the volume is known)

### Snapshot

*interface* · `packages/physics/src/collision-snapshot.ts:7`

```ts
interface Snapshot
```

- `version: number` — a number that is new with every copy: the workers keep their world under it
- `meshes: BABYLON.AbstractMesh[]` — the meshes in the order of the copy: a ray's `mesh` is an index into this
- `index: Map<BABYLON.AbstractMesh, number>`
- `data: CollisionMeshData[]`

### StepResult

*interface* · `packages/physics/src/walkers.ts:57`

```ts
interface StepResult
```

- `landed: number` — he landed this step, at this speed (m/s); 0 otherwise
- `splash: number` — he went into the water this step, falling at this speed (m/s); 0 otherwise
- `blocked: boolean` — a wall stopped his move

### Support

*interface* · `packages/physics/src/walkers.ts:17`

```ts
interface Support
```

- `name: string`
- `clears?: boolean` — a bridge: where it gives ground, walls of other supports do not stop a man (a gangway through a rail, a ramp over a fender)
- `query(x: number, z: number, feet: number, maxStep: number, reach: number, out: SupportHit): void` — the ground a body can step onto from `feet` (the highest walkable top <= feet + maxStep) and whether something solid blocks him (a top between feet + maxStep and feet + reach)
- `frame?: { toLocal(p: Vec3): Vec3; toWorld(p: Vec3): Vec3 }` — a moving support: world <-> its own frame, so a man on it is carried

### SupportHit

*interface* · `packages/physics/src/walkers.ts:15`

```ts
interface SupportHit
```

- `ground: number | null`
- `wall: boolean`

### TierBudget

*interface* · `packages/physics/src/budget.ts:13`

```ts
interface TierBudget
```

- `stepMs: number` — the share of a frame the whole physics step may take, milliseconds
- `maxPieces: number` — pieces alive at once (the strength capability's `maxPieces`)
- `fluidParticles: number` — particles of all liquids, and of all cloths: for the game to give the capabilities that take such a budget
- `clothParticles: number`
- `flowSources: number` — flow sources the level's field takes (`FlowField.maxSources`) and the cells of flow boxes solved per physics step, all boxes together
- `flowBoxCells: number`

### TriggerEvent

*interface* · `packages/physics/src/physics.ts:25`

```ts
interface TriggerEvent
```

- `trigger: Entity`
- `other: Entity`

### Walker

*interface* · `packages/physics/src/walkers.ts:27`

```ts
interface Walker
```

- `x: number`
- `y: number`
- `z: number`
- `vx: number` — velocity of a body in the air, m/s
- `vy: number`
- `vz: number`
- `support: Support | null` — what he stands on (null in the air) and where on it, in its own frame (when it moves)
- `local: Vec3 | null`
- `air: boolean` — feet off the ground
- `depth: number` — water over his feet, m (0 on dry land): the game decides what a deep one means
- `swim: boolean` — afloat: in water too deep to stand in, he floats with his head out and swims by the move asked of him

### WalkersOptions

*interface* · `packages/physics/src/walkers.ts:42`

```ts
interface WalkersOptions
```

- `gravity?: number`
- `maxStep?: number` — the highest step a man climbs, m (default 0.45)
- `maxDrop?: number` — the drop he walks down without falling, m (default 0.6)
- `reach?: number` — how high above his feet a wall must reach to stop him, m (default 2.2)
- `water?: (x: number, z: number) => number | null` — the water surface at (x, z), m, or null for none (land)
- `sink?: number` — the speed a man sinks at in water, m/s (default 1.2)
- `swimDepth?: number` — water deeper than this over his feet and he cannot stand: he floats (default 1.3 m, the chin)

### WorldIn

*interface* · `packages/physics/src/island-step.ts:28`

```ts
interface WorldIn
```

the resident state of a worker: the fixed bodies and the descriptions of the dynamic ones

- `statics: BodyData[]`
- `dyn: BodyDesc[]`

### ZonesData

*interface* · `packages/physics/src/field-kernels.ts:28`

```ts
interface ZonesData
```

- `zones: { name: string; shape: ZoneShapeData; priority?: number }[]`
- `grid?: { cell: number; prefix?: string; origin?: [number, number] }`

## Types

### BodyDesc

*type* · `packages/physics/src/island-step.ts:16`

```ts
type BodyDesc = Omit<BodyData, 'position' | 'orientation' | 'velocity' | 'angularVelocity' | 'sleeping'>
```

what a body is, apart from where it is and how it moves: it stays in the workers while it does not change

### BodyKind

*type* · `packages/physics/src/kernel.ts:19`

```ts
type BodyKind = 'static' | 'dynamic' | 'kinematic'
```

### CombineRule

*type* · `packages/physics/src/materials.ts:20`

```ts
type CombineRule = 'mean' | 'geometric' | 'min' | 'max' | 'multiply'
```

### ConstraintType

*type* · `packages/physics/src/kernel.ts:145`

```ts
type ConstraintType = 'rod' | 'rope' | 'spring' | 'ball' | 'hinge' | 'fixed'
```

A link between two bodies' centres.
 - rod:    a rigid distance (pushes and pulls)
 - rope:   a maximum distance (pulls only; slack when closer)
 - spring: Hooke's law with damping (implicit, so stable at any stiffness)
 - ball:   the two bodies share a point and turn freely about it (a shoulder, a hook)
 - hinge:  they share a point and turn about one axis only, within optional limits (a door, a wheel)
 - fixed:  they are welded in the pose they have (a bracket that can break)
The last three need a kernel with `caps.joints` (rigid bodies).

### FieldFn

*type* · `packages/physics/src/field-kernels.ts:8`

```ts
type FieldFn = (b: Body, h: number) => Vec3 | FieldForce | null
```

### HookFn

*type* · `packages/physics/src/field-kernels.ts:9`

```ts
type HookFn = (c: Contact) => void
```

### Phase

*type* · `packages/physics/src/host.ts:16`

```ts
type Phase = 'field' | 'strength' | 'stretch'
```

The fixed order of the step: fields add forces, the kernel integrates and resolves contacts, strength reads them, stretch integrates soft things.

### Quat

*type* · `packages/physics/src/vec.ts:5`

```ts
type Quat = [number, number, number, number]
```

### Scope

*type* · `packages/physics/src/host.ts:45`

```ts
type Scope = 'world' | 'level' | 'zone' | 'entity'
```

### Shape

*type* · `packages/physics/src/kernel.ts:8`

```ts
type Shape = | { type: 'sphere'; radius: number } | { type: 'box'; half: Vec3 } // static or kinematic only in the light kernel | { type: 'plane'; normal: Vec3; offset: number } // static only: dot(normal, p) = offset // the shapes below need a rigid-body kernel (Havok); the light kernel refuses them | { type: 'capsule'; radius: number; halfHeight: number } // along the body's y, halfHeight to the centre of each cap | { type: 'cylinder'; radius: number; halfHeight: number } // along the body's y | { type: 'convex'; points: Vec3[] } // the hull of the points, in body space | { type: 'mesh'; positions: number[]; indices: number[] } // triangles in body space; static or kinematic only | { type: 'compound'; children: { shape: Shape; position?: Vec3; orientation?: Quat }[] }
```

The part of the dynamics every capability is written against. Havok, the light kernel of this package, or a game's own backend
implements it; a capability asks `caps` what is native and does the rest in a force or contact hook.

### ShapeKind

*type* · `packages/physics/src/physics.ts:6`

```ts
type ShapeKind = 'box' | 'sphere' | 'capsule'
```

### Tier

*type* · `packages/physics/src/budget.ts:12`

```ts
type Tier = 'desktop' | 'mobile' | 'console' | 'low'
```

What a hardware tier can afford, and what to give up when the world step runs over its share of the frame.
The numbers in `TIERS` come from `tools/bench` (2026-11-02), run on the dev machine in Node, Chromium and WebKit: a full step share of 6 ms holds
about 200 resting pieces, or about 170 to 290 liquid particles, or about 230 cloth particles when each takes 40 / 30 / 30 % of it. The console,
mobile and low tiers are scaled down from the same table; they are not measured on those machines: run `tools/bench` there and replace them.
`flowBoxCells` comes from the flow box's measured 0.9 microseconds per cell per step (A13) at 30 % of the step share: 1.8 ms / 0.9 us = 2000 cells
stepped every physics step on the desktop (a box stepped every n-th step may have n times as many).

### Vec3

*type* · `packages/physics/src/vec.ts:4`

```ts
type Vec3 = [number, number, number]
```

Plain-number vectors for the physics code: no allocation-heavy classes, no engine dependency, and the same arithmetic everywhere
so a replay gives the same bits. A vector is [x, y, z]; a quaternion is [x, y, z, w].

### ZoneShapeData

*type* · `packages/physics/src/field-kernels.ts:24`

```ts
type ZoneShapeData = | { kind: 'box'; centre: [number, number, number]; size: [number, number, number]; yaw?: number } | { kind: 'cylinder'; centre: [number, number, number]; radius: number; height: number } | { kind: 'polygon'; points: [number, number][]; minY?: number; maxY?: number }
```

a zone as the zone service holds it (the shapes of

## Constants

### collisionKernel

*const* · `packages/physics/src/collision-world.ts:51`

```ts
const collisionKernel: { world: (p: { meshes: CollisionMeshData[]; }, st: Record<string, unknown>) => number; info: (_p: unknown, st: Record<string, unknown>) => { n: string; v: number; i: number; min: [number, number, number]; max: [number, number, number]; sub: number; chk: boolean; mat: boolean; }[]; move: (p: CollisionMoveIn, st: Record<string, unknown>) => CollisionMoveOut; ray: (p: CollisionRayIn, st: Record<strin …
```

### collisionState

*const* · `packages/physics/src/collision-world.ts:50`

```ts
const collisionState: (st: Record<string, unknown>) => CollisionState
```

the collision world as kernels on a resident state

### DEFAULT_COMBINE

*const* · `packages/physics/src/materials.ts:23`

```ts
const DEFAULT_COMBINE: CombineRules
```

### DEFAULT_CONTACT

*const* · `packages/physics/src/materials.ts:24`

```ts
const DEFAULT_CONTACT: { friction: number; restitution: number; rollingFriction: number; pivotFriction: number; }
```

### DEFAULT_LAYERS

*const* · `packages/physics/src/layers.ts:36`

```ts
const DEFAULT_LAYERS: string[]
```

The layers a game gets unless it defines its own (the common UE object channels).

### EXAMPLE_MATERIALS

*const* · `packages/physics/src/materials.ts:114`

```ts
const EXAMPLE_MATERIALS: Record<string, PhysicsMaterial>
```

A few common materials, as examples and for tests. A game defines its own.

### HAVOK_IN_STRIDE

*const* · `packages/physics/src/havok-islands.ts:17`

```ts
const HAVOK_IN_STRIDE: 22
```

the state of a body going in: IN_STRIDE numbers (id, position, orientation, velocity, angular velocity, sleeping, 0, force 3, torque 3)

### HAVOK_STRIDE

*const* · `packages/physics/src/havok-islands.ts:15`

```ts
const HAVOK_STRIDE: 15
```

a body's numbers after the step, 15 to a body: id, position 3, orientation 4, velocity 3, angular velocity 3, sleeping

### IN_STRIDE

*const* · `packages/physics/src/island-step.ts:18`

```ts
const IN_STRIDE: 22
```

a dynamic body's state in a piece, 22 numbers: id, position 3, orientation 4, velocity 3, angular velocity 3, sleeping, sleep timer, the force 3 and the torque 3 applied since the last step

### STRIDE

*const* · `packages/physics/src/island-step.ts:30`

```ts
const STRIDE: 15
```

a body's numbers after the step, 15 to a body: id, position 3, orientation 4, velocity 3, angular velocity 3, sleeping

### TIERS

*const* · `packages/physics/src/budget.ts:25`

```ts
const TIERS: Record<Tier, TierBudget>
```

