Space Query

physics.space.intersect_shape

Shared

Queries the physics world for all colliders overlapping a given shape at a position — useful for explosion radius or area-of-effect checks

Syntax

local results = physics.space.intersect_shape(
    shape,
    position,
    options = {}
)

Parameters

TypeNameDescription
tableshapeShape descriptor table
Refer Shape section
vector3positionWorld-space position to test the shape at as {x, y, z}
tableoptionsOptional query options table
Refer Options section

Returns

TypeNameDescription
tableresultsArray of tables, each with a collider field

Shape

Shapes are described by a table, only the fields of the chosen type are read.

TypeKeyShapeDefaultDescription
stringtypeAll-Shape kind to build
• "box" - uses size
• "sphere" - uses radius
• "capsule" - uses radius and height
• "cylinder" - uses radius and height
Required, an unknown type makes the query return an empty table
vector3sizebox{1, 1, 1}Full extents of the box as {x, y, z}
numberradiussphere, capsule, cylinder• sphere - 0.5
• capsule, cylinder - 0.4
Radius of the shape
numberheightcapsule, cylinder1.8Total height of the shape

Options

All fields are optional and fall back to their defaults if not specified.

TypeKeyDefaultSideDescription
intmask4294967295SharedCollision layers to test against, as a bitmask
The default matches every layer
tableexclude{}SharedArray of entities to ignore
Only physics bodies and areas are accepted, any other value is skipped
intmax_results32SharedMaximum number of colliders returned
numbermargin0.04SharedExtra collision margin applied to the shape
boolcollide_bodiestrueShared• When true - physics bodies are tested
• When false - physics bodies are ignored
boolcollide_areasfalseShared• When true - areas are tested
• When false - areas are ignored
intdimension0SharedDimension whose physics world is queried, from 0 to 65535
• Anything outside this range raises an error
• A dimension with nothing in it simply finds nothing

Examples

Query colliders in a radius
local nearby = physics.space.intersect_shape(
    { type = "sphere", radius = 5 },
    explosion_position
)

for i, hit in ipairs(nearby) do
    core.engine.print("info", hit.collider)
end

On this page