to detect if the player is in an enemy’s field of view.
This needs a camera attached to the enemy, but does not need to render any output.
Is there a way to set a camera to not render any output? Obviously I can’t just deactivate it or the field of vision detect won’t work. Would setting the width and height of the output to 0x0 pixels do the trick?
I realize I could use a collider instead of a camera to detect the field of view, but I have only a few enemies in my game… how many cameras is it possible to use in this way before slowing things down?
I’m just wondering if unleashing more enemies on the player (each with a camera attached to check if the player is in their field of view) would be tough on CPU?
I know in the Unity manual it says “you can have as many cameras as you like in your scenes” but has anyone tried using say sixteen different cameras simultaneously before?
As mentioned, the cameras don’t actually need to render anything. I’m simply using them as a FOV detector.
I wouldn’t use a camera. I would test if the player were inside a view frustum using some note on the enemy.
I have an animating zombie model (who does’t) and attach a script to the head node. When the model turns it heads, the view frustum follows. Everyone once in awhile the script checks if the player is inside that volume. I think to keep the calculation fast, I assumed a 90 field of view. Once you know the player is inside the frustum, you could do a raycast to see if the player can actually be seen and isn’t behind some other object.
Interesting, that is in effect what I’m doing, but with cameras… First, see if the player is in the field of view. Then if so, I raycast to see if there is unobstructed line of sight.
Could you tell me a bit more about calculating the view frustum without a camera?
One plus of using cameras for me is that if one enemy sees the player (using renderer.isVisible) they all see the player. I know this is an effect most people wouldn’t want but it is exactly what I need for my game.
Is there a reason I shouldn’t use cameras in this way?
What if you made a collision/trigger the shape of the camera’s view. Then if the player entered that, check to see using a raycast if the camera can actually see the player, otherwise don’t make those checks. Wouldn’t that be less intensive?
Actually I did this to begin with, using a simple tapered box mesh with collider/trigger attached. It worked and yes, was probably less intensive.
But I went on to replace it with a real camera as it was easier to adjust the FOV and range via the inspector and I could also get a enemy-eye view of what the enemy could see. Its only now that I am wanting to add some extra enemies that I’m wondering if there will be performance issues using this technique, althoug the Unity Manual does say “you can have unlimited cameras in your scenes”.
My enemy cameras are set to cull everything except the player, so they don’t have to render anything like a complex scene as such. I haven’t noticed a performance issue so far, so I may stick with the method.
I’d just like to know if it’s possible for a camera to be active but not rendering/drawing anything… as that would surely save time.
If it does get intensive I can, as you pointed out, use triggers instead.