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.

12 thoughts on “2D Line of Sight?”

1. Juuso Post author

@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. Juuso Post author

@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

3. tonic

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

4. Juuso Post author

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. :)

5. Andreas

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.

6. Juuso Post author

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

7. Andreas

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