Creating a simple flocking system with particles and fields:

Flockingsystems has become quite popular, its ability to recreate the movement of large numbers of entities can relieve animators of much tedious work.

Programming a simple flockingsystem is not too bad, basically you give the entities simple behaviours lik 'dont bump into eachother', 'follow the leader' etc. when you then combine these behaviours its when it starts to get interesting.

Maya's very well equipped dynamics/particles system can be used to recreate the behaviours:

Ill here explain the setup of a system of particles that move about on the ground (a deformed NURBs plane), trying to follow a leader, making sure they dont bump into eachother, and that they dont come too close to the leader. The file at the end of this document contains the resulting scene.
 

We need a crowd

First create the paricles, I usually use the particleTool to draw them where I want them.

Then lets make sure they dont bump into eachother:
select the particles and create a radial field, turn on 'use max distance' and set it to something that fits the size of your scene, turn on 'apply per vertex', and finally set the magnitude so that they make sure they dont come too close (trial and error is key)
Now attach the field to the particle system, the combination of this and the 'apply per vertex' will cause each particle to 'have a radial field' that pushes away other particles.
This system of having particles affect themselves is what makes the whole thing work.

So now you should have a system where the particles try to stay away from eachother, one problem though is that once they get started moving, they dont stop.
There is two solutions for this, either create a dragfield, or turn down the particles 'conserve' value so that they loose speed.

The result should be a system where once the particles get far enough apart, the movement will die out.
 

In comes the leader

To stir up things we will introduse 'the leader', I like to use a combination of a newtonfield and a radialfield, but its up to you.

Select the particles, create a newton field. This will attract the particles, actually the result is something close to the 'swarm' screensaver.
But theres a problem, the followers are trampeling down the leader, not really a nice thing to do ;)
So create a radial field at the same spot, and setup maxdistance etc. like the first one, this will make sure that they  dont get too close.
 

Thats basically it..

If like in the demofile yo want it to happen on the ground:
Make the ground (plane?) collide with the particles, set the resilience to the particles to a low value, otherwise they will go bouncing around.
Select the particles and create a gravity field.

Also it might be a good idea to geometry constrain the 'leader-group' to the ground aswell.
 

Instancing

Now you can instance you object-of-choice to the particles
You can also setup hov your objects should align, the most useful are velocity, and accleration, that means either face the way you are moving, or face the way you want to move ;)
 

************Workaround exist**********************
************Ill post it later*************************
One really annoying problem with the current instancer is that there is no way to randomize animation on a perparticle/instance basis so all instanced geometry on a particle system will move in sync..
So you will need to go through the tedious process of creating multiple systems, make them cross-affect eachother, and instance them with objects with a time-offset.
A|W please fix this!!!
*************************************************

Other collisions

You can create other objects to make the flock collide with walls etc.
But you will need to use proxy collisionobjects since otherwise the instanced geometry will go through walls etc. because the particles ar infinately small but the instanced geometry is not.
 

Final note

You will most certainly have to tryout different field settings, and magnitude values to get things to work the way you want.

Also the new volumefields, can add a lot of control.
 
 
 

simple_flockingsystem.mb