---
title: "Flocking"
content_type: tutorial
url: "https://learn.unity.com/tutorial/flocking?language=en"
language: en
difficulty: intermediate
duration_minutes: 50
unity_version:
  - "6.0"
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/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.

## 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))

## 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))

## 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))

## 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))
