Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I detect whether a part is visible?

A naive solution would be to cast a ray to center of the part, but this only tests if that point is visible, not whether the whole part is. See this image for an example of what I mean.

3 comments

0

What exactly are you trying to achieve? I've got a few ideas, most of them relying on the same ideas as lighting, but otherwise your question is a little unclear.

0

I'm trying to detect whether a turret has a line of sight to the player.

0

A line of sight to any part of the player, at all, even if partially obscured? You could try raycasting at the Player, and then moving along the obstacle until you're past the Player's bounding region.

1 answer

Well, I am going to give you an obvious solution to see whether a part is visible or not.

See by using an If statement you can easily check if something is of a certain value or even if it plainly exists like so.

if part.Transparency == 1 then
print("Part is not visible")
end

and if you use an else after print you can see if it is visible as well.

if part.Transparency == 1 then
print("Part is not visible")
else
print("Part is visible")
end

I also looked at the photo, but I wasn't sure if you wanted it to see if a part is visible once the ray-cast has hit the object or if you just simply wanted a way to see if a object is visible, if you want the ray-cast just add a comment to this saying so.

This discussion is preserved as it was. New answers, comments, and votes are closed.