Wednesday, July 18, 2012

Swarms Rule

I've been thinking a bit about what rules make a swarm look like a swarm. The three rules that boids follow, cohesion, alignment, and separation, make a nice flock, but a swarm isn't really the same as a flock. A swarm's parts moves around even when it is still, if may change shape at any time, and it more dynamic and less structured then a flock. So what rules do we need to produce swarm behavior?

First off, there appear to be more then one type of swarm, or at least more then one thing a swarm may be doing. A bait ball is a circle of beings all circling in the same direction and staying close together but not converging to a point. A large, mostly stable swarm may appear to grow limbs or briefly split. A moving swarm may be more like a flock then a standing one. Perhaps there are other forms we may wish to create that are swarmlike?

So, the rules. A standing swarm that does not change shape seems to need only two rules- move randomly and stay inside a sphere. Luckily these are both O(n) time operations for a swarm of size n, so we can get away with an efficient little swarm if we allow individuals to move through each other. To get the shape changing effect I would guess we could create invisible attractive or repulsive forces and move them around, orbiting the center of the swarm and possibly reversing their effect occasionally. Another possibility is temporary leaders, either with new rules or with the same rules as others, that are followed by close by individuals. Another possibility is that individuals always sort of follow each other but the strength of that influence varies.

For a bait ball I would guess we would need separation from a central point, random movement, and a strong need for alignment. I'm not sure if this is enough, but I imagine the alignment would keep them in check and the random movement (possibly also a need to move forward) would keep them circling.

Finally the flocking behavior of a moving swarm may simply be the above standing swarm rules with a force pulling the individuals to a certain location. This may be enough to create a nice looking moving swarm.

Thats all I can think of for now. Any thoughts? Other types of swarms? Other rule sets that seem plausible?

4 comments:

  1. Here is a thought- the swarms are following a goal object, right? What if the goal object where not a single objects, but a series of goal objects which themselves swarm around a deeper, single goal object. Parts of the swarm would be assigned to each swarming goal object, which would give an organic feel. Also, the goal object might has a part to play in determining swarming behavior, such that a part of the swarm may form an arm or something because it is following different rules than the others. What do you think?

    ReplyDelete
  2. As far as following the leaders, it could be that the MSG that is closest to the goal would be designated as a leader, and there would be at least a small weight on following it. I think that this would point the swarm a bit, which would look cool.

    ReplyDelete
  3. Hey guys,
    I think I remember some of our AI class talking about swarms. I believe they can converge on a point or always be following a leader. In the games that I have seen before with this type of behavior there is a seeking action, and upon reaching the "seeked" object there is another behavior. I'm not sure how your game works and what not, but I would assume you would want to have some type of leading force for the flock. Sounds cool all the same.
    -Andrew

    ReplyDelete
  4. Ah I forgot to mention, if you guys are interested I just started my own blog http://computerbitsandbytes.blogspot.com/ check it out when you get a chance. Figured I'd start writing about some stuff that I'm learning as well. Feel free to drop a comment, I think you can "guest post" but I'm not sure how to do that on Blogger yet.
    -Andrew

    ReplyDelete