News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Character Avoid Player

Started by kevin, May 06, 2008, 08:37:03 AM

Previous topic - Next topic

kevin


>> Clever Coders Challenge #12 - Character Avoid Player  (Game AI)  <<
 
By Kevin Picone

6th, May, 2008

(c) copyright 2008 Kevin Picone, All Rights reserved   



    The aim of this sample is build some simple 'run away from the player'  styled behavior into our dumb game actors, which are represented by simple blobs.   

     In this sample, each actor in the game (well demo in this case) checks it's proximity to the player.   If the player is getting too close, a Run Away counter is set and the actor then chooses a random direction it should move it.   Then each update, we move this object in it's run away direction until the counter has reached zero.  That's it.. 

     While this will make the actors appear to be afraid of the player, there are a few problems.   Namely,  since where picking a runaway direction randomly, our actors will happily run away into the bounds of the screen and gut stuck, also our actors are not aware of each other. So they'll run into and pass through each other.

    Both can be overcome by adding collision and choosing a more appropriate 'run away' direction.   In other words,  rather than picking a direction at random.  We'd need to survey our environment for the direction with the most available open space.   This can done via ray intersection.

   We could cast out a cluster of rays from the objects position, then pick direction which is the longest (this longest one is the one with potentially the most space to move).    We'd also need to consider if any other objects are within our potential moving range.   Since other actors may well be blocking our escape.     But that's something for another day :)



Written in PB1.63v - Source Code Attached


Related Examples

Movement Path Library Example
Field Of Vision
Line Of Sight
Clever Coder Challenges