# 2d flocking theory

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

## Recommended Posts

I want to give 2d flocking behaviour a try. The three main rules are listed on wikipedia but I need some elaboration on the theory. If I understand wikipedia correctly I need to execute these three steps, in order, every frame. rule 1 - seperation Spring targets away from eachother if within a certain radius. rule 2 - alignment steer left/right towards avarage of total group direction/angle. rule 3 - cohesion steer left/right towards center of nearest neighbours. How do I influence the group direction? Do I need some sort of indipendant group leader to indicate the desired direction? Otherwise, wouldn't they just be flying straight to the eventual average of eachother? Meaby a step 0: to steer left/right towards target direction? And where does object avoidance behaviour fit into these rules?

##### Share on other sites
Short answer, you still need to give your boids something to do -- avoidance or seeking are most common.

Long answer, did you find Craig Reynold's site on Steering Behaviors?
http://www.red3d.com/cwr/steer/

He has code, an in-depth paper, and demos!

##### Share on other sites
I use a scoring algorithm for this where priorities are assigned to many different qualities of behaviour.

Each 'action' in a list of actions is scored (in this image, the boids are following the normal boid rules, as well as hunting for edges in the source image. The action list contains alterations of heading and propulsion; each action is run for a few simulation steps (seekahead) evaluated for score; then the actions are blended, based on their score.

It's a fun system, since you can evoke new behaviours by conceiving of new rules as long as they can be deterministically scored. I can make the boids match a cruising speed, avoid their neighbor's crusing speed, search for edges, search for specific colours, cluster to large groups, attempt to distribute evenly across the simulation field...

It's also cool because the underlying physics can be arbitrarily complex and the boids will still try to minimize their score within that system. Wind, gravity, obstacles etc. require very little modification to the boids themselves, since all they concern themselves with is heading and thrust. (The basic physical model I'm using is a circular object with a swiveling thruster)

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 9
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009388
• ### Who's Online (See full list)

There are no registered users currently online

×