How to detect if player see the object

How to detect if player see this object and when player see the object, something will happen.

3 Likes

I’m not sure if that is even possible, I could be wrong though. :thinking:

1 Like

like x-ray? :grey_question: :question:

1 Like

No,Just if player look at block then fire function

1 Like

You can fire a ray from the players head or humanoid root part and any object it hits, the player is able to see.

1 Like

Tell me how please and thank for respond

1 Like

Here is the API documentation to get you started.

If you don’t understand it, you may want to use this tutorial on making a laser gun but alter it to your character.

1 Like

i mean if you look at this object, it will say like print(“you look at this object”)

1 Like

please use the search function, this has been asked a few times before

1 Like

Use the :FindPartOnRay to return the object that the ray has hit.

3 Likes

Personally the way I’d do it is to get the angle between the player’s head, and the object’s position.
If the angle is less than 60 degrees, you proceed to create a ray from the player’s head, to the object’s position.
If the ray hits the object, it’s safe assume that the player can see it.

Alternatively, I’d probably use WorldToViewportPoint since the second returned item in the tuple is a boolean indicating if the WorldPoint is in the Viewport.

2 Likes