   LOS in hex grids
  Ok, I've gotten pretty far in my hex-based game programming. I currently working on line-of-sight (or field-of-view).My goal was to calculate LOS between 2 hexes by checking a line drawn from the center of hex 1 to the center of hex 2. If the line crosses any pixel of a hex that blocks LOS, the LOS would be blocked.I've based my code on Part 6 of the article on this page:http://www-cs-students.stanford.edu/~amitp/Articles/HexLOS.htmlHere's a screenshot:I drew in the red lines by hand to illustrate the issue below. The hexes with the red dots are within 10 hexes of the ork - his max sight range.I've got my code working - as far as it's doing exactly what I intended it to. Here's a image from current test code. The dark hexes are not in LOS of the ork. As you can see, there are some "floating" hexes that are within LOS - according to center-center line method.So, there seems to be a flaw with that method. I'm unsure what to do.I was thinking about making a 2nd check, if center-center line method results in blocked LOS, I was going to then check 6 more lines, from the center of the viewer's hex to the 6 vertices of the "target" hex, and if 3 (or 2, or 4) of the vertices are within LOS, I'll say the hex is in LOS. That would open up more hexes to being in LOS.Or... I could just make islands like that be NOT in LOS, the ruling being that a valid LOS can not pass through any hexes that block LOS, OR any hexes that are blocked themselves.Any other ideas? Has anyone seen this before?Is there a commonly used solution for such a problem?Thanks!Greg   
  The easiest method would probably be to do the testing in a outward spiral from the target hexagon, and test verus ANY los hexagon.Logically, if you can't see one hexagon, you can't see the hexgons behind it either.Physically, you'll end up with los patterns that are a bit larger than they should be... but they'll look more visually pleasing.If the increased los size becomes a problem you can combat it with los grey areas - use los volumes (like shadow volumes) and any of the edge of the los region can, behave with slightly different los properties (mebbe you can see the other characters, but not tell what team they're on, or something).   ;  On your example picture, the hexes 641 and 642 (for example) are indeed not within LOS, if you assume that you can only see a hex if you see its center, and if you assume that a tree takes up the entire space of a hex. Perhaps you want to relax either or both of those conditions. :) For example: imagine a small circle around the center of the target hex. You can project two tangents from the origin to the sides of the circle, and see if either of those lines is interfered with. Similarly, instead of checking if the line goes through a hex, you could check if it passes within a certain distance of the hex's center (by using a projection to find the closest point on the line to the hex center). I think that would be more robust that checking for visibility of the corners of the target hex - but try it.In any case, once you have behaviour that feels right, you can pre-calculate the "shadow" made by a tree at any position within FOV, and then just union those to get all the blocked hexes. This is a common idea in Roguelike game programming, sometimes referred to as using "vision tables".   