Blacklisting Surface Normals Raycasting?

What would be the best way to blacklist or whitelist specific surface normals? As it can’t be done with FilterDescendantInstances(as it takes in instances) Would there be a way to do this or a method for it to be “whitelisted” on certain surface normals?

2 Likes

Hmm, what’s your use case for this? Are you perhaps trying to distinguish between a wall, floor, and roof perhaps via surface normals?

If so then one way to do it is to measure the angle of the surface normal with a world UpVector then using if statements ignore the raycast result or make it nil if it doesn’t fit your criteria in this scenario if the angle is 0 then the surface normal is parallel with the up vector and such.

Hard to consider if this method is the best way without considering the context of the use case.

Yes, that’s exactly what I’m trying to do. I don’t get what would be the point of measuring the angle, could you explain it a bit further?

Maybe another way would be to use if statements to check if the surface normal is the same as the upvector, and if not then set the ray result to nil? (I’m not sure if this is what you already said, as I’m having trouble understanding )

Well this way could work

I’m assuming by up vector you mean pointing up towards the sky, relative to the world kinda thing.

but what if the floor is somehow slanted like a ramp even a bit? Then it wouldn’t be the case as the == conditions would say it’s false which is why I would suggest an angling method.

Here is what my method would look like of calculating the angle between vector A which is the world’s up vector or pointing up towards the sky and B which is the surface normal:

Yeah by measuring the angle you can allow a range of conditions to be true on what you determine is to be a wall and what you determine is to be a sloped floor like so:

local angleBetweenAandB = 50 -- in degrees

if angleBetweenAandB> 80 and angleBetweenAandB < 100 then
print("Raycast hit a wall")
end

You can also determine if the raycast hit the roof if the dot product is negative in the scenario but I’ll leave it up to you to write the if conditions.

2 Likes