News:

Function Finder  Find all the functions within source code files

Main Menu

Field Of Vision / Field Of View (FOV) (Game AI)

Started by kevin, January 27, 2008, 09:48:23 AM

Previous topic - Next topic

kevin

Quote
   ; *=-----------------------------------------------------------------=*
   ;         >> (Game AI) Field Of Vision / Field Of View (FOV) <<
   ;
   ;                          By Kevin Picone
   ;
   ;                          27th, Jan, 2008
   ;
   ;        (c) copyright 2008 Kevin Picone, All Rights reserved   
   ; *=-----------------------------------------------------------------=*
   ;                           www.PlayBasic.com
   ; *=-----------------------------------------------------------------=*
   ;
   ;  The aim of this example is to demonstrate one method for detecting
   ; if the Player (or Actor) is within another actors view, aka Field Of
   ; Vision (FOV).
   ;
   ;  You can imagine the  FOV of a PIE shape area attached to the actors
   ; position.  The shape would look a lot like head lights from a car at
   ; night.   To  represent this pie shape area we need two things,  the width
   ; of this field of vision in degrees and our maximum view range (how far can
   ; this character see?).  The latter is not essential, but it's often those
   ; little extra's we include in our  actor's behavior, that will (in the
   ; long run) enable us to create more balanced computer controlled opponents.
   ;  There's nothing worse than when the actors in a game have perfect aim or
   ; know insanely where you are within the game arena.   
   ;
   ;  To determine if one actor can see the another, all we're doing is finding
   ; the direction (angle in degrees) from the actor to it's target.   Once we
   ; have this, it's just a matter of finding then difference between the Actors
   ; current direction and the direction towards the target,
   ;
   ; i.e.
   ;           AngleDiff#=AngleDifference(ActorsAngle#,AngleToTarget#)).
   ;
   ;  To determine if the target is potentially within our view,  we just check
   ; Angle Difference is lower than the width of this actor FOV, if it is, it's
   ; potentially inside.    To be sure,  we need to check the distance between
   ; actor and the target, if it's within the FOV view range, then this target
   ; is with the actors FOV.
   ;
   ;
   ;  The demo represents the game actors as rotating blobs,  with a pie shaped
   ; polygon shape attached representing the actors FOV.  The player is simply
   ; the mouse pointer.  The behavior of the actors is much a radar in this
   ; example. As such, if the Actor is unable to see the Player, it will
   ; happily sit and rotate right (clock wise),  but if the players moves in
   ; front of the Actor,  then the actor will try and turn towards the Player.
   ;
   ;  Well, that';s about it... Have fun !
   ;
   ; *=------------------------------------------------------------------=*


  Written in PB1.63.    Source Code Attached



Related Examples

Movement Path Library Example
Line Of Sight
Character(s) Avoiding Player
Clever Coder Challenges




ATLUS