- Home /
Security Camera Scripts?
Hi. I'm creating a watchdog-esque stealth game where you do stuff undetected by the enemies. I am creating a camera system that detects the player, but for ray casting, I want to have a perspective view, and I want the ray cast to not go through walls. How can I create a camera script to do this? Thanks. All helps will be appreciated.
Answer by phil_me_up · Dec 15, 2015 at 10:35 PM
You should just need to do a raycast from the camera in the direction of the player and inspect the hit results. If there is a wall in front of the player, then that will be your hit result (assuming that the raycast is configured to collide with whatever layer the wall is on).
You probably don't want to be doing this all the time though, so I'd suggest setting up a tirgger box on the camera which, when the player enters / stays within the trigger a ray is fired between the camera and the player.
Raycast info: http://docs.unity3d.com/ScriptReference/RaycastHit.html
Your answer
![](https://koobas.hobune.stream/wayback/20220612052740im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Raycasting with multiple cameras and displays 1 Answer
Raycast hits player when looking down 1 Answer
Raycast - Making ray shoot down vertically -Vector.up 1 Answer
Canvas interaction on render texture to message PhysicsRaycaster 1 Answer
Raycast object flies towards mouse on screen, i need it on floor 1 Answer