You can use the cognitive controller feature to cause crowd members to change behaviors during a simulation, depending on the circumstances. For example, a character could wander randomly until it comes within a certain distance of a target, at which point it could head straight for the target.
In technical terms, cognitive controllers let you influence crowd simulations with scripted conditionals, effectively implementing a form of artificial intelligence. You use the Cognitive Controller Editor, a flowchart-style editor (much like the Motion Flow Graph dialog) to set up a network of behaviors and behavior combinations, known as states. Then you then apply MAXScript-based transitions that specify when delegates are to move from one state to another. Even with a relatively simple setup, you can create simulations that make your characters appear to be living, conscious beings, making decisions as they move through the scene.
You can find procedures describing various examples of cognitive-controller transitions in the State Dialog topic:
Testing a particle system parameter
Testing an atmospheric property
Testing the distance between two objects
Testing another delegate's behavior
To set up and use a cognitive controller:
This procedure describes a typical setup routine for creating and using a cognitive controller. The procedure assumes basic knowledge of crowd simulation setup. For more information about crowd setup, see Crowd Helper Object and Setup Rollout.
character studio gives the controller the default name of “Cognitive Controller.” It's recommended that you give more descriptive names to cognitive controllers, such as "Seek/Wander". Do this by clicking on the name in the text box and editing it from the keyboard.
Creating a new cognitive controller automatically places you in Create State mode.
Next, define a behavior or behaviors for each state.
If you choose multiple behaviors, you can specify different weights for each in the State editor. For example, you can combine a Seek behavior at full weight with a Wander behavior at half weight, so that the delegate will meander slightly as it seeks the target.
Next, use Create Transition to define the sequence of states during the simulation.
A transition arrow appears, pointing from the "source" state to the "destination" state.
Each state can have any number of incoming and outgoing transitions. Specify different transition conditions for each to create as complex a state diagram as necessary.
Next, use the State Transition dialog to define a conditional for each transition.
Typically, this is a function that tests a condition and returns 1 (if true) or 0 (if false).
For example:
fn test1 del t = ( if (del.simpos.x <= 40 and del.duration > 50) then 1 else 0 )
In plain English, the above statement says that if the delegate's position on the X axis is less than or equal to 40, and it has been in the current state for more than 50 frames, then the transition should occur. However, if either condition is false, or both are, then the delegate should stay in the current state (or test any other transitions). Following is a list of its keywords:
You can see a complete list of delegate-specific parameters that can be checked in the script by opening a MAXScript Listener window (press function key F11) and entering:
ShowProperties $delegate01
And because the delegate is a node, it also responds to standard MAXScript node-related functions, with the exception of "simpos," as noted above. Also, for information on how to access the transition properties, such as duration and priority, see the MAXScript Help.
For more examples of MAXScript conditionals that can be used with cognitive controllers, see State Transition Dialog.