If you are directly below or above the object the 'line' becomes too thin and isn't displayed. Now you can do a workaround by making the line 2x2 pixels instead of 1x1. But then it overlaps the backgrounds in some situation where it shouldn't. IE the enemy is one field above and one to the right of you. At least in my game it is like that. I use a grid movement.
Also it doesn't seem to work if the enemy is off the screen.
I'm trying to get LoS in my game using Sketchy's example but it grinds everything to a massive halt when there are 50+ enemies/players all with shoot-if-distance < x conditions running around... I wish I could implement it but I may have to let it go and just have my units look stoopid firing into walls and such.
@Blubblub -
Where are the hotspots on those objects?
If they're in the top-left corner, there *is* a clear line of sight, because the blue object is not properly aligned to the grid. Either way, you should *always* put the hotspot in the centre of the object when checking line of sight (or use the action point instead, and put that in the centre).
Which example is that anyway?
There are two basic ways of doing it:
A. Have a small detector, and move it step-by-step from A to B - it's potentially buggy and may miss collisions if the step is too large; you can check for the exact point at which the line of sight is broken; it's slow, but may be faster than the alternative if you're not using HWA (especially if you use larger steps).
B. Stretch and rotate a detector to form a line - if you're using HWA it's very fast, but it may be slow if you're developing for Flash/iOS/etc which don't benefit from HWA; it gives 100% accurate, bug-free results; it only tells you *if* the line of sight is broken, not *where*.
@Noodles -
100+ objects certainly shouldn't be a problem with HWA. If you're using Flash / iOS exporters, you might be better off using the other method, but it'll probably still be slow.
If you have many enemies and many players, using ForEach loops instead of fastloops will make a big difference. Also, make sure you only resize the detector after checking the distance/angle (and keep the maximum shooting distance quite small).