Clever Coders Challenge #10 - Line Of Sight (LOS)
The aim of this example is demonstrate an approach for performing line of sight calculations between game actors and the player within a world space.
The world space represents 'hard' or impassible areas by drawing the outlines of various simple shapes (boxes, circles) into playbasic world. Normally if you creating game you wouldn't build the collision world in code like this example, you'd write an editor. But ya get that
Actors use this world definition to calculate player visibility by running ray intersection between the actors current position and the target. If the ray reaches the target position without hitting the world, then the actor can see the target, and attempts to move towards it. However is the ray hits the world, the target has gone out of view and the actor will just sit still. Giving the actors the most basic "Follow Me" style behavior.
I really recommend carefully picking through this world command, it's not difficult, but often overlooked.
Download
playbasic source codes
Clever Coders Challenge Board
Related Posts
Field Of Vision \Field Of View