Diagonal line of sight with two corners

Posted by Ash Blue on Game Development See other posts from Game Development or by Ash Blue
Published on 2013-05-31T06:34:18Z Indexed on 2013/10/30 4:17 UTC
Read the original article Hit count: 458

Filed under:
|
|
|
|

Right now I'm using Bresenham's line algorithm for line of sight. The problem is I've found an edge case where players can look through walls. Occurs when the player looks between two corners of a wall with a gap on the other side at specific angles.

Line of sight edge case

The result I want is for the tile between two walls to be marked invalid as so.

Desired result

What is the fastest way to modify Bresenham's line algorithm to solve this? If there isn't a good solution, is there a better suited algorithm? Any ideas are welcome. Please note the solution should also be capable of supporting 3d.

Edit: For the working source code and an interactive demo of the completed product please see http://ashblue.github.io/javascript-pathfinding/

© Game Development or respective owner

Related posts about 3d

Related posts about tiles