Checking to see if part is visible in the viewport?

I am trying to create a part that can only be interacted with if it is being looked at. I believe I need to do some raycasting, but I am not sure how to go about this.

3 Likes

Determining whether any part of an object is visible on the screen is a complex problem, but an easy problem is determining whether one point is on the screen, and you can check the point at the center of the object.
Camera:WorldToViewportPoint will give you the screen position of a point in the world. If it is not outside the bounds defined by 0, 0 and Camera.ViewportSize, and the depth (Z component) isn’t negative, then the point is on the screen.

5 Likes

Actually, WorldToViewportPoint returns two things.
It returns the Vector3 for screen position, and a bool that says whether or not the point is within the bounds of the screen. No additional checks are needed. After that, you can shoot a ray to make sure the point is not obstructed.

8 Likes