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
Controller editor, a flowchart-style editor
(much like the
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
You can find procedures
describing various examples of cognitive-controller transitions
State Dialog topic:
a particle system parameter
an object position
an atmospheric property
the distance between two objects
a modifier parameter
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
Helper Object and
- Create a scene containing a crowd object
and one or more delegates. See
Creating Crowd Helpers.
- Create at least two behaviors. See
- Click the New button to create a cognitive
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.
a new cognitive controller automatically places you in Create State
- Click in the editor window to create
and place a state. Continue clicking in different places to add
as many states as necessary.
- Right-click a state to open the
- Again, it's recommended that you give
more descriptive names to states, which you can do in the State
dialog. Click the name (State or State#) in the text box and edit
it from the keyboard.
Next, define a behavior or behaviors for each state.
- Click the Add button.
- In the Select Behaviors dialog, choose
one or more behaviors.
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.
- Close the Select Behaviors dialog, and
then close the State editor.
- Repeat steps 6–10 as necessary to define
behaviors for the other states in the controller.
Next, use Create Transition to define the sequence
of states during the simulation.
- Decide on the sequence in which the states
are to occur.
- Click (Create
- Drag a line from one state to the next
in the order that they are to execute. Click a state to create a
transition from itself to itself.
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.
- Right-click a transition line.
- In the
Transition dialog, enter the name of the
transition condition, and then click the Edit MAXScript button.
- Use the MAXScript editor window to enter
or load a script that defines the condition or conditions under
which the transition is to occur.
Typically, this is a function that tests a condition
and returns 1 (if true) or 0 (if false).
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
- fn - What follows is a MAXScript function.
- test1 - The function name; this should
also appear in the Transition dialog, as the transition condition.
This function is executed first when the transition is tested. The
script may contain any number of additional functions to be called
from within a function in the script.
- del - Refers to the delegate to which
the script is currently being applied. The transition script is
executed once per frame for each delegate/team member the cognitive
controller is assigned to. Thus, if you use "del" in the script
rather than the name of a specific delegate, all delegates to which
the cognitive controller is assigned are tested.
- t - The current time (frame number) in
- del.simpos.x - The delegate's current
position on the X-axis. The special function "simpos" is used to
determine a delegate position during a simulation solution. This
is necessary because delegate positions aren't available to MAXScript
using the standard "[node].pos" function during a simulation.
- del.duration - The number of frames the
delegate has been in the current state.
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 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
- Use the State Transition dialog to set
other parameters such as priority and duration.
- Use the
and Teams dialog to assign the cognitive
controller to delegates or teams.
NoteCrowd doesn't let you use multiple cognitive
controllers with a delegate. You can assign them, but when you solve, character
studio notifies you that it will use only the first assigned cognitive