Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flocking and surrounding instead of moving away?

Are there any examples of flocking where the flock surrounds and engages the target instead of a fish like feeding frenzy where they swoop in then fly away?

I'm working on an overhead shooter and I want the pack of melee enemies to rush the enemy and surround him and keep attacking while more file in behind. I'm trying to avoid them all bunching up on one spot and flocking seems perfect but all the "move to target" examples have them move at the target then move away immediately afterwards.

Ideas?

like image 577
Charles Whopner Avatar asked Jan 22 '26 18:01

Charles Whopner


1 Answers

As I understand it, generic flocking is generated by a weighted-average of:

  • an alignment vector, which is an average of the alignment vectors of those around you
  • a separation vector, which is a vector pointing away from those around you
  • a cohesion vector, which is a vector pointing towards the local group center

There are different ways to calculating these vectors and different behaviours result when they are given different weights. There are also different ways of combining the combined, weighted-average vector with the current velocity vector.

If I read your question correctly, you would like your flock to circle or flit around a central point. To do this, you've created a fourth vector, which is

  • a target vector, which is a vector pointed towards a particular destination point

Now, you can probably see where this is going... the behaviour of your flock is the result of the weights placed on each vector. If the weight you've placed on the target vector is too small relative the others, your flock will be focusing on flocking instead of attacking.

Therefore, assuming I've outlined flocking correctly, and you've programmed things in a reasonable way, you'll be wanting to try different combinations of weights until you find a behaviour that suits your needs.

like image 102
Richard Avatar answered Jan 24 '26 09:01

Richard