Is it possible to have 1 ray detecting multiple parts at once? I cannot find any information about this and the default workspace-ray functions return only 1 part. Is there a hidden property that allows the ray to continue until the endpoint and collecting all of the parts that intersect with that ray? And if that is not possible can you explain me why this hasn’t been added?
This would be really usefull for me and it would save me from spawning alot of rays after eachother.
There’s no built-in way of doing this. But you can achieve the same effect by raycasting repeatedly, adding each target to an ignore list before doing the next raycast. One implementation might look like so:
function findAllPartsOnRay(ray)
local targets = {}
repeat
local target = game.Workspace:FindPartOnRayWithIgnoreList(ray, targets)
if target then
table.insert(targets, target)
end
until not target
return targets
end
You can read up on the other two raycasting functions here and here. The second argument to FindPartOnRayWithIgnoreList is a table containing all the parts that you don’t want to “hit” with the ray.
It’d definitely be nice to have a built-in way of doing this, especially since it would probably run quite a bit faster when doing many of these sorts of raycasts.