Writing Crowd Behavior Plug-ins
 
 
 

A crowd behavior plug-in for character studio inherits from the BaseBehavior class found in bhvr.h. A behavior plug-in has a super class of BEHAVIOR_SUPER_CLASS_ID exists in the 3ds Max plug-in directory. The 3ds Max crowd system uses the super class id to find the plug-in as an available behavior.

There are three basic kind of behaviors: force, constraint, and orientation. The type of behavior is queried using the function BaseBehavior::BehaviorType().

Before writing a behavior plug-in it is important to understand the basic algorithm used by the crowd system during a simulation. This algorithm is performed for each delegate each frame. The crowd system always computes on a frame by frame basis, not ticks.

  1. All of the force vectors and speeds for a delegate are gotten from its active force behaviors by calling the plug-ins BaseBehavior::Perform() function.
  2. Based upon the delegate's motion parameters, these force vectors and speeds are averaged and integrated to compute a velocity for the delegate.
  3. This velocity may then be modified, if the delegate has an active constraint behavior, by calling the behavior's BaseBehavior::Constrain() function.
  4. The velocity may then be modified if the delegate has an active avoidance behavior.
  5. After the velocity is set, if there is an active orientation behavior, it is used to set the orientation of the delegate by calling the behavior's BaseBehavior::Orient() function. Otherwise the orientation is calculated from the default delegate parameters.
  6. Finally, the velocity is integrated and a new position is calculated.

The new position of the delegate isn't set until after all of the forces are calculated for all of the behaviors and all of the delegates.

For a biped crowd, bipeds use goals and not forces to determine which direction they should go in. In order to create a force behavior that will work with a biped, a goal position must be specified. The movement of the biped is then determined by using the goal to select clips found in the motion flow graph.