Skip to main content
The Trace module casts rays and sweeps shapes through the game world using the same collision data the engine uses - static geometry, dynamic entities, and tagged collision layers.
All trace functions are synchronous and return immediately. Create a TraceFilter once and reuse it across frames - this avoids per-call allocation and lets you build up an ignore list over time.

Overview

Filters

Create reusable trace filters from presets or custom configs.

Raycasts

Single and multi-hit rays, box / sphere / capsule sweeps.

Spatial queries

Visibility, solid checks, overlap spheres, closest point.

Results

TraceResult, OverlapResult, ClosestPointResult shapes.

Filters

Every trace function accepts an optional filter that controls what the trace collides with. Filters can be passed in three forms - pick whichever fits your situation:

Trace.filter


Creates a reusable TraceFilter. Pass a preset string for common scenarios, or a configuration object for fine-grained control.
string
default:"bullet"
One of the built-in filter presets (see table below).
Preset strings
Configuration object fields
Disable resolveNormals, resolveMaterials, and resolveEntity if you only care about whether something was hit - the trace runs faster when it doesn’t need to fill in extra data.

TraceFilter methods

Once you have a filter, you can tell it to skip specific entities.
Adds an entity to the filter’s ignore list. Accepts a raw entity index or any object with an .index property (e.g. an Entity).
Clears the ignore list so the filter collides with all entities again.

Raycasts

Trace.ray


Casts a single ray from start to end. The workhorse of the trace API - use this for hit detection, aim checks, and penetration tests.
Vector
required
Ray origin, typically the player’s eye position.
Vector
required
Ray endpoint - the target position.
string | TraceFilter | FilterOptions
Collision filter. Defaults to "bullet" if omitted.

Trace.box


Sweeps an axis-aligned box from start to end. mins and maxs define the box extents relative to the sweep origin.
Vector
required
Sweep origin.
Vector
required
Sweep destination.
Vector
required
Minimum corner of the box (negative offsets).
Vector
required
Maximum corner of the box (positive offsets).
string | TraceFilter | FilterOptions
Collision filter. Defaults to "bullet".

Trace.sphere


Sweeps a sphere from start to end.
Vector
required
Sweep origin.
Vector
required
Sweep destination.
number
required
Sphere radius in game units.
string | TraceFilter | FilterOptions
Collision filter. Defaults to "bullet".

Trace.capsule


Sweeps a capsule (cylinder with hemispherical caps) from start to end. Useful for simulating player-sized collision hulls.
Vector
required
Sweep origin.
Vector
required
Sweep destination.
number
required
Capsule radius.
number
required
Half the height of the cylindrical section.
string | TraceFilter | FilterOptions
Collision filter. Defaults to "bullet".

Trace.rayAll


Casts a ray and returns all hits along the path, not just the first. Useful for penetration simulation - you get every surface the ray passes through.
Vector
required
Ray origin.
Vector
required
Ray endpoint.
string | TraceFilter | FilterOptions
Collision filter. Defaults to "bullet".
number
default:"32"
Maximum number of hits to return. Clamped to 1..128.

Spatial queries

Fast utility functions that answer spatial questions without giving you a full TraceResult.

Trace.isVisible


The fastest way to check line of sight. Returns true if nothing blocks the path between from and to. Skips normal, material, and entity resolution entirely - just a yes/no answer.
Vector
required
Start position (e.g. eye position).
Vector
required
Target position (e.g. enemy head).
Use isVisible over Trace.ray when you only need a boolean - it’s significantly faster because it doesn’t resolve any hit data.

Trace.isSolid


Returns true if the given point is inside solid geometry. Useful for checking whether a calculated position is valid or stuck in a wall.
Vector
required
World position to test.

Trace.overlapSphere


Returns all colliders overlapping a sphere centered at origin.
Vector
required
Center of the sphere.
number
required
Sphere radius in game units.
string | TraceFilter | FilterOptions
Collision filter. Defaults to "bullet".

Trace.closestPoint


Finds the closest point on any surface within maxDistance of origin.
Vector
required
Search center.
number
required
Maximum search radius in game units.
string | TraceFilter | FilterOptions
Collision filter. Defaults to "bullet".

Results

TraceResult

Returned by Trace.ray, Trace.box, Trace.sphere, Trace.capsule, and each element of Trace.rayAll. entity - populated when resolveEntity is true and the trace hit a dynamic entity: surface - populated when resolveMaterials is true:

OverlapResult

Returned by each element of Trace.overlapSphere.

ClosestPointResult

Returned by Trace.closestPoint.

Collision tags

Tags control which collision layers are included or excluded in a filter’s includeTags / excludeTags arrays.

Recipes

Fast visibility check

Trace.isVisible is the fastest way to check line of sight - it skips normal / material / entity resolution and just returns a boolean.

Ground trace