Player looks at something and the something triggers a certain action

Hello, I am trying to make a horror game and make some “sudden” jumpscares, this one is something like “when a player turns around, and if on the screen there is a scary figure” I want the scary figure to rapidly move and unload, however, I can do it, I just want to know how could I trigger it, it should trigger even if the figure is on a corner of the screen. Thanks for any help!

To clarify, I tried looking everywhere, but I do not understand it fully as none asked a question like mine.

2 Likes

Try raycasting using the Head.CFrame.lookvector, then you can see if it faces within the certain direction or hits the part, then you trigger the jumpscare.

Will try to! Are there any other possible ways in case it won’t work as wanted?

You could also send a raycast from the camera’s position with a direction of the camera’s lookVector instead, if you want to see where the player is actually looking and not where their character is looking.

Yep, this is exactly what I wanted to, as the game won’t be 1 person, thank you! If it works, I will mark it as a solution.

https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToScreenPoint

This function allows you to check if a given world point is currently visible on screen.

1 Like