Monday, 3 March 2008

Flocking in Flash

I put together a simple flocking demo in Actionscript during the week and tweaked it a little over the weekend. The algorithm is very simple but does support a goal location and also obstacle avoidance. The goal by default is the top right of the map but you can click anywhere to set the goal there instead. You can think of this flocking as representing something like an insect swarm.

What's interesting is how the flock have some ability to find their way around obstacles without having any knowledge of the game space. They do know there is an obstacle there when they are repelled by it, but that is all. So no path finding in here, no influence maps, yet they do have some ability to get around the map simply as emergent behaviour.

There really isn't too much else to say about this as there are lots of flocking algorithms out there but not too many in flash so I figured I would share it with you.

Anyway, the demo is available here. It uses fifty sprites and is not optimised.