---
title: "Fleeing"
content_type: tutorial
url: "https://learn.unity.com/course/crowd-simulation/tutorial/fleeing-i?language=en"
language: en
container_type: course
container_title: "Crowd Simulation"
container_url: "https://learn.unity.com/course/crowd-simulation.md?language=en&version=2021.3"
standalone_markdown_url: "https://learn.unity.com/tutorial/fleeing-i.md?language=en&version=2021.3"
previous_title: "Creating a City Crowd"
previous_url: "https://learn.unity.com/course/crowd-simulation/tutorial/creating-a-city-crowd?language=en&version=2021.3"
previous_markdown_url: "https://learn.unity.com/course/crowd-simulation/tutorial/creating-a-city-crowd.md?language=en&version=2021.3"
next_title: "Flocking"
next_url: "https://learn.unity.com/course/crowd-simulation/tutorial/flocking?language=en&version=2021.3"
next_markdown_url: "https://learn.unity.com/course/crowd-simulation/tutorial/flocking.md?language=en&version=2021.3"
difficulty: intermediate
duration_minutes: 20
unity_version:
  - "2021.3"
supported_unity_versions:
  - name: "6.0"
    url: "https://learn.unity.com/tutorial/fleeing-i.md?language=en&version=6.0"
  - name: "2021.3"
    url: "https://learn.unity.com/course/crowd-simulation/tutorial/fleeing-i.md?language=en&version=2021.3"
  - name: "2019.4"
    url: "https://learn.unity.com/course/crowd-simulation/tutorial/fleeing-i.md?language=en&version=2019.4"
  - name: "2019.3"
    url: "https://learn.unity.com/course/crowd-simulation/tutorial/fleeing-i.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/course/crowd-simulation/tutorial/fleeing-i.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/course/crowd-simulation/tutorial/fleeing-i.md?language=en&version=2019.1"
last_updated: "2026-08-04T14:22:16.000Z"
---

# Fleeing

Add a hazardous obstacle to a crowd simulation and script agents to flee for a set duration.

In this tutorial students will learn how to add a dangerous obstacle to a crowd simulation and program the agents to flee for a specified amount of time.

## Materials

- [S0905Solution.zip](https://unity-connect-prd.storage.googleapis.com/20220916/823252d1-9ec6-4b4e-96b2-39b0df872432/S0905Solution.zip)

## 1. Fleeing Part 1

[Video](https://connect-mediagw.unity.com/h1/20220906/videos/be1f0ecd-7fa4-4db8-8127-4ec7f87dfb4a_S0904.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20221012/bfe64f77-a4d6-4a17-9664-39ef464b1422_S0904.vtt))

In this lecture students will setup a project to drop an obstacle into the scene that the agents in the crowd will flee from.

## 2. Fleeing Part 2

[Video](https://connect-mediagw.unity.com/h1/20220906/videos/4fe6eba0-a554-44c5-be45-67de779c81f0_S0905.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20221012/40b628c5-f916-489a-bca7-6236eb7fa160_S0905.vtt))

In this lecture students will complete the fleeing simulation by adding code to the agents controller to calculate a flee direction.
