Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Character Avoiding Player [PB SRC]

Author
Message
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 6th May 2008 17:04 Edited at: 26th Mar 2011 22:28
Clever Coders Challenge #12 - Character Avoid Player (Game AI)

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



Download

playbasic source codes

Get Source Code




Related Examples

Movement Path Library Example
Field Of Vision
Line Of Sight

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-05-06 14:01:03
Your offset time is: 2024-05-06 14:01:03