Overview
Let us watch a demo first.
Go to https://boids.rbtr.ee/ to see further.
As you can see, the Boids algorithm is a method to simulate the movements of social creatures.
Algorithm
The Boids algorithm is quite simple.
Each individual only needs to follow three rules.
- Separation.
To avoid collision, a force is applied between individuals that are too close. The closer they are, the stronger the force. - Alignment
To prevent individuals from drifting away, they tend to align with the average direction of their neighbors. - Cohesion
Individuals who are not at the center of the group tend to move toward the center.
Code
https://github.com/rbtre/Boids/