- Home /
How to detect an object which be in FOV of certain camera ?
Hey,
I'm working on stealth game, I was trying many ways to make a camera detect an object which be in FOV (field of view) of it.
But I have met many problems, the major problem is when i'm using methods of unity such as (Renderer.isVisible) all cameras of game use the method even scene camera !!!.
How to solve that ?
Note: sorry if my English language is not clear.
are you talking about the player's camera? or the npc's "camera"?
Answer by pako · Oct 26, 2018 at 06:52 AM
You can create a BoundingSphere for your Object: https://docs.unity3d.com/ScriptReference/BoundingSphere.html
... and then use it with a CullingGroup:
https://docs.unity3d.com/Manual/CullingGroupAPI.html
https://docs.unity3d.com/ScriptReference/CullingGroup.html
...which allows you to select a target camera.
O$$anonymous$$, but if your object is a moving NPC you'll have to "update" the BoundingSphere. You might find this post useful:
https://answers.unity.com/questions/1278677/cullinggroup-boundingsphere-position.html