Tutorial 8: Working with Crowd Animation
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.
Adding the Avoid behavior
Load the file you saved at the end of the previous lesson. Or, if you like, load the file cs_tut08_lesson3.max from the cstudio\tutorials\tutorial_8 directory, in your 3DS MAX path.
Select the crowd object.
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.
In the Avoid Behavior rollout, click Multiple Selection.
Highlight all objects (the delegates and the box) and click Select.
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. All behaviors are applied simultaneously, unless you animate their Active status, so when you solve, both the Seek and Avoid behaviors are applied to the Seek team at each frame.
Solve the simulation.
For the most part, the delegates now stay far away from each other and the target box.
Using 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.
In the Avoid Behavior rollout, turn on Display Hard Radius and Display Repel Radius.
Wireframe spheres appear around the delegates showing the respective radii.
Turn off Display Hard Radius and Display Repel Radius to avoid an overly complex display.
In the Avoid Behavior rollout > Display During Solve group, turn on Potential Collisions, Repel Activity, and Look Ahead Radius.
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.
Adjusting 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 will get closer to each other if you reduce this amount.
Set Look Ahead to 3.
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.
Changing 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.
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.
Move the time slider back to frame 0 and turn on the Animate button.
Open the Behavior Assignments dialog and assign the Repel behavior to the Seek team.
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.
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.
Drag the time slider to frame 70.
Turn on Active for the Seek Team Repel Behavior assignment, and then choose the Seek Team Seek Behavior assignment, and turn off Active.
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.
Close the dialog and turn off Animate.
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.
Lesson 4: Applying Logic to Crowd Behavior