---
title: "Flocking"
content_type: tutorial
url: "https://learn.unity.com/course/crowd-simulation/tutorial/flocking?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/flocking.md?language=en&version=2021.3"
previous_title: "Fleeing"
previous_url: "https://learn.unity.com/course/crowd-simulation/tutorial/fleeing-i?language=en&version=2021.3"
previous_markdown_url: "https://learn.unity.com/course/crowd-simulation/tutorial/fleeing-i.md?language=en&version=2021.3"
difficulty: intermediate
duration_minutes: 50
unity_version:
  - "2021.3"
supported_unity_versions:
  - name: "6.0"
    url: "https://learn.unity.com/tutorial/flocking.md?language=en&version=6.0"
  - name: "2021.3"
    url: "https://learn.unity.com/course/crowd-simulation/tutorial/flocking.md?language=en&version=2021.3"
  - name: "2019.4"
    url: "https://learn.unity.com/course/crowd-simulation/tutorial/flocking.md?language=en&version=2019.4"
  - name: "2019.3"
    url: "https://learn.unity.com/course/crowd-simulation/tutorial/flocking.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/course/crowd-simulation/tutorial/flocking.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/course/crowd-simulation/tutorial/flocking.md?language=en&version=2019.1"
last_updated: "2026-08-04T14:23:46.000Z"
---

# Flocking

Apply flocking rules to program a school of fish, confine them to a tank, and add obstacles to the simulation.

In this tutorial students will learn the about the three rules used for simulating flocking and begin setting up a project to create a flocking fish scene.  Next, students will program their fish with more flocking mechanisms to get them to follow the simulated rules and keep them confined in a boundary.  Finally, students will complete the flocking simulation and add obstacles to the fish tank.

## Flocking Part 1

[Video](https://connect-mediagw.unity.com/h1/20220906/videos/32bef1c7-69a1-400b-a2e0-cb1c8d14bba2_S0906.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20221012/e4b3e17f-dd35-4b78-a6b3-fe8c14e14c8e_S0906.vtt))

In this lecture students will learn how the flocking algorithm works and begin setting up a project to create a schooling fish simulation.

## Flocking Part 2

[Video](https://connect-mediagw.unity.com/h1/20220906/videos/9915eeb5-7b4b-4779-bd54-bbc80ad6995c_S0907.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20221012/ff0596b0-2007-4024-aef2-c5ff743cad8d_S0907.vtt))

In this lecture students will write a basic flocking algorithm to create a school of fish.

## Flocking Part 3

[Video](https://connect-mediagw.unity.com/h1/20220906/videos/5f89f062-52d2-42fd-95e7-6f99934326ba_S0908.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20221012/88db9adc-2c15-462c-a813-a428f4f71687_S0908.vtt))

In this lecture students will learn how to add a goal position to the flocking simulation.

## Flocking Part 4

[Video](https://connect-mediagw.unity.com/h1/20220906/videos/79fd124c-d0ad-4d86-b734-5280f90318e2_S0909.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20221012/47cee941-fdf7-4348-bec2-4f02b51af005_S0909.vtt))

In this lecture students will learn how to keep the flocking fish within the confines of a bounding box so they can't swim off into infinity.
