- Home /
How to make walls that block light cones in 2D?
Hi everyone! I'm working on a top-down 2D stealth game. As pictured below, I'm trying to have enemies display a cone of light representing their vision area. The cone is simply a 2D sprite with a layer that puts it under everything except the background.
However, as you can see in the picture, the cone will go through objects. This isn't a problem to gameplay, since I can run a raycast to check that the sight's not blocked before enemies "see" the player, but it is a problem visually.

How can I fix this? At a basic level, I could run raycasts along the sides of the cone to detect the wall, and resize the cone, but that'd run into problems also, since not all parts of the cone will necessarily be blocked.
Answer by Flopado · Sep 12, 2015 at 09:23 PM
Try this: https://www.assetstore.unity3d.com/en/#!/content/3787 You'll be able to shape the light into any size and create events that will happen if something enters the light. You should also check this tutorial: https://www.youtube.com/watch?v=SguZi9uuEvw And sorry for the bad grammar, I'm Brazilian.
Your answer