Creating a ray that automatically ignores transparent parts

You could do :

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.

4 Likes

Well what you could do is set up a registry system.

Whenever you add a part to Workspace that’s transparent, add it to the registry (a huge table essentially).

Then reuse this table for all your raycasting needs.

I don’t want to add all instances tho, it there like a “CanBeHitByRay” toggle .-. Lol

You told you want to ignore transparent parts, please give more context.Plus my script doesn’t add all instances.

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)

I think you could make a function like this

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

I’ve provided an example of what I want to achieve, but not using said method please read this topic and all of its contents properly.

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

Your context makes no sense , perhaps learn how to elaborate well.

1 Like

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.

I mean, everyone else “understands” the context of this topic and it’s Contents, just saying :man_shrugging:

Pretty sure everyone else didn’t ,cause you changed your goal in several replies.

I’ve read several of the provided reply’s, almost understands what I’m trying to do, except you?

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.

No we dont.
Your post description says that

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

1 Like

Did you read all of my threads?

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.)

But I stated that I don’t want to add descendants that are transparent to the filter.

unless theres parts within that transparent part (as children) then the descendants of that model will not be ignored

Here’s what I mean

in this case the non transparent part will NOT be ignored by the ray

BUT


in this case the non transparent part WILL be ignored by the ray (as its a descendant of the part)

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?