Hmm...I guess if Sixty Squares posted his code I'll post a little snippet:
Rem Project: Enemy Running Away
Rem Created: Saturday, January 17, 2009
Rem ***** Main Source File *****
//Here we set up some variables for our objects.
PoliceCar = 1
Enemy = 2
PoliceCarSpeed# = 0.8
EnemySpeed# = 0.25
//Now we set up our app.
Set Display Mode 1024, 768, 32
Sync On
Sync Rate 60
//We make a box for our police car and a sphere for our enemy and position them.
Make Object Box PoliceCar, 5, 2, 10
Color Object PoliceCar, RGB( 0, 0, 255 )
Make Object Sphere Enemy, 2
Color Object Enemy, RGB( 255, 0, 0 )
Position Object Enemy, 5, 0, 10
//Now we position the camera high above our car and enemy.
Position Camera 0, 75, 0
Point Camera 0, 0, 0
Do
//This handles the movement of our police car.
If KeyState( 17 ) Or UpKey( )
Move Object PoliceCar, PoliceCarSpeed#
EndIf
If KeyState( 31 ) Or DownKey( )
Move Object PoliceCar, -PoliceCarSpeed#
EndIf
If KeyState( 30 ) Or LeftKey( )
Turn Object Left PoliceCar, 3.0
EndIf
If KeyState( 32 ) Or RightKey( )
Turn Object Right PoliceCar, 3.0
EndIf
//This is where the enemy is handled.
//First we point him at the police car.
Point Object Enemy, Object Position X( PoliceCar ), Object Position Y( PoliceCar ), Object Position Z( PoliceCar )
//Now we turn our enemy AWAY from the car.
Turn Object Left Enemy, 180.0
//And now we move him.
Move Object Enemy, EnemySpeed#
Sync
Loop
That code doesn't handle obstacles yet. I'm doing that right now.
EDIT:
Here's a little snippet which shows a red ball dodging obstacles:
Rem Project: Enemy Running Away
Rem Created: Saturday, January 17, 2009
Rem ***** Main Source File *****
//First we set up our enemy variables and some obstacles.
Enemy = 2
Dim Obstacles( 9 )
For I = 1 to 9
Obstacles( I ) = I + 2
Next I
EnemySpeed# = 0.25
EnemyViewDist# = 100.0
IsColliding = 0
//Now we init.
Set Display Mode 1024, 768, 32
Sync On
Sync Rate 60
Randomize Timer( )
//Now we make our enemy object.
Make Object Sphere Enemy, 2
Color Object Enemy, RGB( 255, 0, 0 )
Position Object Enemy, -20.0, 0, 0
Point Object Enemy, 0, 0, 0
//Here we make and position five green boxes randomly.
For I = 1 to 5
Make Object Box Obstacles( I ), Rnd( 8 ) + 8, 1, Rnd( 8 ) + 8
Position Object Obstacles( I ), Rnd( 80 ) - 40, 0, Rnd( 80 ) - 40
Color Object Obstacles( I ), RGB( 0, 255, 0 )
Next I
//And these are walls, so our enemy doesn't leave the screen.
Make Object Box Obstacles( 6 ), 80, 1, 5
Position Object Obstacles( 6 ), 0, 0, 30
Color Object Obstacles( 6 ), RGB( 0, 255, 0 )
Make Object Box Obstacles( 7 ), 80, 1, 5
Position Object Obstacles( 7 ), 0, 0, -30
Color Object Obstacles( 7 ), RGB( 0, 255, 0 )
Make Object Box Obstacles( 8 ), 5, 1, 80
Position Object Obstacles( 8 ), 30, 0, 0
Color Object Obstacles( 8 ), RGB( 0, 255, 0 )
Make Object Box Obstacles( 9 ), 5, 1, 80
Position Object Obstacles( 9 ), -30, 0, 0
Color Object Obstacles( 9 ), RGB( 0, 255, 0 )
Position Camera 0, 75, 0
Point Camera 0, 0, 0
Do
//Now we move our enemy in increments forwards and check for collision each time.
For I = 1 to 10
Move Object Enemy, 1.0
//If we find any collision, we move our enemy back to his starting spot and set the IsColliding flag.
If Object Collision( Enemy, 0 ) > 0
IsColliding = 1
Move Object Enemy, -I
Exit
Else
//Otherwise we set it to 0.
IsColliding = 0
EndIf
Next I
//If the enemy collided at all, which means there's an object ahead of him, we turn him a random amount. This value can be edited for longer response times.
If IsColliding = 1
Turn = Rnd( 2 )
If Turn = 1
Turn Object Right Enemy, Rnd( 45.0 )
Else
Turn Object Left Enemy, Rnd( 45.0 )
EndIf
Else
//If there's no object we move him back to his starting spot.
Move Object Enemy, -10.0
EndIf
//Now we move him forward.
Move Object Enemy, EnemySpeed#
Sync
Loop
Function Dist( ObjA as Integer, ObjB as Integer )
D#=Sqrt( ( Object Position X( ObjA ) - Object Position X( ObjB ) ) ^ 2 + ( Object Position Z( ObjA ) - Object Position Z( ObjB ) ) ^ 2 )
EndFunction d#