# 2D Line of Sight?

It’s becoming pretty obvious that I need some sort of “line of sight” system to figure out if the ninjas get spotted. (My current “compare direction and coordinate X” won’t go a long way).

I did check some BlitzMax archives, and was hoping to find some libraries but couldn’t find suitable yet. (It’s too late now anyway, so I’m better off by checking things tomorrow).

Here’s some articles I googled regarding 2D line of sight – seemed to have some decent info:

Any relevant links are most welcome.

### Juuso Hietalahti

1. @Joonas: That’s one cool avatar. O:)

…and, I might look something simpler – such as vision check. I think it’ll work just fine for me. Thanks.

2. You can likely use the A* algorithm. http://en.wikipedia.org/wiki/A*_search_algorithm

I wrestled with this some years ago when trying to put together a tile-based stealth title on BlitzBasic. What I came up with after brushing up my math skills for days was basically the A* algorithm. It worked for me, but I wasn’t using it in realtime.

3. @Andreas: yeh, thanks. Like Jake said… it was not in my line of sight. I was thinking something way too complex ^_^

@shagwana: I checked that one, thanks.

@tonic: eh, I’d rather keep it so that somebody else tackles this for me :P

4. Do yourself a favor and buy “Real-Time Collision Detection” by Christer Ericson, you’ll find lot of usable stuff there, including relevant stuff for problems like this (e.g. tile traversal). Every game programmer should own it. :)
http://bit.ly/RTCDbook

5. :) glad I could help. Sometimes you get blind to the simple solution.

6. That is bloody genius. How come I didn’t think of that.

Maybe I should do (1) less 2d math research when tired and (2) spend more time listening to people who know. :)

7. He he ok, well have a line for the guards line of sight, check that line against all gameobjects bounding box. If the ninja is the closest one itÂ´s visible.

8. yeh, but besides direction there could be wall/objects between them which makes ninjaInSight = false :)

9. some code got lost because of bad signs I imagine… if dot less than 0.5 AND dot more than -0.5 THEN ninjaInSight

10. Use 3d math. Get the right vector of the guard and the direction to the ninja (normalized vectors) use the dot product on these vecotors, if the result is 0 the guard is looking exactly at the ninja. You can check for a cone like this for instance if( dot -0.5) ninjaInSight = true