Tutorial 8: Working with Crowd Animation

Lesson 7: Advanced Crowd/Bipeds

To create sophisticated crowd behavior using bipeds, you need to use a motion flow graph with multiple motion clips. In this lesson, you'll set up a graph that allows branching behavior, with most of the clips able to transition to several other clips. As it solves the simulation, Crowd will use motion synthesis to apply to each biped the clips that make the most sense in the context of the scene setup.

Here's the premise for this lesson: Two rival mini-gangs, the Tough Cookies and the Milquetoasts, meet in a face-to-face showdown. Each wants to get to a goal behind its adversaries. The Tough Cookies, whose members brook no interference, charge straight ahead to get to their goal. But the Milquetoasts, being a timid, fearful bunch, will have to make way for Tough Cookies before they can reach their own goal.

As preparation for doing this lesson, please read Attaching Bipeds to Crowd Delegates. The topic contains important background information for understanding the methods Crowd uses to when solving simulations with bipeds.

Initial Setup

  1. Load the file cs_tut08_lesson7.max in the cstudio\tutorials\tutorial_8 directory, in your 3DS MAX path.

    This file contains the delegates and target objects for both gangs, plus the Crowd helper object with team and behavior assignments already made. In the Top viewport, the Tough Cookies stand shoulder to shoulder (figuratively speaking) at the bottom, while the Milquetoasts are more loosely arrayed at the top.

    Take a look at the basic Crowd setup.

  2. Select the Crowd object and open the Modify panel.

  3. In the Setup rollout, click the Behavior Assignments button.

    The ToughCookies team contains delegates 1-3 and is assigned the Seek Green behavior, while the Milquetoasts team, with delegates 4-6, is assigned the Seek Red behavior. A third team, containing all six delegates, is assigned an Avoid behavior whose targets are all six delegates and the spheres.

  4. Close the Behavior Assignments and Teams dialog.

  5. Solve the simulation. When the delegates come near their goals, press Esc to halt the solution.

    The two teams head toward their respective targets while the delegates avoid each other, much as you'd expect.

Adding bipeds and associating them with the delegates

  1. In the Perspective viewport, add a Biped about 80 units in height.

  2. Use Shift-Move to clone the biped. When prompted for Number of Copies, enter 5.

    You end up with six bipeds.

  3. Select the Crowd object.

  4. Click the Biped/Delegate Associations button in the Setup rollout.

  5. Beneath the Bipeds list, click the Add button.

  6. In the Select dialog, click the All button, and then click Select.

  7. Beneath the Delegates list, click the Add button.

  8. In the Select dialog, click the All button, and then click Select.

  9. Click the Associate button to connect the bipeds and the delegates.

    Note: When using delegates with bipeds, none of the settings in the delegates' Motion Parameters rollout, except those in the Biped group, have any effect in the simulation.

Setting up a shared motion flow

You'll set up a motion flow graph that they'll all share, also known as a shared motion flow. When solving a simulation with delegate-controlled bipeds, Crowd uses this graph to synthesize motion flow scripts for the bipeds. The motion is shared, but Crowd typically generates a unique script for each biped, depending on the behaviors influencing its delegate. This process is motion synthesis.

  1. Select any part of one of the bipeds, and go to the Motion panel.

  2. Click the Motion Flow Mode button.

  3. Click the Show Graph button.

    As a first step in creating the motion flow graph, you'll add all the necessary clips.

  4. On the Motion Flow Graph dialog toolbar, click the Create Multiple Clips button.

  5. Navigate to the cstudio\tutorials\tutorial_8 directory in your 3DS MAX path, and load the following files (you can select multiple files in the Open dialog by using SHIFT+click and CTRL+click):

  6. If you like, use the Move Clip tool to rearrange the clips in the graph.

    Tip: The arrangement is arbitrary, but in this case a roughly circular arrangement with walk in the center seems to work well with this type of graph.

Creating a motion flow network

You'll create a motion flow network by adding transitions between pairs of clips. Think about which clips might logically lead to other clips. For instance, it makes sense to create a transition from walk to walk_L90, but not from walk_stop to itself.

  1. On the Motion Flow Graph dialog toolbar, click the Create Transition button.

  2. Start by clicking the walk clip so that it loops back to itself.

    The motion flow network after looping the walk clip

    This lets the software use the clip repeatedly if necessary.

    Typically, you'd want to proceed directly from walk_start to a walking motion.

  3. Add another transition from walk_start to walk by dragging from the first to the second. The arrow direction should indicate the proper order of the transition.

  4. This step gives recommendations for all of the transitions, which, if followed, will produce the expected results. In your own animations, the motion flow network structure is entirely up to you. The transitions you specify are used as strict guidelines by the software when synthesizing the crowd/biped simulation.

  5. In the Motion Flow rollout, click the Save File button. Save the motion flow network as my_Lesson7.mfe.

  6. In the Motion Flow rollout, click the Shared Motion Flow button.

  7. In the Shared Motion Flow dialog, click the New button to add a shared motion flow.

  8. In the Parameters, click the Load .mfe button, and load the my_Lesson7.mfe file you saved previously.

    If you like, you can instead load the Lesson7.mfe file included in the cstudio\tutorials\tutorial_8 folder. But if you do, you might first need to edit the biped.ini file in your plugcfg folder. Add this line to the end of the file:


    Replace X with the letter of the drive containing the 3dsmax folder. This is so the software can find the BIP files referenced by the motion flow network. If your installation differs from the default, change the sample line accordingly.

  9. In the Shared Motion Flows dialog, click the Add button, and use the Select dialog to add all of the bipeds to the shared motion flow.

    All of the bipeds appear in the Bipeds Sharing this Motion Flow list.

  10. Click the Put Multiple bipeds in Motion Flow button, and then click OK.

    This turns on Motion Flow mode for all of the bipeds.

    You must designate a random start clip so the crowd simulation can solve.

  11. In the toolbar at the top of the Shared Motion Flow Graph dialog, click the Select Random Start Clips button, and then click walk_start in the graph.

    The walk_start clip is now displayed in purple with a probability value (100).

    This means the software will always use this clip to begin the motion flow script that Crowd synthesizes for each biped.

Set the delegates to use random start clips

You can specify that biped/delegates should use the first start clip from the current script or from the Random Start Clip setting. When you first solve this simulation, none of the bipeds will have scripts, so you must choose the second option.

  1. Select the Crowd Object in the viewport.

  2. In the Setup rollout, click Multiple Delegate Editing.

  3. In the Edit Multiple Delegates dialog > Delegates to Edit group, click the Add button.

  4. In the Select dialog, click All and then Select.

  5. In the Biped group, choose Random Start Clip and turn on its SET check box.

  6. Click the Apply Edit button.

Solving the simulation

  1. On the Modify Panel > Solve rollout, click the Solve button.

    Tip: In general, you can speed up the solution significantly by increasing the Solve rollout > Display During Solve group > Frequency setting to 100 or so. But for this lesson, leave it at 1 so you can see exactly what happens during the solution. Or, if it proceeds too slowly on your computer, set Frequency to 2 or 3.

    As before, all six delegates, now teamed with bipeds, solve simultaneously. However, they don't seem to be avoiding each other successfully; in fact, they pass through each other. This happens because, when using bipeds in crowd simulations, directional changes indicated by the delegate behaviors can be overridden by the motion clips guiding the biped animation. For correct character animation, the biped motion must take precedence.

    To resolve this, use Crowd's ability to set priorities and solve one biped/delegate pair at a time. Subsequent bipeds can accurately predict the location of solved bipeds and take corrective measures to avoid collisions. Using backtracking, Crowd avoids collisions by backing up in the motion flow graph and trying other paths through the network.

Setting priorities

  1. At the bottom of the Priority rollout, turn on Display Priorities.

    In the viewport, each delegate displays the number 0. By default, the Priority value 0 is assigned to all delegates. You can change Priority assignments manually, picking delegates in the appropriate order.

    Note: Delegates with lower Priority values take precedence over those with higher values. Thus, for example, a delegate with Priority 0 goes before a delegate with Priority 1, and so on.

  2. In the Priority rollout, click the Assign by Picking group > Pick/Assign button.

    For this lesson, assume that each gang's "captain" is in its center. The Tough Cookies, at the bottom of the Top viewport, go first.

  3. Use the Top viewport to change priority assignments. First pick the center delegate in the bottom group, near the red sphere.

    Because, by default, you assign a Priority value of 0 to the first delegate you pick, the number doesn't change.

  4. Pick the delegate to its left or right.

    The Priority value 1 appears next to the delegate.

  5. Pick the remaining delegate in the bottom group, and then pick the three in the top group, starting with the center delegate.

    The Tough Cookies now have priorities 0, 1, and 2, while the Milquetoasts have 3, 4, and 5.

  6. Right-click in the viewport to turn off picking.

    In order for Crowd to be able to use priorities, you must turn the feature on.

  7. In the Solve panel > Bipeds group, turn on Biped/Delegates Only. Also turn on Use Priorities and Backtracking.

  8. Lastly, still in the Solve panel, turn on Delete Keys Before Solve.

    This disables any existing animation keys, so that it's easier to see what's happening during the solve.

Solving the simulation

  1. On the Modify Panel > Solve rollout, click the Solve button.

    This time, the solution proceeds one biped/delegate pair at a time because Use Priorities is on. First, the captain of the Tough Cookies heads toward the goal, and then his two lieutenants join in, one at a time. During each subsequent sub-solution, you can see the previously solved delegates moving, along with the current biped/delegate pair.

    Next, the captain of the Milquetoasts goes. This is where things start to get interesting. At about frame 250, the time slider jumps back to frame 220 or so, where the solution begins again (your results may vary). Each time it backtracks, Crowd is returning to the start of the current motion clip and trying a different path through the motion flow network, based on the transitions you supplied. If it can't avoid a collision by jumping back one clip, it returns to the start of the previous clip, and so on. Crowd should backtrack two or more clips at least once in this lesson; watch the last biped closely during the solution.

    You might notice that some of the turns taken by the Milquetoast gang members seem too extreme. That's because the bipeds are limited to the motion clips available to them in the motion flow network. For best results in your biped-based crowd simulations, provide as many different appropriate motion clips as possible. For instance, the results of this lesson would probably look more realistic if you had motion clips for turning 45 and 135 degrees in addition to the existing 90- and 180-degree turns. Of course, that would necessitate a larger and more complex motion flow graph as well.

    Other techniques for successful simulations with bipeds include:

Checking the results

To see the results of the motion synthesis, check each biped's motion flow script.

  1. Select one of the Tough Cookies bipeds, and then go to the Motion panel.

  2. In the Motion Flow Script rollout, scroll through the script. Check the other two Tough Cookies members as well.

    Their scripts are pretty straightforward: after the initial walk_start clip, they just repeat the walk clip until they have to turn right to reach the goal. By the way, the directional adjustment is necessary because of a slight discrepancy between the direction of walking in the walk motion clip and the direction indicated by the Seek behavior. You could correct this by incorporating into the motion flow two additional versions of the walk clip, with the footsteps bent slightly to the left and right.

  3. Next, check the Milquetoasts' scripts.

    Each uses a different sequence of walk and turning clips to reach their goal without getting in the Tough Cookies' way.

    Note that some of the clips, such as Loiter, weren't used. Loiter would be more likely to be used if you restricted the use of turning to avoid. Try reducing the Avoid behavior's Steer To Avoid > Detour Angle setting to see if you can get Crowd to use the Loiter clip. Also try different combinations of other Avoid settings and Seek settings to vary the simulation.