Efficient way to calculate "vision cones" on 2D tile map?

Posted by OverMachoGrande on Game Development See other posts from Game Development or by OverMachoGrande
Published on 2014-08-20T18:00:18Z Indexed on 2014/08/20 22:35 UTC
Read the original article Hit count: 224

Filed under:
|
|

I'm trying to calculate which tiles a particular unit can "see" if facing a certain direction on a tile map (within a certain range and angle of facing). The easiest way would be to draw a certain number of tiles outward and raycast to each tile. However, I'm hoping for something slightly more efficient. A picture says a thousand words:

vision cones

The red dot is the unit (who's facing upwards). My goal is to calculate the yellow tiles. The green blocks are walls (walls are between tiles, and it's easy to check if you can pass between two tiles). The blue line represents something like the "raycasting" method I was talking about, but I'd rather not have to do this.

EDIT: Units can only be facing north/south/east/west (0, 90, 180, or 270 degrees) and FoV is always 90 degrees. Should simplify some calculations. I'm thinking there's some sort of recursive-ish/stack-based/queue-based algorithm, but I can't quite figure it out.

Thanks!

© Game Development or respective owner

Related posts about 2d

Related posts about algorithm