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:
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.
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.
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.
Wireframe spheres appear around the delegates, showing the respective radii.
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.
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.
Choose frame 70, or a frame near frame 70.
The corresponding items in the Assignment Design group are highlighted, and the controls at the bottom of the Behavior Assignments group become available.
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.
At the same time that the Repel behavior turns on, the Seek behavior turns off.
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.