- Home /
Player is "Seen" through walls by AI cameras
So I have a fairly simple tech demo structure - It's an FPS where you navigate through a maze and avoid guards (Hitman-esque). All of the guards are basic AI units, with a camera attached.
I'm using the Camera's OnWillRender() function (Which tells if an object is within the viewport, and thus will render), however, this will render my character even if behind a wall, and thus tell the AI that the player is within their line of sight, and alert them. Obviously, this is not good. I've tried using Occlusion Culling to no avail.
My summarized question is - How do I get the AI to stop "seeing" the player through walls?
Answer by Larcondos · Apr 23, 2018 at 02:05 AM
I have solved my issue, though doing it was not entirely using my above method.
To save on processing power I am still using the confines of the OnWillRender() function. When this is true I do a Linecast from the camera to the player, and if that linecast hits the player (Which will only happen if the player is not behind a wall!), then it will tell the AI I am in the line of sight.
Yes. I have an urban setting and got very annoyed when the enemies would shoot at me through walls. I was just using a simple Vector3 where if I was in a certain range they would attack. Then discovered raycast so if I am in range they do a raycast and will only fire if the ray hits the player . If it hits something else ( tagged "wall") I change the enemies $$anonymous$$Distance range so they get closer
Your answer
Follow this Question
Related Questions
occlusion culling conflict with shader,Occlusion culling conflict with shader 0 Answers
Render Gameobjects in one specific Layer as transparent, 1 Answer
Unity - blur on one camera effects the other as well 0 Answers
AR Render only area around character 0 Answers
Is it possible to view two camera at the same time? 2 Answers