Taos API Reference
    Preparing search index...

    Class PhysicsWorld

    Index

    Properties

    jolt: typeof Jolt

    The runtime Jolt module — use for new this.jolt.Vec3(...) etc.

    joltInterface: JoltInterface
    system: PhysicsSystem
    bodyInterface: BodyInterface
    tempAllocator: TempAllocator

    Temp allocator, needed by CharacterVirtual updates.

    Accessors

    • get debugShapes(): readonly DebugShape[]

      Live list of tracked bodies with their primitive collision shapes (in body-local space). A debug renderer reads body.GetPosition() / GetRotation() to place each part in the world. Bodies whose shape is a triangle mesh / height-field / convex hull appear with empty parts.

      Returns readonly DebugShape[]

    Methods

    • Packs a (group, mask) pair into a Jolt object layer.

      Parameters

      • group: number
      • mask: number

      Returns number

    • Builds a mask-aware object-layer filter for collision queries (raycasts, character sweeps): it accepts a body when its layer collides with objectLayer per the world's pair filter. The caller owns the returned filter and must jolt.destroy() it. Unlike SpecifiedObjectLayerFilter (exact-equality), this honors the (group, mask) collision rules.

      Parameters

      • objectLayer: number

      Returns ObjectLayerFilter

    • Builds the matching broad-phase filter for objectLayer. Caller destroys.

      Parameters

      • objectLayer: number

      Returns BroadPhaseLayerFilter

    • Sets world gravity (default is (0, -9.81, 0)).

      Parameters

      • x: number
      • y: number
      • z: number

      Returns void

    • Casts a ray against every collider and returns the closest hit point (world space), or null if nothing was hit. direction is the full ray vector — its length is the maximum cast distance. Useful for grounding a camera/character against the streamed terrain colliders. staticOnly restricts the cast to the World (non-moving) layer so a ray fired from above an actor doesn't hit the actor itself.

      Parameters

      • origin: Vec3
      • direction: Vec3
      • staticOnly: boolean = false

      Returns Vec3 | null

    • Fast straight-down ground raycast that allocates no Jolt objects per call (it reuses cached scratch), so it's safe to call hundreds of times per frame — e.g. baking a collision heightmap by sampling the streamed colliders. Casts from (x, y, z) down dist meters and returns the world Y of the closest hit, or null. staticOnly restricts to the World layer (ignores dynamic actors, so a ray over the player doesn't hit the player).

      Parameters

      • x: number
      • y: number
      • z: number
      • dist: number
      • staticOnly: boolean = false

      Returns number | null

    • Adds a capsule body — the standard actor/projectile shape. halfHeight is the half-length of the cylindrical section (excluding the hemispherical caps), so total height is 2 * (halfHeight + radius). The capsule's axis is the local Y (up) axis.

      Parameters

      Returns Body

    • Adds a cylinder body. halfHeight is the half-length along the local Y (up) axis, so total height is 2 * halfHeight; radius is the cross-section radius. Used by the level collision (Godot CylinderShape3D).

      Parameters

      Returns Body

    • Adds a static triangle-mesh collider from raw geometry — arbitrary, possibly concave "soup" (ramps, level geometry, the surface of a wavy terrain). positions is packed xyz triplets; indices is a triangle list.

      Triangle meshes have no defined inertia, so Jolt only allows them on static (or kinematic) bodies — this is the standard rule in every physics engine. opts tunes the static body's surface and collision layer/mask.

      Parameters

      Returns Body

    • Static collider for INSTANCED geometry: one initJolt.MeshShape per unique mesh, referenced at every instance transform through a StaticCompoundShape. Jolt builds + caches each unique mesh shape ONCE, so peak memory scales with the unique meshes — not the merged instance soup that a single huge addMeshCollider would build (which OOMs the WASM heap on a heavily-instanced level). instances[i].mesh indexes unique; instances[i].matrix is a column-major 4×4 (translation · rotation · scale).

      Parameters

      Returns Body

    • Adds a static compound collider from a list of primitive sub-shapes (box / cylinder / sphere / capsule), each with its own local position + rotation. Builds a single Jolt StaticCompoundShape so a whole authored level collision set (hundreds of shapes) is one body / one broadphase entry — far cheaper than one body per shape, and exact (unlike a trimesh of the visible geometry). Sub-shape axes follow the engine convention (box half-extents per axis; cylinder/capsule axis = local Y). Always static. This is what the StaticBody component builds from its child Colliders (Godot StaticBody3D + CollisionShape3D children).

      Parameters

      Returns Body

    • Adds a static height-field collider — the fast, memory-light path for terrain. heights is a sampleCount × sampleCount row-major grid of world Y values (index = z·sampleCount + x); cellSize is the world spacing between samples; the field is placed so its origin sample sits at originXz.

      Parameters

      Returns Body

    • Adds a dynamic body whose shape is the convex hull of points — the way to give a falling object a custom (convex) mesh shape. For concave objects, decompose into several hulls and combine with a compound shape.

      Parameters

      Returns Body

    • Creates and adds a constraint between two bodies (e.g. a PointConstraintSettings). The settings object is consumed and destroyed.

      Parameters

      • settings: TwoBodyConstraintSettings
      • body1: Body
      • body2: Body

      Returns Constraint

    • Advances the simulation. Sub-steps long frames to keep each step stable.

      Parameters

      • deltaTime: number

      Returns void

    • Removes and destroys a single body. Its shape frees once no body holds it.

      Parameters

      • body: Body

      Returns void

    • Install a global begin-overlap callback invoked for every contact pair with both bodies' stable ids (bodyKey). The caller resolves ids to owners. Pass null to clear. Installs the contact listener on first use.

      Parameters

      • cb: ((keyA: number, keyB: number) => void) | null

      Returns void

    • The stable id key for a body, matching the keys passed to the contact callback.

      Parameters

      • body: Body

      Returns number