- Home /
2D Line of Sight with tiles
I'm making a top-down view game as seen below. The tan grid background is the base art, and as a player (P) moves and uncovers tiles, I will be using a sprite for the bordering walls as they become visible.
The map tiles with the red X's will not show unless the player has vision.
I need a technique for determining which tiles are visible. I've written a lot of line of sight (LoS) code over the years, but I'm wondering how best to achieve this in Unity with 2.5D. It feels silly to code 3D stuff that may already be built in.
The only solution I've come up with so far was to manually put in some invisible box colliders as "walls" wherever the black lines are, then do something with line casting from the player. Anyone have any suggestions for how best to solve this problem? I'd really appreciate some advice here.
I ended up doing what I suggested above. At runtime, I create a box collider on every square. I also create box colliders for the walls. Then, I cast a bunch of 2D rays out from the player to see what she can see, with the walls blocking rays. The more rays, the better, as it will account better for situations where you can barely see around a corner.
I recommend using Renderer.isVisible but sadly my answer is not approved yet.
Where is your answer posted? I don't see it.
Answer by gosaints70 · May 25, 2017 at 02:53 PM
If the tiles have a Renderer attached to them you can use the built-in variable Renderer.isVisible to check if they're in the camera's view.
Not sure that'd work for a top-down game unless you attach some kind of secondary camera to the player?!
Your answer
![](https://koobas.hobune.stream/wayback/20220613141938im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Need help finding a library/solution for efficient 2D tilemap rendering, collisions and interaction. 1 Answer
Pixel Perfect 2 Answers
find prefabs that extend Base Class c# 0 Answers
Is there another way of making a Top-Down-2D Map other than generating hundreds of Spriterenderes? 1 Answer
why is unity set tile not working? 0 Answers