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.

    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 honours 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 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

    • 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