Creating a vision cone with occlusion

I need to be able to create a number of vision sensors on an NPC. These need to be able to detect if the NPC can “see” other game objects, so it needs to take occlusion into account.

I was told there was two ways to do this.

  1. Cast Rays in an arc - I can do this, however, as the rays get further from the oragin, there are gaps between them. Meaning something could be in the vision cone but be in a “blind spot”.

  2. Attach a camera to the NPC and check if the game object is visable to that camera - … I was told this was possible but I cant find any guides on how to do this and access the information. Is this actually a possible method? And if so, is it a computationally expensive way to go?

Thanks for the help!

Or there is a third method which is explained in this tutorial from project Stealth.

CCTV CAMERAS

Hi you could try this, go to my answer to this question and get the 3D cone model. Use this as your main collider for the vision. When you get an on trigger stay event in this cone for the right type of object, raycast from the eye position to this object. If the object returned by the raycast is not = to this object that you cannot see it.