World:querySphere

Edit

Find colliders within a sphere. This is a fast but imprecise query that only checks a rough box around colliders. Use World:overlapShape for an exact collision test.

Rough queries like this are useful for doing a quick check before doing lots of more expensive collision testing.

Pass a callback function to call for each collider detected, or leave the callback off and this function will return the first collider found.





Arguments

NameTypeDefaultDescription
xnumber The x coordinate of the center of the sphere.
ynumber The y coordinate of the center of the sphere.
znumber The z coordinate of the center of the sphere.
radiusnumber The radius of the sphere, in meters
filterstringnil An optional tag filter. Pass one or more tags separated by spaces to only return colliders with those tags. Or, put ~ in front of the tags to exclude colliders with those tags.
callbackfunction A function to call when an intersection is detected. The function will be called with a single Collider argument.

Returns

Nothing

Arguments

NameTypeDefaultDescription
positionVec3 The position of the center of the sphere.
radiusnumber The radius of the sphere, in meters
filterstringnil An optional tag filter. Pass one or more tags separated by spaces to only return colliders with those tags. Or, put ~ in front of the tags to exclude colliders with those tags.
callbackfunction A function to call when an intersection is detected. The function will be called with a single Collider argument.

Returns

Nothing

Arguments

NameTypeDefaultDescription
xnumber The x coordinate of the center of the sphere.
ynumber The y coordinate of the center of the sphere.
znumber The z coordinate of the center of the sphere.
radiusnumber The radius of the sphere, in meters
filterstringnil An optional tag filter. Pass one or more tags separated by spaces to only return colliders with those tags. Or, put ~ in front of the tags to exclude colliders with those tags.

Returns

NameTypeDescription
colliderCollider A Collider that intersected the sphere.

Arguments

NameTypeDefaultDescription
positionVec3 The position of the center of the sphere.
radiusnumber The radius of the sphere, in meters
filterstringnil An optional tag filter. Pass one or more tags separated by spaces to only return colliders with those tags. Or, put ~ in front of the tags to exclude colliders with those tags.

Returns

NameTypeDescription
colliderCollider A Collider that intersected the sphere.

See also