Flash obstacle avoidance prototype

Obstacle avoidance can be very important in Flash gaming because allows designers to create smart enemies.

Obstacle avoidance behavior gives a character the ability to maneuver in a cluttered environment by dodging around obstacles.

In this prototype, I’ll try to simulate everyday life.

In everyday life, you walk straight until an obstacle appears in your line of sight.

Then, you slow down, and choose a random direction to cross the obstacle. If necessary, you make two or three steps back and approach the obstacle again.

Well, I hope you don’t act this way in your real life but this is what we are going to do in this prototype.

It’s up to you to improve it and make a more realistic movement.

In the project there are 20 random obstacles placed in the same way as seen on Create a Flash Game like Nano War, and an object linked as runner running through them.

Runner’s behavior is explained in the commented script

and here it is

As you can see, sometimes the runner is quite dumb, but it’s a good start to develop a more complex AI script for obstacle avoidance

Download the source code and enjoy

  • This is pretty cool and I can already see a few games that could be developed around it. The simplicity of it is also great. Good idea

  • You could always read about backtracking if you want your AI to navigate in a labyrinth.

  • Emanuele Feronato
  • Jon B

    If you want to make it look a bit slicker and remove some of the apparent dumbness you could make the current runner act as an invisible ‘scout’ for another runner who can follow the correct path without the last minute decision making lol.

  • Nathan

    Just noticed something, theres an ad on your title, don’t know if you want that there?

    This is pretty cool, sometimes the runner gets stuck in a rut, you could say, and will never hit any obstacles again, but as long as it has an obstacle in front of it, its cool

  • A lot of code, but works well. Now how do you get the player to go from one place to another avoiding obstacles?

  • npgames

    emanuele i demand you GET OUT OF MY HEAD

    im making a zombie game and was pondering how to do this for the past few days, and this just “MAGICALY” appears when i need it, i think not!

  • Wocker

    reminds me of the opensteer project. Take a look for some good (and opensource) sample code.

    http://www.red3d.com/cwr/steer/