RaycastFilterType.Include not working as intended

So I’m trying to perform a raycast using the Include filtertype but it doesn’t seem to be working properly.

The documentation states that the Include filtertype works by only hitting objects that are descendants of the object in the list. From using the Exclude filtertype previously I know that one also included the object itself, not just its descendants (should really be reflected in the API documentation but I digress).

When trying to use the Include filtertype however, it was hitting every object regardless of the fact that there were no objects in the FilterDescendantsInstances array. When putting one object into that array it also continued with this behaviour though instead fixating on an unrelated object.

the line of code controlling the params:

HoverRaycastParams = RaycastParams.new(workspace.stupidpartthatthegameneedstowork, Enum.RaycastFilterType.Include)

it throwing an error as a result of the resulting raycast hitting an unrelated part:
image
(it repeated this many times)

Any help here would be appreciated.

Raycast params does not quite work like how you’re currently writing it.

You first create the params and then set the fields on seperate lines. Afaik you cannot set the fields in the constructor itself.

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = { ... }

local result = worldRoot:Raycast(origin, direction, params)
1 Like

I am shocked to see proper usage of the params lol honestly I gave up on the filter a long time ago :rofl: I just set can query to false on excluded objects and set it to true on included objects

1 Like

that’s really weird implementation on ROBLOX’s end considering .new() constructors usually work that way

but yeah you’re completely right that fixed the issue, thanks!

1 Like

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