Line-of-sight algorithm

I’m building and RPG and working on the Monster AI. I got my head around the A* algorithm for path finding and it’s working fine. Now I’m trying to deal with ranged weapons and line-of-sight.

For example a player may want to take aim at a monster. How can I decide if he can see that monster? Maybe there’s a wall or other obstacle in the way. I could check simple directionality to see that a path is successful and straight but I think I should allow aiming around some things (like maybe another player).

Any thoughts on this topic?

TIA

Try doing line-line intersection tests. Java.awt.geom.Line2D.linesIntersect is v fast.

Thanks. Gives me something to digest over the next few days. :slight_smile:

Each thing should have a property, “canSeePast” or somesuch, that determines whether it blocks LOS.
I use Bresenham’s line algorithm for plotting LOS at high resolution through a low-resolution tile map.

Cas :slight_smile:

Thanks. I found the Wikipedia entry on this. :slight_smile: