Cognitive Controllers
 
 
 

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 object position

Testing an atmospheric property

Testing the distance between two objects

Testing a modifier parameter

Testing another delegate's behavior

Procedures

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.

  1. Create a scene containing a crowd object and one or more delegates. See Creating Crowd Helpers.
  2. Create at least two behaviors. See Assigning Behaviors.
  3. Open the Cognitive Controller Editor .
  4. Click the New button to create a cognitive controller.

    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.

  5. Click in the editor window to create and place a state. Continue clicking in different places to add as many states as necessary.
  6. Right-click a state to open the State Dialog.
  7. 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.

  8. Click the Add button.
  9. 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.

  10. Close the Select Behaviors dialog, and then close the State editor.
  11. 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.

  12. Decide on the sequence in which the states are to occur.
  13. Click (Create Transition).
  14. 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.

  15. Right-click a transition line.
  16. In the State Transition Dialog, enter the name of the transition condition, and then click the Edit MAXScript button.
  17. 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).

    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:

    • 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 the simulation.
    • 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 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.

  18. Use the State Transition dialog to set other parameters such as priority and duration.
  19. Use the Behavior Assignments 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 controller.
See Also