---
title: "Flocking"
content_type: tutorial
url: "https://learn.unity.com/course/artificial-intelligence-for-beginners/unit/crowd-simulation/tutorial/flocking?language=en"
language: en
container_type: course
container_title: "Artificial Intelligence for Beginners"
container_url: "https://learn.unity.com/course/artificial-intelligence-for-beginners.md?language=en&version=6.0"
unit_title: "Crowd Simulation"
unit_url: "https://learn.unity.com/course/artificial-intelligence-for-beginners/unit/crowd-simulation?language=en&version=6.0"
standalone_markdown_url: "https://learn.unity.com/tutorial/flocking.md?language=en&version=6.0"
previous_title: "Fleeing"
previous_url: "https://learn.unity.com/course/artificial-intelligence-for-beginners/unit/crowd-simulation/tutorial/fleeing-i?language=en&version=6.0"
previous_markdown_url: "https://learn.unity.com/course/artificial-intelligence-for-beginners/unit/crowd-simulation/tutorial/fleeing-i.md?language=en&version=6.0"
next_title: "An Introduction to GOAP"
next_url: "https://learn.unity.com/course/artificial-intelligence-for-beginners/unit/goal-driven-behaviour/tutorial/an-introduction-to-goap?language=en&version=6.0"
next_markdown_url: "https://learn.unity.com/course/artificial-intelligence-for-beginners/unit/goal-driven-behaviour/tutorial/an-introduction-to-goap.md?language=en&version=6.0"
difficulty: intermediate
duration_minutes: 50
unity_version:
  - "6.0"
supported_unity_versions:
  - name: "6.0"
    url: "https://learn.unity.com/course/artificial-intelligence-for-beginners/unit/crowd-simulation/tutorial/flocking.md?language=en&version=6.0"
  - name: "2021.3"
    url: "https://learn.unity.com/course/artificial-intelligence-for-beginners/unit/crowd-simulation/tutorial/flocking.md?language=en&version=2021.3"
  - name: "2019.4"
    url: "https://learn.unity.com/tutorial/flocking.md?language=en&version=2019.4"
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/flocking.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/flocking.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/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.

## Materials

- [S0906Starter.unitypackage](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/b0532145-eb3e-5db8-b4c7-c85ac60b1b35/versions%5B_key==%22a75bff9d01a7d1fa30ad6016c5c6e395%22%5D.materials%5B_key==%22063a7be4c732%22%5D.file/S0906Starter.unitypackage_20260323_211116.gz)
- [S0909SolutionU6.zip](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/b0532145-eb3e-5db8-b4c7-c85ac60b1b35/versions%5B_key==%22a75bff9d01a7d1fa30ad6016c5c6e395%22%5D.materials%5B_key==%22d223cb420420%22%5D.file/S0909SolutionU6_20260323_211140.zip)

## 1. Flocking Part 1: Setting up Fish Agents

In this tutorial, students will setup a scene with animated fish and spawning functionality before moving onto the next tutorial which will implement flocking.

[Video](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/b0532145-eb3e-5db8-b4c7-c85ac60b1b35/versions%5B_key==%22a75bff9d01a7d1fa30ad6016c5c6e395%22%5D.sections%5B_key==%22rbCl1Be6HAVyj2JQSnEZIA%22%5D.body%5B_key==%22rbCl1Be6HAVyj2JQSnEZL5%22%5D.overviewVideo/S0906_20260414_162716.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/b0532145-eb3e-5db8-b4c7-c85ac60b1b35/versions%5B_key==%22a75bff9d01a7d1fa30ad6016c5c6e395%22%5D.sections%5B_key==%22rbCl1Be6HAVyj2JQSnEZIA%22%5D.body%5B_key==%22rbCl1Be6HAVyj2JQSnEZL5%22%5D.subtitles/S0906%20VTT%20en_20260525_220717.vtt))

## 2. Flocking Part 2: A Basic Schooling Behaviour

In this tutorial, students will get the basic flocking algorithm working to create a simple school of fish.

[Video](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/b0532145-eb3e-5db8-b4c7-c85ac60b1b35/versions%5B_key==%22a75bff9d01a7d1fa30ad6016c5c6e395%22%5D.sections%5B_key==%22rbCl1Be6HAVyj2JQSnEZTq%22%5D.body%5B_key==%22rbCl1Be6HAVyj2JQSnEZWl%22%5D.overviewVideo/S0907_20260320_062002.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/b0532145-eb3e-5db8-b4c7-c85ac60b1b35/versions%5B_key==%22a75bff9d01a7d1fa30ad6016c5c6e395%22%5D.sections%5B_key==%22rbCl1Be6HAVyj2JQSnEZTq%22%5D.body%5B_key==%22rbCl1Be6HAVyj2JQSnEZWl%22%5D.subtitles/S0907%20VTT%20en_20260525_220734.vtt))

## 3. Flocking Part 3: Adding goal locations and speed variety

In this tutorial, students will learn how to add variety to the fish schooling by adding moving goal locations and variable speeds.

[Video](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/b0532145-eb3e-5db8-b4c7-c85ac60b1b35/versions%5B_key==%22a75bff9d01a7d1fa30ad6016c5c6e395%22%5D.sections%5B_key==%22rbCl1Be6HAVyj2JQSnEZfW%22%5D.body%5B_key==%22rbCl1Be6HAVyj2JQSnEZiR%22%5D.overviewVideo/S0908_20260320_062056.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/b0532145-eb3e-5db8-b4c7-c85ac60b1b35/versions%5B_key==%22a75bff9d01a7d1fa30ad6016c5c6e395%22%5D.sections%5B_key==%22rbCl1Be6HAVyj2JQSnEZfW%22%5D.body%5B_key==%22rbCl1Be6HAVyj2JQSnEZiR%22%5D.subtitles/S0908%20VTT%20en_20260525_220743.vtt))

## 4. Flocking Part 4: Containing Fish in a Tank

In this tutorial, students will learn how to add a bounds to the flocking simulation to keep fish contained in an area.

[Video](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/b0532145-eb3e-5db8-b4c7-c85ac60b1b35/versions%5B_key==%22a75bff9d01a7d1fa30ad6016c5c6e395%22%5D.sections%5B_key==%22rbCl1Be6HAVyj2JQSnEZrC%22%5D.body%5B_key==%22rbCl1Be6HAVyj2JQSnEZu7%22%5D.overviewVideo/S0909_20260320_062127.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/b0532145-eb3e-5db8-b4c7-c85ac60b1b35/versions%5B_key==%22a75bff9d01a7d1fa30ad6016c5c6e395%22%5D.sections%5B_key==%22rbCl1Be6HAVyj2JQSnEZrC%22%5D.body%5B_key==%22rbCl1Be6HAVyj2JQSnEZu7%22%5D.subtitles/S0909%20VTT%20en_20260525_220755.vtt))
