# Line of sight

Hi to all. This is my first attempt at AS Artificial Intelligence Programming that’s better than just adjusting the enemie’s _y coordinate relative to the player’s position.

Short intro, skip this paragraph to get on with the brass tacks. Now, what I want to do, is a top-down game where the player has free 360º movement and aiming capabilities. The player character(let’s call him James)'s direction, and _rotation, is always pointing towards the mouse pointer. Pressing forward and backwards means the player walks or backpedals towards the mouse and left and right is sidestepping, relative to the pointer (so if you want to sidestep in a straight line you have to move the mouse so that James keeps facing the same direction). You have to imagine a FPS without the Z coordinate and you can get the feel of it.

Now, my AI is patrolling around a “tile-generated” universe, using the main four possible directions, 0(360), 90, 180 and 270. So the little guards about to be shot by James (I’ll leave it to you to guess our Double Oh agent’s family name) would patrol around vertically and horizontally UNTIL THEY SEE THE PLAYER. Then, once they see they player, the guards would be in their “agressive mode”: they’d stop moving and concentrate on shooting in the direction of James. Agressive mode is a boolean checked at every frame. If James moves out of the line of sight, the guard resumes patrolling. This whole line of sight thing is the hard part. I’m able to calculate the hypothenuse of the two coordinates (the guard’s and Jame’s) in real time and to show/trace a boolean which dictates if James is in range of the guard. But I don’t know how to trace a line and see if there’s any obstacles between the guard and James, such as walls or crates.

Finally, my question: Suppose these obstacles are all instances of duplicated movie clips, how do I determine if an object is in the way (thus blocks line of sight) of the guard?

[font=Arial]Supplementary: I tried to have a small mc that’s like a pixel large and wide and that travels along the hypothenuse of the aforementionned points (guard’s and Jame’s coordinates) and thus that could see if it hits an obstacle along the way, turning a boolean false and thus proving the guard cannot see James. But I cannot make that because the checks have to be made every frame, and the movement of that little reticule has to be done onEnterFrame. So we have to be more creative…and I still haven’t found how![/font]