Boids AS3 Demo

I’ve uploaded the Boid source code. Sorry for the delay. I’ve also included some basic examples of how you can create nice behaviors using the Boid class. If you set as your document class then you’ll see that within that you can specify the demo to run when you compile.

The basic demos included are:

  • Chase – Boids chase each other
  • Flock – Boids flock together with some wander
  • Graphics – How to use custom graphics with a Boid instance
  • Seek – Boids seek the mouse position
  • Wander – You guessed it, they wander

I’ve commented all of the methods and properties and there is also documentation (open index.html in the docs folder) to get you started. Before you mention it, yes, there is some redundant code ;) (such as the constrainToRect method which doesn’t really work) but I need to do some optimisations anyway so I just left it as is for now, rough and ready.

Download: AS3 Boid Class & Demos

It’s been a little while since I posted! I’m in the process of moving house and office, plus I’ve been repeatedly slammed at work. Apologies to those of you who’ve left comments and haven’t got much by way of reply. I’ll hopefully be visible again over the next few weeks.

I actually coded this experiment back in November, but only recently decided that enough was enough and hijacked an evening so I could tidy up the code and build a UI for the demo.

Since coming across Craig Reynold’s paper; “Steering Behaviors for Autonomous Characters” whilst I was researching complexity theory for a university project (it wasn’t as academic as it sounds!), I’ve found myself becoming fascinated by flocking and swarm beahviors and the notion that you can create complex systems from relatively simple components. Much like the Cellular Automata, you can program an agent to have only a limited set of abilities and awareness, define a set rules for it to follow, and then create a multitude of instances of the agent to see what patterns begin to emerge through their interactions.

Flocking is a great example of this, as Reynolds demonstrated. His agents, or “Boids”, could perform certain maneuvers, such as seeking a target, fleeing from a predator, avoiding obstacles or wandering randomly. Combine these behaviors though, and allow each Boid to consider it’s neighbors when deciding on its locomotion, and complex behaviors begin to emerge.

The most infamous of these combinations is that of separation, cohesion and alignment, as it can produce a swarm behavior reminiscent of flocking birds or shoals of fish.

Separation means that each Boid attempts to maintain a certain distance from its immediate neighbors, Cohesion ensures that each Boid attempts to stay close to the centre of the immediate flock and Alignment will calculate the average heading of the flock and steer towards this vector.

Each of these behaviors is fairly simple in isolation, but the results can give the impression that some significant AI is at work, when all that’s really going on is some simple vector math.

Robert Hodgin has done some amazing work with flocking behaviors, so too has Psyop, and of course Reynolds is the daddy of all this stuff. There are some good libraries out there too, such as OpenSteer, and Keith Peters talks about this too in Advanced Actionscript Animation.

I’ve been trying to sharpen up my mathematical skills lately though, and was eager to play around with the new (new when I created this experiment anyway!) Flash Player 10 API – the 3D aspects in particular. So at the core of the Boid class are the native Vector3D, Matrix3D and PerspectiveProjection classes. Ok, so we’ve all got our own Vector3D and Matrix3D class in our library, but I thought it’d be good to use Adobe’s, especially seeing you can then apply the Matrix3D directly to a DisplayObject’s transform property.

Another cool feature I came across was the Matrix3D.pointAt() method, which will rotate a Matrix around a given axis and in this case can be used to orientate the Boid to it’s heading vector… Nice!

I’ve had a lot of fun putting together the Boid demo anyway – tweaking various settings on the individual Boids as well as the group behaviors (my personal favorite is ‘Chase’ mode with ‘Number of Boids’ cranked right up!).

If you have a play with the settings though, you’ll quickly see what I mean about the plethora of different effects that can be accomplished, even by simply adjusting the locomotive abilities of the Boids.

Due to said lack of free time as of late, I haven’t documented the code fully, though I have started and so if anyone is interested in the source code then please say so in the comments and I’ll try and finish the job (after a mere 6 months!) and put it up for download.

Posted on 05 May 2009
19 Trackbacks


Flipping you the Boid was posted on May 5th 2009 in the category Lab / Actionscript 3.0, Code, Flash, Lab, Open Source and tagged; , , , , , , , .

You can Leave a comment.

Warning: file_get_contents( [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 410 Gone in /home/soulwire/webapps/soulwire_blog/wp-content/themes/soulwire/functions.php on line 203


68 Responses to Flipping you the Boid

1 4 5 6

Leave a Reply

Pingbacks / Trackbacks

  1. 7 years ago AS3 Boid Flocking Simulation using Steering Behaviors - AI Flash Player 10 — Some Random Dude

    [...] AS3 Boid Flocking Simulation using Steering Behaviors – AI Flash Player 10 [...]

  2. 7 years ago Notes & quotes » Blog Archive » Mother flocker

    [...] the day after I wrote those previous lines, I had an email from Justin Windle tellin me about is brand new flocking class  for FP10. I was very exited because it was he most achieved boid manager done in as3 (at least for [...]

  3. 7 years ago Notes & quotes » Blog Archive » Flocking manager for away3D

    [...] I rewrote and was gonna work again on it. Then a few days ago Justin came with his wonderfull boid class, that was my new start point. I had to rewrite a lot of it to make it accurate with away3D, because [...]

  4. 7 years ago Flocking around with AS3 and Multitouch | SethSandler

    [...] recently came across a great and clean example of some boids code by soulwire (make sure to check out his whole site; it’s great). Since we’ve seen various examples [...]

  5. 6 years ago Overarching Inspiration < egnm3004

    [...] Soul Wire & Flock Systems Post a comment | Trackback URI [...]

  6. 6 years ago The secret life of points (part 1)

    [...] A computer science classic is Craig Reynolds’ Boids, a system where a few points each with a set of simple behavioral rules and environmental awareness can approximate bird flocking in a scarily accurate way. An excellent Flash example can be found here. [...]

  7. 6 years ago alberne frage... - Flashforum

    [...] pros – sch

  8. 6 years ago Random Steering – 7 Components for a Toolkit · code-spot

    [...] Flipping you the Boid (ActionScript swarming behaviour demo – with source code). [...]

  9. 6 years ago Post-A-Day #4 – Objective-C Flocking-Behaviors/Boid Class » Onedayitwillmake

    [...] actually didn’t work all that great, but, I came across SoulWire’s interpretation of Flocking (also in AS3), and I ported that. Maybe it was because it was my second attempt at porting, but this time I got [...]

  10. 6 years ago Post-A-Day #4 – Objective-C Flocking-Behaviors/Boid Class » Learning Iphone

    [...] actually didn’t work all that great, but, I came across SoulWire’s interpretation of Flocking (also in AS3), and I ported that. Maybe it was because it was my second attempt at porting, but this time I got [...]

  11. 5 years ago Boids « Matthias Oostrik

    [...] the future I’m inspired by this demo. The inputs are very understandable and easy to [...]

  12. 5 years ago Kinect Flash Tests - The Lawrie Cape Blog

    [...] Items move around the screen based on the depth levels from the camera. Based on Soulwire’s Flocking Experiment. [...]

  13. 5 years ago Paisaje Sonoro Interactivo

    [...] El vehículo se desarrolló a partir de la librería SteeredVehicle descrita en el libro Advanced ActionScript3 Animation de Keith Peters.  Puede encontrarse una librería similar en [...]

  1. Chris Dennett 5 years ago

    Lovely, really lovely. I was lost in the flock for 15 minutes, one of the shoal. Even when they turned on me it felt like home. Thank you very much for this, you’re a wonderful person.

    Reply to this comment

  2. shade 5 years ago

    this is a great library, thanks. fyi i’ve made a game using your library you can play it here

    Reply to this comment

1 3 4 5