Sign in to follow this  
marcus12

Flocking

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[i].Position() < min_dist) { difference = TargetBird.Position() - EachBird[i].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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Bobboau
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.


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

Share this post


Link to post
Share on other sites
Quote:
Original post by marcus12
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[i].Position() < min_dist)
{
difference = TargetBird.Position() - EachBird[i].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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this