Flocking Autonomous Agents


Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

In the previous chapter, the desired vector pointed straight towards a random point. However, in order to display flocking behaviour, the boids must be aware of each other.


We will add three rules to our boids to dictate their decision-making, as defined by Craig Reynolds in his paper on flocking.

Each rule will provide the boid with a different steering force. We can then calculate the average of these forces and use it for the boid's acceleration.

💡 Any number of rules can be added, such as wind, the desire to explore randomly, etc. Each resulting force can be weighted differently for the boid's final decision.


We find a vector which points away from nearby boids.


We use the average velocity of the other boids.


We find a vector which points towards the average position of the other boids.

Alignment and cohesion illustrate how the individuals will "cooperate". Separation, illustrates how the individuals will "compete" for space. It is this tug-of-war between competition and cooperation which will give our system its complexity.


The rules above can be implemented in such a way that every boid is aware of every other boid, creating a system with one great hive-mind. However, our boids are autonomous agents, they may only take a decision based on their local environment.

For each boid, we will calculate the distance to every other boid, then if that distance is lower than a chosen constant, we calculate the three forces above, then use the sum of the three to calculate the boid's acceleration. Each force can be weighted differently, which can fundamentally change how the boids move.


You can try moving the constants around or implement the three rules differently to see how your boids react now.


👁 The boids grew some eyeballs to percieve the environment with. 👁

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content