I've made a very simple 2D top down prototype with Unity. Now I want to expand the thing and add a feature where objects change when the player looks at them.
So I have to add a visibility polygon feature. I want to be able to get a list of objects (2d Colliders) which are in the Field of view of the player.
How I can do that?
I looked around and only found a tutorial which works with Physics2D.Raycast, but this seems to be only one ray as I need a field of view. Similar to the light of a flashlight.
I've drawn a sketch to illustrate my question:
In this case the list should contain the collider V1, V2 and V3 because the player can see them.
Edit:
- I experimented with the sending a "fan" of Raycasts every 0,1 ° but this solution does have some problems. The accuracy depends on how far the collider is away. Also this is not the best performing solution. And there are problems with small objects.
- As solutions like this: https://www.redblobgames.com/articles/visibility/ seems to be a lot of work just to reinvent something which is already out there I wonder if there is a built-in way in unity to help me to compute this area.