Bird Flocking Behavior Algorithms
Run the Flock Simulator
Flocking / swarming behaviors are an example of emergent behaviors,
where complex global behavior can arise from the interaction of simple local rules.
In this example, the birds follow three simple rules that together cause the flock / swarm behavior.
- Separation: Steer to avoid crowding birds of the same color.
- Alignment: Steer towards the average heading of birds of the same color.
- Cohesion: Steer to move toward the average position of birds of the same color.
Each bird has a detection and separation range.
The applet program has the option of displaying or hiding the ranges.
The detection range is the distance at which birds can detect predators, obstacles, food and other birds.
The separation range is the distance at which a flock of birds might split up to avoid a predator, obstacle, or bird.
Until something falls within a birds detection range, it will not react to it.
Don't get confused by the overlapping circles in the example to the left.
It this example, the birds cannot see each other until the bird itself falls within the other birds detection circle.
Birds are repelled by birds of different colors and by obstacles.
The closer the bird, the greater the repel effect.
This causes birds to turn away from predators, obstacles, and different color birds.
In a flock of birds that are all the same color, each bird will try to match the direction
of the birds around it that it can detect.
If some of the birds in a flock detect an obstacle, they will turn.
This causes the rest of the flock that can't even detect the obstacle to also turn away from it.
Birds within a flock are attracted to each other as long as they are within the detection range, but outside the separation range.
This goal is to have the birds flock together, but not to be so close that they are on top of each other.
If there are too many birds in the flock, the separation range will need to be increased.
You can download this program here:
See a online video game designed using flocking behaviors
Boids - A space shooter where the enemies use flocking/swarming and avoidance behaviors.
Enemies will group together and attack without lining up in a straight line making them harder to kill.
In some of the later levels, the enemies will also dodge bullets similar to avoiding predators.
See some of the other AI projects on the site