How can I check that the players look at a object?

I want to make a fuction, that the player have to look at a object and press E to interact with it.
Like if the player want to open this Fusebox, he must look at it before he can press E otherwise it should not execute my if statement to open the fusebox cover!
But how can I make a simple fuction like this? because I dont want to use only a collider trigger event because the player should look at the object with what he want to interact.

But how can I make this query that checks whether the center of the screen (where the crosshairs are) is exactly to look at the fusebox?

So that I can then ask in an if whether the player touches the collider of the Fusebox
(so he is close enough to it).
Additionally he is also looking at the fusebox and that he has pressed the “E” key to execute the if statement the open the Fusebox cover…

You can use a raycast shot from the camera position – if the raycast hits something interactable, the player can interact with it.

1 Like

Pretty sure you will want to set up a raycast or linecast. Then if it hits something, you can get results back on what it hits and determine that they are able to interact with it. Basically where you see something like “Press E to open” in games.

1 Like

thanks, that was probably exactly what i was looking for!