Hi Creators,
Today we’re releasing generalized shapecasts. These allow you to cast any arbitrary part into the world: Blocks, spheres, cylinders, wedges, CSG, MeshParts, etc.
We previously released Blockcast
and Spherecast
as ways to find collisions using swept shapes. These can be thought of as “raycasts with volume”.
Until today, shapecasts were limited to block and sphere shapes, which limited their usefulness. Even if you started with a block or sphere-shaped part, you couldn’t simply plug the part into the shapecast query; you had to manually copy over the CFrame/Size values.
For performance reasons, you can’t cast terrain, i.e. use Terrain as the part argument in Shapecast.
Use cases
- Draggers: To create a furniture dragger, you previously had to cast many rays and do a bunch of math. Casting the mesh directly simplifies this and results in more accurate collisions.
- Projectiles: To simulate a rocket’s collisions, you previously had to approximate the rocket shape with block/sphere/raycasts. You can now accurately cast the rocket directly.
- Mesh collisions: Developers could previously only use approximations for other objects such as swords and car colliders. Casting meshes allows more accurate collisions with less code.
API
WorldRoot:Shapecast(
part: BasePart,
direction: Vector3,
params: RaycastParams?
): RaycastResult?
Parameter | Summary |
---|---|
part |
The part to cast. |
direction |
The direction in which the part is cast. Direction.Magnitude is the maximum distance the part will travel to find a hit. |
params |
RaycastParams struct for defining filters. |
Usage is congruent to the existing shapecast methods, but we now take a part instead of a shape / cframe / size.
What’s coming next
Performance
Performance is acceptable for smaller cast sizes, but large casts against dense worlds can be pretty slow. We plan to optimize this with our ongoing broadphase work.
Collision Margins
A common pain point with shapecasts is that there is no collision margin (aka “skin”). This means that a shapecast starting flush with another part won’t detect that part. We’ve heard your feedback, and this is one of the next steps we will be taking for shapecasts.
Optional CFrame override
We’ll be adding an optional “cframe” param to override the part’s original CFrame later this year.
Thank you for your feedback so far! Let us know what you think and if you have any questions below.