# flocking and formations

This topic is 4341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to make large groups of units move using flocking (swarming) behavior. But if I do that, how can I make the units move in formations like the delta that birds do? Thanks.

##### Share on other sites
By applying constraints to their local positioning rules. A formation such as a flying 'V' that some breeds of birds use is a 'follow the leader' formation. Each bird is basically trying to position the leader behind the bird that is next closest to the leader than them. Their cone of vision would prevent them from flying in a perfect line and being able to quickly react to position changes (hence the lagged V formation).

Other formations can be created in a similar fashion; find a set of local constraints that give a global behaviour when all individuals satisfy the constraint.

##### Share on other sites
Thanks, I just don't understand how their "cone of vision" prevents them from flying in a straight line? And how do you implement it?
Thanks.

##### Share on other sites

As for you you can implement this in simulation? Well, there would be several ways I can think of. I'll leave the details of implementation up to you (I don't have a lot of time at the moment to write up a detailed explanation), but you should be considering how each unit in the formation can represent and maintain its alignment to a given vector (that formed by the line between the unit next closest to the leader and the leader themself). You'll want each unit to choose its actions so as to minimise errors in alignment and separation. One method to do this would be to implement a fuzzy control system, for which you can find a wealth of information online and in a variety of game AI books.

Cheers,

Timkin

##### Share on other sites
Quote:
 Original post by TimkinBy applying constraints to their local positioning rules. A formation such as a flying 'V' that some breeds of birds use is a 'follow the leader' formation. Each bird is basically trying to position the leader behind the bird that is next closest to the leader than them. Their cone of vision would prevent them from flying in a perfect line and being able to quickly react to position changes (hence the lagged V formation).Other formations can be created in a similar fashion; find a set of local constraints that give a global behaviour when all individuals satisfy the constraint.

This is an interesting idea, but I'm not sure I follow what you mean by "position the leader behind the bird that is next closest to the leader than them". If the idea is that they want to have a clear view of any changes in heading the leader makes, why not fly in a perfect line the other way? That is, all in a single file line, the leader in front. Most birds would not see the leader when flying straight, but if the leader were to veer at all, each bird could immediately see that and adjust course.

##### Share on other sites
Quote:
 Original post by timford why not fly in a perfect line the other way? That is, all in a single file line, the leader in front. Most birds would not see the leader when flying straight, but if the leader were to veer at all, each bird could immediately see that and adjust course.

Birds have eyes on the sides of their heads, not the front like humans do.
they see better to the left and to the right than straight ahead
in fact with many birds there is a blind spot right in front, ever notice when feeding pidgeons in the park that they turn their heads a lot and give you lots of sideways glances?

they evolved that way since even though straight ahead is blind, they have excellent vision to the sides and rear in huge arcs... important for dogfighting

##### Share on other sites
hello, im AP above...

additionally, they fly this way for aerodynaic reasons...

http://www.aerospaceweb.org/question/nature/q0237.shtml

##### Share on other sites
Quote:
 Original post by timfordThis is an interesting idea, but I'm not sure I follow what you mean by "position the leader behind the bird that is next closest to the leader than them".

Draw a line from the leader to the bird next closest to the leader than the one you are considering. So...
                              L                        X                  X           B     A

L is the leader, A is the bird under consideration, B is the next closest to the leader from A. Draw a line from L to B. For optimal positioning, assume that A wants to stay on that line at a given distance from B. L will appear to be behind B from A's perspective.

As for the leader changing direction or speed, this will affect its position 'behind' B (as A looks at it) and will affect A's flight direction and speed. The bird X closest to L has the responsibility of staying in the correct position relative to the leader and their actions will have a ripple effect down the line.

##### Share on other sites
There's still something that I don't understand, does A look fo the next closest out of all of the birds, or just out of the ones next to him?
Thanks.

##### Share on other sites
A looks for B, which is the closest bird to itself in the direction of L. L is the furthest bird from A in the direction of B. One of these two constraints must be fixed (they're circular), so fix the leader and make it so that each bird knows who the leader is.

##### Share on other sites
but in real life bird dont elect a leader before taking flight ;)

Its been a while since i played with flocking, but i think the for a wedge formation, birds look for the closest bird in front, and try to position themselfs to the back/side of them. If there are no birds in front of you, then you're on your own (or maybe there's birds following you!) so just do your own thing, untill someone happens to be in front of you.
The basic'forces' involved in flocking are (as i remember..) :
trying to match your speed with the speed of others around you, trying to position yourself away from others (to an optimal distance) and trying to position yourself at the average position of the flock. - these balance out into a formation. Other forces, such as keeping at an angle to others in the flock (as mentioned above) can be added to change the form of the formation.

##### Share on other sites
http://www.red3d.com/cwr/boids/

This guy is where i originally got my info, so listen to him more than my ramblings above ;)

I used his techniqes in a Half-Life teamplay bot, and it worked pretty well for squad-based exploration without specific directions ;)

##### Share on other sites
Quote:
 Original post by Anonymous Posterbut in real life bird dont elect a leader before taking flight ;)

Game AI isn't about simulating real world entities... it's about making things 'look' like real world entities (or at least entities that are natural in the world you define for them).

Furthermore, flocking behaviours such as boids are not simulations of how real animals move in flocks... but they do show us that animals that move in flocks need only simple local rules to achieve coordinated behaviours.

If you want to simulate how real birds fly in a V, go and talk to some biologists. If you want to create your own behaviours in the style of boids, then you can get away with whatever you like that gets you to the result you desire.

Cheers,

Timkin