WorldRoot:Spherecast() (In-engine spherecasting)

As a Roblox developer, it is currently too hard to do fast sphere casts in Roblox.

If Roblox is able to address this issue, it would improve my development experience because it would allow for much, much more complicated interactions in games. Unity has a sphere cast feature, and its effectively a raycast with a spherical radius all the way around it. (You can think of it like a sphere at each start and end point with a cylinder in between).

Sphere casting as a feature would allow for more projectile types, and much much more CPU efficient custom explosions. Sphere casting in-engine has the added benefit of not requiring the use of physical part objects and thus would be significantly faster than current methods.

Additionally games like Super Smash Bros use something similar sphere casting for combat, and if I’m not mistaken do in some cases use sphere casting. Sphere casting would be very useful when you need “big raycasts.”

Also, @Elttob pointed out below that Boxcasting would be a similarly appreciated feature. I think that raycasts, boxcasts, and spherecasts are all very important, and it is extremely important we have efficient means to perform these types of things.

And, ideally, raycasting, boxcasting, and spherecasting should be as fast as they possibly can be, as they are fundamental to some of the most core mechanics in a lot of non-Roblox games. All around I think these sorts of casts deserve focus.

108 Likes

Full support - this has been a showstopper for me before! Spherecasting (and boxcasting too!) are long overdue in Roblox :slightly_smiling_face:

24 Likes

In all honestly, it’s weird that spherecasting and boxcasting aren’t already features when Roblox recently did a massive overhaul to raycasting. I fully support this feature because it’ll make life for countless developers so much easier. A good example for this is that you could spherecast around a position to detect parts to destroy instead of wasting resources to loop through the entire Workspace.

13 Likes

I know one use I’ve seen, though I’m not sure if its effective for poorly optimized sphere casts, is finding things in range of something else, for example, sphere casting around the player at a certain radius. (I have literally no clue if thats a bad use or not tbh) I would be curious which would be better, though I guess if sphere casting was built in I would rely on it even if its slower solely for the reason that it can probably become faster in the future.

5 Likes

I am using deformable meshes on a project and really need spherecasting functionality to detect when a player’s deformable round head hits a border of the map so they can’t clip out of bounds. Normal raycasting seems to have issues that allow players to clip out of bounds.

7 Likes

I found myself with a similar issue with a primitive custom character system. A solution I found was using :GetTouchingParts(). I definitelly support this request as that method is only applicable for detecting whether a collision took place, not how.

3 Likes

On the roadmap.

The big raycast API overhaul set the stage for this!

84 Likes

Sorry to bump this, but please please include either a contact point (point and normal) or a plane of contact with this.
Because if you are using this for building no-physics character controllers (the primary purpose imho) you need the plane of the surface you ran into to “slide” the player velocity along it.
Right now I am emulating a spherecast using (way too many!) rays, and I would need this feature to be able to replace it.

10 Likes

I believe a few of these are in the engine so far, though I don’t think they’re enabled. You should be able to achieve a plane intersection with box intersection I think but it might not be the exact case you’re looking for, since it would only tell you “yes this intersects a plane” and not where on the plane.


cc @kleptonaut

I also want to note since this has been bumped, the method for sphere intersection that’s in the engine isn’t actually sphere casting.

Sphere casting is a raycast with a radius, but the existing implementation is not a sphere cast it’s just sphere intersection.

It’s important to note that since a lot of the use cases people would like sphere casting for aren’t covered by plain sphere intersection, and sphere casting can achieve the same sphere intersection by using the same two points as the start and end points.

The workaround is to use a cylinder part and two sphere intersections but this doesn’t necessarily work the same.


This is not related to Roblox or this request, but I thought it was cool to bring up a mathematical version of spherecasting using signed distance fields (SDFs) for the people that are interested. It also generalizes to all kinds of other shapes, anything you can define an SDF for, which basically includes everything.

I’ve sort of found that SDFs are great for implementing special casts between a piece of complex geometry and a shape that’s easy to define an SDF for, since they tell you if a point is inside, outside, or on the edge of a surface, and they tell you how far. If you can define an SDF (e.g. for a radial line segment) you can determine if a point intersects if the distance <= 0. IIRC you can also do this between two SDFs (I think it can be achieved by subtracting the two SDFs to get a new SDF or something and using the center point of either, I forgor though)

One approach is to apply the SDF to every vertex, which leaves gaps, but is typically accurate enough. A better approach is to define an SDF for the shape using line segments between the vertices of each face (creating a wiremesh type shape) and using that.

The last and fully complete approach is to create an SDF for the shape from its vertices, which is possible for convex shapes, and more difficult for concave shapes.

The SDF of a radial line segment can be used to determine intersection between any point and a radial line segment, I have no clue if this is the typical approach to a spherecast, but, it is extremely cheap, and mathematically accurate.

Here’s an excellent video by an excellent YouTuber:

5 Likes

Just a question on this, was full fledged spherecasting/boxcasting dropped, or did that get confused somehwere, or is it like postponed or something? @MrChickenRocket’s reply highlights what’s important about it pretty much, it’s in Unity and Unreal and such and was what my OP was requesting

A spherecast or boxcast should give a contact point and normal as opposed to just whether or not there’s an intersection which the spacial queries don’t do (I <3 the spacial query APIs though they are so useful and fast)

tl;dr: Remember to add Thick Raycasting to the roadmap please :pleading_face:

17 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.