Skip to main content

Assembling Custom Agents

A pedestrian, a dog, a delivery robot, and a scooter with a rider, side by side

If none of the agents in the Agent Catalog suit your scenario, you can make your own: a different pedestrian, an animal, or a vehicle with a new look. You can start from scratch or begin as a copy of one that already works, and you swap your own model into it.

This page changes to match the agent you're making. Answer the questions below, and it shows only the steps that apply to you.

What type of agent is it?
Is it an ego agent or a road agent?

Before You Start​

Every agent starts from a prefab: either a base prefab that has everything but the model, or a copy of an agent that already works. Here's which prefab to start from, what's already inside it, and what you'll need to have ready.

Josh and Kate, the two pedestrians that participants can control

Start from EgoAgentBase_Pedestiran. Here's what's already inside it:

EgoAgentBase_Pedestiran in the Hierarchy and Inspector, with the camera targets, the Character Controller, and the Player Pedestrian Driver labeled

Everything except the character is already there:

  • A Character Controller, the invisible capsule that the character moves inside.
  • The Player Pedestrian Driver, which turns the participant's controls into movement. As the character speeds up, it also blends the animation from walking to running.
  • The camera targets, which decide where the participant's camera sits.

Your job is to add the character, fit the capsule around it, and connect the two.

You'll need your character, imported into the project with a Humanoid rig. To check the rig:

  1. Select the model file in the Project window.
  2. Open the Rig tab in the Inspector.
  3. Make sure Animation Type is set to Humanoid.

Rig tab of a character model in the Inspector, with Animation Type set to Humanoid

The project already has plenty of characters you can use, including the Actor Core library. You'll find them under Pedestrian in the Agent Catalog.

Build It​

Create a variant

RoadAgentBase_Pedestrian selected in the Project window

  1. In the Project window, go to Assets/mobisim/Actors/Pedestrian/Prefabs, and find EgoAgentBase_Pedestiran.
  2. Right-click it, and choose Create > Prefab Variant.
  3. Name the variant after your agent.
  4. Double-click the variant to open it in Prefab Mode.

A variant is a copy that stays linked to the original, so when the original gets a fix, your agent gets it too. Meanwhile the original stays unchanged, and other scenarios that use it aren't affected.

Add the character

The character dropped under the root of the variant, with its Position and Rotation set to 0

  1. Drag your character's prefab or model from the Project window onto the root of the variant in the Hierarchy, so it becomes a child of the root.
  2. In the Inspector, set the character's Position and Rotation to 0, 0, 0.

The root sits at the agent's feet, so the character now stands on the ground, facing the same way as the root's blue arrow in the Scene view.

Fit the capsule to the character

The capsule outline shrinking to wrap a child character as its Height, Center Y, and Radius change

The capsule is the invisible shape that the character moves inside and that others bump into. It's sized for an adult, so a smaller character needs a smaller capsule.

Select the root of the variant in the Hierarchy.

On the Character Controller in the Inspector, set:

  • Height to your character's height, in meters.
  • Center Y to half of that.
  • Radius to about half the width of its shoulders.

It starts with a height of 1.7, a center Y of 0.85, and a radius of 0.3.

The green outline in the Scene view shows the capsule. It should wrap the character from the ground to the top of its head, which for a child or an animal usually means making it a lot shorter.

Set up its animation

Animator on the character, with Controller set to pedestrian_animation_controller and Apply Root Motion unticked

Select the character in the Hierarchy, and find its Animator in the Inspector:

  1. Set Controller to pedestrian_animation_controller.
  2. Check that Avatar is the character's own avatar, and that it's a Humanoid avatar.
  3. Untick Apply Root Motion, because the controller on the root does the moving rather than the animation.
Connect the driver to the character

Player Pedestrian Driver in the Inspector, with the character in Animator

Select the root of the variant. On its Player Pedestrian Driver, drag the character from the Hierarchy into Animator. The driver uses it to keep the walking animation in step with the speed.

Hide the body in first-person view

The character's Layer set to Invisible In First Person View

In first person, the camera sits inside the character's head, so the character needs to be hidden from that camera:

  1. Select the character in the Hierarchy.
  2. At the top of the Inspector, set Layer to Invisible In First Person View.
  3. When Unity asks whether to change the children too, choose Yes, change children.

The first-person camera skips this layer, so the participant never sees the inside of their own head.

Set up the participant's camera
What will you build the scenario for?

The first-person and third-person camera targets on an E-Scooter, seen from the side

The participant's camera follows one target and aims at another, and first person and third person each have their own pair. You'll find them under CameraPivot in the Hierarchy. Move them in the Scene view:

  • FirstPersonFollowTarget goes at the participant's eye position.
  • FirstPersonAimTarget goes a little ahead of it, at the same height.
  • ThirdPersonFollowTarget goes behind and above the agent, where the third-person camera should sit.
  • ThirdPersonAimTarget goes on the point the third-person camera should aim at, such as the agent's shoulders.

Then, in your scenario's Player Selector, choose the view participants start in: FirstPerson_Switchable_CameraRigPrefab or ThirdPerson_Switchable_CameraRigPrefab. See Choosing a Camera Rig. To switch views during the scenario or add driving camera effects, see Participant Camera.

Connect navigation arrows
Does the participant need navigation arrows?

Then there's nothing to set up here.

Make it selectable

The Controllable label ticked in the label menu

In the Project window, select the variant, and give it the Controllable label at the bottom of the Inspector. It then shows up in the Player Selector's Controllable Prefab list, ready to be chosen as the participant's agent.

See Making a Prefab Controllable.

Tag it

Actor Identifier in the Inspector, with four tags in its Tags list

Tags tell the rest of your scenario what your agent is, such as which agents an event trigger reacts to. To learn how they work, see Scriptable Tags.

Select the root of the variant, and find Tags on its Actor Identifier in the Inspector. Make sure the list has the tags below. To add one, click +, and drag the tag asset into the new slot.

  • What it is: Pedestrian_Tag.
  • Whose it is: Player_Tag, which marks it as the participant's agent.
  • Who it is: Male_Tag or Female_Tag, and the character's own tag, such as Brian_Tag, if it's one of the project's characters.

Remove any other tags left over from the agent you started from that don't fit yours.

Use the tags that already exist, rather than new ones with the same names. If you need a tag that doesn't exist yet, such as one for your animal, see Creating Scriptable Tag Assets.

Also make sure the built-in Tag at the very top of the Inspector is Mine. Without it, the agent's tags don't count as the participant's, so the help panel can't use them to pick which keyboard controls to show.