Boids

Image

A demonstration of the Boids concept, each of the coloured spheres in this Space follow simple rules that produce complex behaviours.

Download the Boids Space.

Each of the coloured spheres is a physics shape. The controlling script (implemented in Python) cycles through the present Boids, calculates a vector based on the applicable rules, and applys this vector as a force to the physics body.

The basic Boid rules are:

 

  • Move towards the midpoint of your neighbours
  • Avoid colliding with your immediate neighbours
  • Move in the same direction as your neighbours

Each colour represents a variation on the rules being followed:

  • Black - These boids only consider their neigbour to include those within a specified radius. Thus they usually end off on their own, circling the limit of the space, or one or two will mix in with other groups and act as one of them.
  • Blue - These boids consider all the Boids in the scene to be their neighbours. This causes them to swirl around in the middle of all the other groups.
  • Green (on ground) - These Boids have an additional rule, that causes them to be attracted to the center of the space.
  • Red - These boids are like the green Boids, except they are attracted to the current position of the large orange sphere.
  • Yellow - Like the Red boids, they are attracted to the large sphere, but once they cross a certain threshold, they are repelled by it. This causes an effectively 'shy' behaviour, where they will come up to, then move away from the large sphere. But if they approach in large enough numbers, or with other boids, the rule to follow their neighbours will overpower the repulsion of the large sphere, and they will come closer and past.
  • Green (airborn) - These Boids ignore gravity, and apply their motion forces in three dimensions. They are also attracted to a randomly selected point in space, which changes every 60 seconds. This causes a very swarm like behaviour.