Applying Avoidance
 
 
 

In the previous lesson, you might have noticed that the delegates penetrated each other when they were close to the box. In this lesson, you'll learn to use the Avoid behavior to prevent delegates from colliding. You'll also learn to apply a second "desired direction" behavior to the Seek team and animate the behaviors' influences.

Set up the lesson:

Add the Avoid behavior:

  1. Select the Crowd object.
  2. Add an Avoid Behavior.

    Like Seek and Repel, the Avoid behavior has a button for specifying a single object to avoid. But in this case, you want to specify several Avoid objects, so you use the Multiple Selection button.

  3. On the Avoid Behavior rollout, click Multiple Selection.
  4. Highlight all objects (the delegates and the box), and click Select.
  5. Use the Behavior Assignment dialog to apply the Avoid behavior to the Seek team.

    When you click New Assignment, the Avoid behavior appears in the assignments list above the Seek behavior. That's because the list is sorted alphabetically, starting with the leftmost column. By default, all behaviors are applied simultaneously, so when you solve, both the Seek and Avoid behaviors are applied to the Seek team at each frame.

  6. Solve the simulation.

    For the most part, the delegates now stay far away from each other and the target box.

Use visual cues:

You can get a better idea of how Avoid works by turning on its various feedback options. These give visual cues for distance-related settings and activities.

  1. On the Avoid Behavior rollout, turn on Display Hard Radius and Display Repel Radius.

    Wireframe spheres appear around the delegates, showing the respective radii.

  2. Turn off Display Hard Radius and Display Repel Radius to avoid an overly complex display.
  3. On the Avoid Behavior rollout > Display During Solve group, turn on Potential Collisions, Repel Activity, and Look Ahead Radius.
  4. Solve again.

    During the solution, white lines appear indicating Potential Collisions detection; colored lines indicate Repel Activity calculations, and spheres indicate Look Ahead radii. The latter are available only during solution, because the distance must be computed from the Look Ahead setting and the delegate's current velocity.

Adjust the behavior:

The delegates give each other a wide berth because the Look Ahead setting, which tells delegates how many frames to look ahead for potential collisions before turning to avoid each other, is set to the fairly large default value of 30. The delegates can get closer to each other if you reduce this amount.

  1. On the Avoid Behavior rollout, set Look Ahead to 3.
  2. Solve the simulation.

    This time the Seek Team delegates don't stay quite so far apart. In fact, you might see some interpenetration, because the small Look Ahead setting doesn't give them enough to time to start turning to avoid each other. The best settings for Avoid, as with most other behaviors and Crowd settings, depend on the situation, and finding them usually takes trial and error.

Change the behavior:

Next, you'll make the delegates stop seeking the box and start moving away when they reach it. You can do this by assigning the existing Repel behavior to the Seek team and activating it at the proper frame while simultaneously deactivating the Seek behavior.

First, examine the animation to determine when to change the behaviors.

  1. Move the time slider back and forth to find frame where the delegates come closest to the box.

    Choose frame 70, or a frame near frame 70.

  2. Move the time slider back to frame 0. Turn on the Auto Key button.
  3. Open the Behavior Assignments dialog, and assign the Repel behavior to the Seek team.
  4. In the Behavior Assignments list, click the Seek Team Repel Behavior item.

    The corresponding items in the Assignment Design group are highlighted, and the controls at the bottom of the Behavior Assignments group become available.

  5. At the bottom of the Behavior Assignments group, turn off Active.

    The X next to the assignment in the list disappears, indicating that the assignment is inactive. This setting is animatable, so you can directly control which assignments are active on a frame-by-frame basis throughout the animation.

  6. Drag the time slider to frame 70.
  7. Turn on Active for the Seek Team Repel Behavior assignment. Then choose the Seek Team Seek Behavior assignment, and turn off Active.
  8. Drag the time slider back and forth to either side of frame 70 and watch the Behavior Assignments list.

    At the same time that the Repel behavior turns on, the Seek behavior turns off.

  9. Close the dialog, and turn off Auto Key.
  10. Solve the simulation.

    At frame 70, the delegates stop seeking the box, turn abruptly, and begin to move away.

    For a more gradual change, you can animate the Weight setting. This controls the relative influence of the behavior over the delegates, and ranges from 0 to 1.0.

Next

Applying Logic to Crowd Behavior