These guys above are way fun to play with! (those of you in an RSS reader will probably have to click through.) Click on the stage for more boids.
I started this project with Phil a while back and have decided to stop working on it, at least for now. Ichigo was my introduction to programming in Actionscript 3.0 but also turned out to be my introduction to boid theory. Every boid above has several forces that influence its interactions, including:
- alignment: heading towards the mouse cursor
- cohesion: heading towards the center of the flock
- separation: maintaining ample distance from flockmates
- steerResistance: momentum that provides resistance to turning or stopping
- randomness: some slight randomization of their movements
One of the trickier bits during the process was telling the boids which direction to face. Simply pointing them in the direction of their velocity vector resulted in boids that could instantaneously flip their faces from back to front or left to right. Not only did we end up interpolating the sprite's rotation, but we also programmed each boid so it begins to turn only if its new velocity vector is at least theta degrees away from its old velocity vector. This last adjustment resulted in more flock-like and fish-like behavior.
The public build is here, and the source code is of course up on github if you're curious.