World:shapecast
EditMoves 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
| Name | Type | Default | Description |
| shape | Shape | The Shape to cast. | |
| x1 | number | The x position to start at. | |
| y1 | number | The y position to start at. | |
| z1 | number | The z position to start at. | |
| x2 | number | The x position to move the shape to. | |
| y2 | number | The y position to move the shape to. | |
| z2 | number | The z position to move the shape to. | |
| angle | number | The rotation of the shape around its rotation axis, in radians. | |
| ax | number | The x component of the rotation axis. | |
| ay | number | The y component of the rotation axis. | |
| az | number | The z component of the rotation axis. | |
| filter | string | nil |
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.
|
| callback | function | The function to call when an intersection is detected (see notes). |
Returns
Nothing
Arguments
| Name | Type | Default | Description |
| shape | Shape | The Shape to cast. | |
| position | vector | The position to start at. | |
| destination | vector | The position to move the shape to. | |
| orientation | quaternion | The orientation of the shape. | |
| filter | string | nil |
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.
|
| callback | function | The function to call when an intersection is detected (see notes). |
Returns
Nothing
Arguments
| Name | Type | Default | Description |
| shape | Shape | The Shape to cast. | |
| x1 | number | The x position to start at. | |
| y1 | number | The y position to start at. | |
| z1 | number | The z position to start at. | |
| x2 | number | The x position to move the shape to. | |
| y2 | number | The y position to move the shape to. | |
| z2 | number | The z position to move the shape to. | |
| angle | number | The rotation of the shape around its rotation axis, in radians. | |
| ax | number | The x component of the rotation axis. | |
| ay | number | The y component of the rotation axis. | |
| az | number | The z component of the rotation axis. | |
| filter | string | nil |
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
| Name | Type | Description |
| collider | Collider | The Collider that was hit. |
| shape | Shape | The Shape that was hit. |
| x | number | The x coordinate of the impact point. |
| y | number | The y coordinate of the impact point. |
| z | number | The z coordinate of the impact point. |
| nx | number | The x component of the normal vector. |
| ny | number | The y component of the normal vector. |
| nz | number | The z component of the normal vector. |
| triangle | number |
The triangle that was hit, or nil if a MeshShape was not hit.
|
| fraction | number | The fraction along the ray where the impact occurred. |
Arguments
| Name | Type | Default | Description |
| shape | Shape | The Shape to cast. | |
| position | vector | The position to start at. | |
| destination | vector | The position to move the shape to. | |
| orientation | quaternion | The orientation of the shape. | |
| filter | string | nil |
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
| Name | Type | Description |
| collider | Collider | The Collider that was hit. |
| shape | Shape | The Shape that was hit. |
| x | number | The x coordinate of the impact point. |
| y | number | The y coordinate of the impact point. |
| z | number | The z coordinate of the impact point. |
| nx | number | The x component of the normal vector. |
| ny | number | The y component of the normal vector. |
| nz | number | The z component of the normal vector. |
| triangle | number |
The triangle that was hit, or nil if a MeshShape was not hit.
|
| fraction | number | 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:
- Returning 0.0 will abort the shapecast and ignore all other hits.
- Returning 1.0 will call the callback for all hits.
- Returning
fractionwill return successively closer hits.
Shapecasts will hit sensors and sleeping colliders, but will not hit disabled colliders.