You can see the basic of the flocking here (:
if (flock.proximity < boidDistance && boidDistance < flock.vision)
{
flock.acceleration = flock.position.Translation;
flock.acceleration -= flock[j].position.Translation;
flock.acceleration *= (boidDistance / -0.1f);
//If the acceleration is greater than the maxAcceleration allowed we normalize the vector in order to control the speed
if (flock.acceleration.Length() >= flock.maxAcceleration)
{
flock.acceleration.Normalize();
flock.acceleration *= flock.maxAcceleration;
}
//Adding the acceleration to the velocity.. well actually a Hyrda!, we multiply it!
flock.velocity *= Matrix.CreateTranslation(flock.acceleration);
}
and then I want them to attack some different targets, for directing them in the right direction I say
else if (!boundingSphere.Intersects(player.buildingList[1].boundingSphere))
{
behavior = Behavior.Flock;
vision = 50;
proximity = 15;
maxAcceleration = 0.008f;
acceleration = position.Translation;
acceleration -= Target;
acceleration *= (-0.0005f);
if (acceleration.Length() >= 0.003f)
{
acceleration.Normalize();
acceleration *= 0.003f;
}
velocity *= Matrix.CreateTranslation(acceleration);
}
Which is basically the same as before.. Now my real problem is when they reach their target their velocity is pretty high and they will pass fast through it and juggle back and forth like idiots ..
What I want is them to go to the buildings boundingsphere/box and do the stupid-bee thing ^^ you know hit its head against the window repeately .. any suggestions? Its really bugging me >_<