Raycast inclusion / exclusion list without their descendants

As a Roblox developer it is currently too hard to raycast (and blockcast, spherecast, etc…) while including / excluding specific instances, but not their descendants.

RaycastParams.FilterType provides the option between an inclusion filter and a exclusion filter. However, both these filter types also include / exclude the descendants of any instances in the list. This becomes problematic when you want to do something like the following.

Run a raycast where you can hit ContainerPartA and the Part instances, but not ContainerPartB .

image

For example, one way to do this currently would be to turn CanQuery off for anything you want to ignore, but this also requires you to set CanCollide to false as well. Since this is happening so quickly that likely won’t have any impact on the physics of your game. However, if you are watching property changed signals and don’t have defered signalling on then you may have some problems.

From a bigger picture you might say just don’t place BaseParts as children of other BaseParts, but I’ve found cases where that structure is super helpful when building games. I.e. weld all baseparts to their parent.

There are some solutions of other approaches I can think of, but every one I can think of has some kind of con to it or isn’t generalized enough. It would be nice to have a solution built into the API.

My proposed solution would be to add two new filter types:
Enum.RaycastFilterType.ExcludeWithoutDescendants
Enum.RaycastFilterType.IncludeWithoutDescendants

Thanks!

18 Likes

you could always just unparent it from the largeted part but this is cool too

3 Likes

Again, I am aware there are some approaches that can resolve the specific example.

However, depending on the greater context of your game doing this may not be plausible and as such I’m looking for an API solution that is robust enough to handle cases without compromise from the developer.

1 Like

That’s fair enough, I guess a switch between old and this would be a boolean which would be nice.

1 Like

Not really?
You can just disable it through scripts.

While you can edit CanQuery without setting CanCollide to false, the property will have no effect during spatial queries / raycasts if CanCollide is true.

1 Like