World:shapecast

Edit

Moves a shape from a starting point to an endpoint and returns any colliders it touches along its path.

This is similar to a raycast, but with a Shape instead of a point.





Arguments

NameTypeDefaultDescription
shapeShape The Shape to cast.
x1number The x position to start at.
y1number The y position to start at.
z1number The z position to start at.
x2number The x position to move the shape to.
y2number The y position to move the shape to.
z2number The z position to move the shape to.
anglenumber The rotation of the shape around its rotation axis, in radians.
axnumber The x component of the rotation axis.
aynumber The y component of the rotation axis.
aznumber The z component of the rotation axis.
filterstringnil An optional tag filter. Pass one or more tags separated by spaces to only return colliders with those tags. Or, put ~ in front the tags to exclude colliders with those tags.
callbackfunction The function to call when an intersection is detected (see notes).

Returns

Nothing

Arguments

NameTypeDefaultDescription
shapeShape The Shape to cast.
positionvector The position to start at.
destinationvector The position to move the shape to.
orientationquaternion The orientation of the shape.
filterstringnil An optional tag filter. Pass one or more tags separated by spaces to only return colliders with those tags. Or, put ~ in front the tags to exclude colliders with those tags.
callbackfunction The function to call when an intersection is detected (see notes).

Returns

Nothing

Arguments

NameTypeDefaultDescription
shapeShape The Shape to cast.
x1number The x position to start at.
y1number The y position to start at.
z1number The z position to start at.
x2number The x position to move the shape to.
y2number The y position to move the shape to.
z2number The z position to move the shape to.
anglenumber The rotation of the shape around its rotation axis, in radians.
axnumber The x component of the rotation axis.
aynumber The y component of the rotation axis.
aznumber The z component of the rotation axis.
filterstringnil An optional tag filter. Pass one or more tags separated by spaces to only return colliders with those tags. Or, put ~ in front the tags to exclude colliders with those tags.

Returns

NameTypeDescription
colliderCollider The Collider that was hit.
shapeShape The Shape that was hit.
xnumber The x coordinate of the impact point.
ynumber The y coordinate of the impact point.
znumber The z coordinate of the impact point.
nxnumber The x component of the normal vector.
nynumber The y component of the normal vector.
nznumber The z component of the normal vector.
trianglenumber The triangle that was hit, or nil if a MeshShape was not hit.
fractionnumber The fraction along the ray where the impact occurred.

Arguments

NameTypeDefaultDescription
shapeShape The Shape to cast.
positionvector The position to start at.
destinationvector The position to move the shape to.
orientationquaternion The orientation of the shape.
filterstringnil An optional tag filter. Pass one or more tags separated by spaces to only return colliders with those tags. Or, put ~ in front the tags to exclude colliders with those tags.

Returns

NameTypeDescription
colliderCollider The Collider that was hit.
shapeShape The Shape that was hit.
xnumber The x coordinate of the impact point.
ynumber The y coordinate of the impact point.
znumber The z coordinate of the impact point.
nxnumber The x component of the normal vector.
nynumber The y component of the normal vector.
nznumber The z component of the normal vector.
trianglenumber The triangle that was hit, or nil if a MeshShape was not hit.
fractionnumber The fraction along the ray where the impact occurred.

Notes

The callback function is passed a collider, a shape, a world-space point, a world-space normal, a triangle index (for mesh shapes), and a fraction:

function(collider, shape, x, y, z, nx, ny, nz, tri, fraction)
  return fraction
end

The callback can return a fraction value used to limit the range of further hits. For example:

Shapecasts will hit sensors and sleeping colliders, but will not hit disabled colliders.

See also