Houdini 21.0 Crowd simulations

Agent relationships

Define parent-child relationships between agents.

On this page

Parent-child relationships between agents can be set up using the Agent Relationship SOP. The Agent Relationship SOP adds attributes on the agents that describe the parenting relationships they have. These attributes are then used by the crowd solver and crowd motion path tools to keep the child attached to the parent.

Set up the parent-child relationship

In this example, we attach rider agents (child) to horse agents (parent):

Child agents are attached to parent agents based on point number. It’s not necessary to have the same number of parent and child agents. If there are more child agents than parents, there will be multiple child agents attached to some parents.

By default, the Agent Relationship SOP updates the child’s overall transform to match the parent’s overall transform. There are a couple ways to further adjust the child agent once the initial attachment is made:

  • Enter the Agent Relationship viewer state by clicking on the left toolbar, and adjust the child agent using the handle. To change the orientation of the child, click the handle and select Cycle Translate/Rotate, or press Y over the viewport to change the handle to rotate mode. The Translate and Rotate parameters on the Agent Relationship SOP will be updated as you manipulate the handle:

  • Attach the child to a particular joint on the parent - on the Agent Relationship SOP, turn on Parent Joint, and select a joint on the horse to attach the rider to. You can also specify a joint on the child agent (in the Child Joint parameter) to attach to Parent Joint.

To...Do this

Specify the agents that can be parents

  1. On the Agent Relationship SOP, click beside the Parent Group parameter.

  2. In the viewport, select the agents you want as parents.

  3. Press Enter over the viewport.

The Parent Group parameter will be populated with the selected parent agents.

Attach a child agent to a specific parent agent

  1. Place an Attribute Wrangle SOP upstream of the Agent Relationship SOP:

  2. On the Attribute Wrangle SOP, write VEX code in the VEXpression field to set the agentrel_parentid attribute. For example, to attach children to parents in reverse point number order, use the following VEX code:

    i@agentrel_parentid = npoints(0) - @ptnum - 1;
    

Change the scale of the child to match the scale of the parent

On the Agent Relationship SOP, turn on Match Parent Agent Scale.

Crowd simulation network

In the crowd simulation network, the crowd solver keeps the child agent attached to its parent, and the parent’s movement is steered by the forces applied to it. The crowd_simulation DOP network from the parent SOP network is shown below:

  1. On the crowdobject DOP, set Source to First Context Geometry because the Agent Relationship SOP in the parent SOP network is connected to the first input of the crowd_simulation DOP network node.

  2. Set the horse agent’s state:

    • Rename the horse agent’s Crowd State DOP, in our example, horse_run_straight.

    • Set the animation clip that the horse plays in this state - on the Crowd State DOP, set Clip Name to run_straight.

    • Set Type to Locomotive because the original clip has some overall root motion.

    Note

    To view the animation clips that are available on the agent, use an Agent Clip SOP:

    1. On the Agent Clip SOP, turn on Set Current Clip and select the animation clip you want to view from the drop-down menu. These animation clip names are used to set the clip that the state plays in the Crowd State DOP’s Clip Name parameter.

    2. Click in the playbar to play the clip. If the animation plays really fast, try clicking the Real Time Toggle in the playbar.

  3. Make the horse agents move around randomly using the POP Steer Wander DOP:

    • Set Output Attribute to Crowds steerforce because we are working with agents and not particles.

  4. Set the rider agent’s state:

    • Rename the rider agent’s Crowd State DOP, in our example, rider_run_straight.

    • Set the animation clip that the rider plays in this state - on the Crowd State DOP, set Clip Name to run.

The parent and child agents are treated as separate agents with their own sets of animation clips (defined in their respective Crowd State DOPs). Any steering forces applied to the child agent will not have any effect on the child’s motion because it is attached to the parent.

Simulation of child agents attached to their parent agents

Detach child agents

There may be cases where you would want to detach a child agent from its parent. For example, if you want to transition a child agent to a full ragdoll, you would first detach the child from its parent.

The Agent Relationship SOP adds attributes on the agents that describe the parenting relationships they have. The attribute agentrel_parentid on an agent identifies the parent agent it is attached to. If agentrel_parentid is less than 0, that agent does not have a parent, and its other agentrel_* attributes are meaningless.

In this example, we detach the rider agent from its parent horse agent after 50 frames. We do this by adding a Crowd State DOP with the animation clip to play when the rider become detached, as well as the trigger condition that transitions the rider to the new animation clip:

  1. The Crowd State DOP, rider_detached, is a copy of the Crowd State DOP, rider_run_straight.

  2. Detach the rider from its parent using a POP Wrangle DOP:

    • In the VEXpression field, write VEX code to set the agentrel_parentid attribute to -1 for the child agents you no longer want to be parented. For example, the following VEX snippet unparents all the child agents:

      i@agentrel_parentid = -1;
      
  3. Use a Crowd Trigger DOP to set the trigger that detaches the rider from its parent:

    • Set Type to Time (Current). By default, the trigger is activated when the number of frames is greater than 50 (based on the values of parameters Units, Comparison, and Playback Time).

  4. Use a Crowd Transition DOP to transition the rider to another state after detaching from its parent:

    • We want to transition the child from state rider_run_straight to rider_detached, so set Input State to rider_run_straight and Output State to rider_detached.

The video below shows the rider agents detaching from their parents after 50 frames and continuing to play their animation clip:

See also

Crowd simulations

Getting started

  • Basics

    An overview of Houdini crowd simulation concepts.

  • Setup

    How to set up and edit a crowd simulation.

The moving parts

  • Agents

    About agents, the moving actors that make up a crowd simulation.

  • States

    About agent states, the virtual mood of each agent that controls the agent’s animation and the behaviors it runs.

  • Triggers

    How to specify conditions that cause agents to change from one state to another.

  • Caches

    Tips for efficiently caching and loading crowd sims.

Behavior

Appearance

  • Diversity

    How to create a more realistic crowd by making agents look and act differently.

  • Attaching cloth

    You can add and constrain vellum cloth as part of agent shape geometry, and then simulate the cloth based on agent movements.

Terrain

  • Foot planting

    How to set up agents to adapt their animation to terrain and prevent skating.

  • Terrain

    How to specify terrain geometry for agents to walk across.

  • Obstacles

    How to set up obstacles for agents to avoid.

SOP crowds

Crowd Procedural