Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How can I detect whether a part is visible?

Asked by 8 years ago

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.

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. User#6546 35 — 8y
0
I'm trying to detect whether a turret has a line of sight to the player. jode6543 15 — 8y
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. User#6546 35 — 8y

1 answer

Log in to vote
0
Answered by
IcyEvil 260 Moderation Voter
8 years ago

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.

Ad

Answer this question