local IgnoreList = {}
for _ , v in ipairs(workspace:GetDescendants()) do
if v:IsA('BasePart') and v.Transparency == 1 then
table.insert(IgnoreList,v)
end
end
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Blacklist
Params.FilterDescendantsInstances = IgnoreList
workspace:Raycast(Origin,Direction,Params)
This is just a pseudo code , you can make changes to update the list/ loop through only specific instances.Note : If you add transparent parts in-game , you could DescendantAdded event to detect the newly added part and add them to the table by checking their transparency.
However you can use recursive function/loop and some basic math to avoid this method and cast the ray.
You can try using CollectionService and tag all instances you dont want to be hit by the ray. (Assuming you dont want ALL transparent parts to be ignored by the ray)
function RayCast(p,dir,ignore)
local Rayparams = RayCastParams.new()
Rayparams.FilterType = Enum.RaycastFilterType.Blacklist
Rayparams.FilterDescendantsInstances = ignore
local ray = workspace:RayCast(p,dir,Rayparams)
if ray and ray.Instance and ray.Instance.Transparency==1 then
local clone = {unpack(ignore)}
table.insert(clone,ray.Instance)
return RayCast(p,dir,clone)
end
return ray
end
Look, i already have a solution, but I don’t want to use said method, I want to know if there is a way to cast one, and one ray only and ignore if there is a transparent part in in front of said ray
This function is still casting two rays, although I appreciate everyone’s reply, but I dont seek to
cast more that one ray, or add all “invisible” descendants to the filter.
Look, I don’t know if you think providing solutions and giving insight to people on the devforum is enforced, but it’s not if you don’t have a answer you can just move on, it’s really not that important, plus feels like it’s this situation is getting heated.
Is there a way to automatically add transparency parts in an ignore list
If anyone would read this they’d assume that you want to ignore transparent parts while raycasting.
then you say
Look, i already have a solution, but I don’t want to use said method, I want to know if there is a way to cast one , and one ray only and ignore if there is a transparent part in in front of said ray
but the method provided by @Razor_IB casts one and only one ray and that should be the suitable solution for this problem.
Another thing one reading your post can make out is that you want the ray to ignore one specific transparent part and not all transparent parts in which case you can simply do this
Params.FilterDescendantsInstances = {IgnoredPart}
TL;DR you seem to contradict your goal in several of your replies
Because I clearly state that I want to cast one ray, and if that one ray hits a part that is transparent, is there a way to make the ray continue (go through) said part without needing to cast an additional ray.
Yes, I told you how to do that in my last reply. @Razor_IB’s solution is what you should be using with a few tweaks. All his solution does is make use of the IgnoreDescendantsList property of RaycastParams and adds all transparent parts to that list (which means there will only be one ray cast and that ray will go through and ignore all transparent parts.)
There aren’t transparent children in the object, there is one part over shadowing another part, is there a way to for the ray to go through the part without needing to cast another ray entirely?