# Drawing visibility polygons in Unity (for vision cones with occlusion)

I'm currently trying to create an effect like the one displayed below in Unity:

However, it seems that I can't do this with any of Unity's built-in light objects, and I simply cannot find anything online that talks about this. Is there a way to achieve this in Unity? 2D or 3D solutions are fine, as I'm sure that they're both very similar to each other,

• Do I understand correctly that you're trying to draw something like a vision cone, visualizing gaps due to obstructions? Something like a Visibility Polygon with a particular angular field of view? If so, I think you're right that there's nothing native in Unity to generate this, but there are guides for how to implement your own – DMGregory Apr 25 '16 at 16:46
• @DMGregory I am trying to get something like that. Thanks for the link. – Ethan Bierlein Apr 25 '16 at 17:14
• Another nice example/explanation here that even covers doing some fade-off near the edges. Neat effect even if it's not useful to you. – Draco18s no longer trusts SE Apr 29 '16 at 17:56
• You could cast many rays and then join the endpoints and fill in the area between the player and the end line. Just an idea, not sure how you could do that but I'm sure there's a way. – Vadim Tatarnikov Apr 30 '16 at 5:48
• Have you checked this? – idurvesh May 2 '16 at 3:58

You can use a dynamically generated mesh. The points for the mesh can be obtained using one of the techniques described in the links from the comments. Those steps are as follows:

1. Collect all the objects in your vision cone. This depends on what you're using for your vision cone and underlying data structure for keeping track of your objects. You could use a collider for your vision cone and maintain a list of objects using OnTriggerEnter and OnTriggerExit, or you could do a Physics.SphereCastAll.
2. For each object
1. Get the points that define the object's collider, or otherwise find the edges of the collider.
2. For each point
• Cast a ray from your vision cone source through the point to the edge of your vision cone.