Raycasting and Collision Groups

I’ve read some posts about people trying to figure out how to add multiple collision groups to the Raycast, but I realized that this isn’t possible and I haven’t found any possible work arounds yet so if anyone can help me it would be greatly appreciated.

Here’s my dilemma:

So I have set all invisible parts to their own CollisionGroup so raycasts fired from weapons ignores them as long as the CollisionGroup is set to default.
image

 local params = RaycastParams.new()
        params.FilterType = Enum.RaycastFilterType.Blacklist
        params.FilterDescendantsInstances = {Character}
        params.CollisionGroup = 'Default'

Another raycast though is needed to hit SOME invisible parts, and some VISIBLE ones as well.

        local params = RaycastParams.new()
        params.FilterType = Enum.RaycastFilterType.Blacklist
        params.FilterDescendantsInstances = {Character}
        params.CollisionGroup = 'Invis'

This code won’t work though because the ray will ignore all visible parts and only hit invisible ones, vise versa.

How would I go about making one ray ignore invisible parts while another ray recognizes invisible parts?

This would be a lot simpler if we were allowed to set multiple CollisionGroups in the RaycastParams like this:

params.CollisionGroup = {'Default', 'Invis')

You can use CollectionService to Tag all the invisible Parts and the non invisible Parts, so when you are casting the ray, you can tell the ray to ignore them using FilterDescendantsInstances, like so:

params.FilterDescendantsInstances = {Character, unpack(CollectionService:GetTagged("yourTag"))}

If you want, you can keep track of the Instances that were added to a specific CollisionGroup, and then apply it from there.

Also, you can just disable CanQuery on the Parts


It really would.

11 Likes

You’re the best honestly.

My only gripe is that objects can only be tagged in run time so I have to have a script iterate through all descendants as soon as the game starts.

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