# Flocking

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

## Recommended Posts

hi, I am trying to implement flocking of birds. I used C.Reynolds concept to get it done but it is having some problem. The way I implemented it is: 1) Cohesion - In a for loop I took each bird at a time and calculated the average distance. Like Vector3f centre = 0; centre += Bird{i].Getposition(); //then centre = centre/Total_Number_birds; Vector3f value = centre - Bird[].GetPosition();//Takes the bird for which we are considering the cohesion value.normalise(); Then normalised 'value' is returned which is added to the velocity of the bird. 2) Alignment - Its also done in the same way except that in place of position the velocity is taken. 3) Seperation - Here a minimal distance is fixed for which each bird so that they are not colliding with each other. like float min_dit = 2.0f; if( TargetBird.Position() - EachBird.Position() < min_dist) { difference = TargetBird.Position() - EachBird.Position(); move_bird += difference; } then mov_bird /= Total_Number_Birds; mov_bird -= TargetBird.Position(); mov_bird.nomalise(); we return the value 'mov_bird' Is this the right way to get all the 3 values? What is happening is that all the bird are merging together after few seconds . Let me know the exact procedure of calculating all the three values. All suggestions are welcome

##### Share on other sites
from the description of your problem it sounds like the separation property isn't being implemented properly.

you should use an average for cohesion and alignment, but just use the position of the actual closest bird for separation. I just implemented flocking for a class recently, I'd give you my code if I had a place I could upload it to.

[Edited by - Bobboau on March 22, 2010 1:07:09 AM]

##### Share on other sites
Quote:
 Original post by Bobboaufrom the description of your problem it sounds like the separation property isn't being implemented properly.you should use an average for cohesion and alignment, but just use the position of the actual closest bird for separation. I just implemented flocking for a class recently, I'd give you my code if I had a place I could upload it to.

Hi,
You can send a PM to me if possible.

##### Share on other sites
Quote:
 Original post by marcus12hi, I am trying to implement flocking of birds. I used C.Reynolds conceptto get it done but it is having some problem. The way I implemented it is:1) Cohesion - In a for loop I took each bird at a time and calculated the average distance. Like Vector3f centre = 0;centre += Bird{i].Getposition(); //then centre = centre/Total_Number_birds;Vector3f value = centre - Bird[].GetPosition();//Takes the bird for which we are considering the cohesionvalue.normalise();Then normalised 'value' is returned which is added to the velocity of the bird.2) Alignment - Its also done in the same way except that in place of position the velocity is taken.3) Seperation - Here a minimal distance is fixed for which each bird so that they are not colliding with each other.like float min_dit = 2.0f;if( TargetBird.Position() - EachBird.Position() < min_dist){ difference = TargetBird.Position() - EachBird.Position(); move_bird += difference;}then mov_bird /= Total_Number_Birds; mov_bird -= TargetBird.Position(); mov_bird.nomalise();we return the value 'mov_bird'Is this the right way to get all the 3 values? What is happening is that all the bird are merging together after few seconds .Let me know the exact procedure of calculating all the three values.All suggestions are welcome

Hi,
Can anyone suggest what kind of changes I should do in the above algorithm.
All suggestions are welcome

##### Share on other sites
I rate you up for hinting my over to the fact that there's research material on simulated flocks :D

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001833
×