World
World is the top-level handle. It owns the Jolt interface, the body set, the shape store, and every native object created through it. Disposing the world releases all of them.
Creating
Section titled “Creating”World.create(options?)
Section titled “World.create(options?)”static create(options?: WorldCreateOptions): Promise<World>Asynchronously builds a world. Loads the default wasm-compat runtime unless you pass runtime, raw, or build.
Key WorldCreateOptions:
| Option | Type | Notes |
|---|---|---|
gravity | Vector3Input | Default [0, -9.81, 0] is not applied automatically — pass it explicitly. |
layers | LayerConfig | Collision layer table. Defaults to static + moving. See Collision layers. |
deterministic | boolean | "cross-platform" | Enable deterministic stepping. "cross-platform" requires a build compiled for it (jolt-ts’ builds are). |
maxBodies | number | Body capacity hint. |
maxBodyPairs, maxContactConstraints | number | Broad/narrow-phase capacity hints. |
runtime | JoltRuntime | Reuse a runtime from loadJolt() across worlds. |
build | JoltBuild | Pick a WASM variant. See Loading. |
Simulation
Section titled “Simulation”step(deltaTime, collisionSteps?)
Section titled “step(deltaTime, collisionSteps?)”Advance the simulation. Use a fixed deltaTime (e.g. 1 / 60). collisionSteps (default 1) subdivides collision detection for fast bodies.
setGravity(gravity) · gravity() · gravityInto(out)
Section titled “setGravity(gravity) · gravity() · gravityInto(out)”Get or set world gravity. gravityInto writes into a caller-owned [x, y, z] or { x, y, z }.
deterministicSimulation() · setDeterministicSimulation(enabled)
Section titled “deterministicSimulation() · setDeterministicSimulation(enabled)”Read or toggle deterministic stepping at runtime.
Bodies
Section titled “Bodies”createBody(options | BodyDesc)
Section titled “createBody(options | BodyDesc)”Create and add a Body. Accepts a CreateBodyOptions object or a fluent BodyDesc. Returns the wrapper.
removeBody(body)
Section titled “removeBody(body)”Remove and destroy a body, invalidating its wrapper.
getBody(id) · bodyCount
Section titled “getBody(id) · bodyCount”Look a body up by its numeric id, or read how many bodies the world tracks.
Queries
Section titled “Queries”castRay(origin, direction, options?) → RayHit | null
Section titled “castRay(origin, direction, options?) → RayHit | null”Closest-hit raycast. direction carries the ray length. See Queries.
castRayAll(origin, direction, options?) → RayHit[]
Section titled “castRayAll(origin, direction, options?) → RayHit[]”All hits, sorted nearest to farthest.
castShape(shape, position, rotation, direction, options?) → ShapeCastHit | null
Section titled “castShape(shape, position, rotation, direction, options?) → ShapeCastHit | null”Sweep a shape through the world and return the first contact.
QueryOptions: excludeBody, includeSensors, and a filter(hit) predicate.
State & snapshots
Section titled “State & snapshots”saveState(state?, filter?) → Uint8Array
Section titled “saveState(state?, filter?) → Uint8Array”Serialize simulation state (positions, velocities, contacts…) to bytes. Overloads accept a reusable recorder for the hot path. See Determinism & networking.
restoreState(bytes | recorder, filter?) → boolean
Section titled “restoreState(bytes | recorder, filter?) → boolean”Restore state previously saved.
takeSceneSnapshot(options?) → Uint8Array · restoreSceneSnapshot(bytes, options?)
Section titled “takeSceneSnapshot(options?) → Uint8Array · restoreSceneSnapshot(bytes, options?)”Serialize/restore the full world topology (bodies, shapes, config, preserved ids).
createStateRecorder(input?) → NativeByteRecorder
Section titled “createStateRecorder(input?) → NativeByteRecorder”A reusable byte recorder for repeated save/restore without per-call allocation.
Debug & escape hatches
Section titled “Debug & escape hatches”debugRender(options?) → DebugRenderBuffers
Section titled “debugRender(options?) → DebugRenderBuffers”Rapier-style wireframe line buffers (vertices + colors) for every body. See Debug rendering.
Direct access to { module, joltInterface, system, bodyInterface } for calls the wrapper doesn’t cover. See Raw escape hatches.
runtime · shapes
Section titled “runtime · shapes”The backing JoltRuntime and the world’s ShapeStore.
Lifetime
Section titled “Lifetime”dispose() · [Symbol.dispose]()
Section titled “dispose() · [Symbol.dispose]()”Release the world and everything it owns. Also runs automatically at the end of a using block.
using world = await World.create();// …used here, disposed at block exitdisposed
Section titled “disposed”true once disposed. Calling most methods afterward throws.