Game Devs Unleash Artificial Intelligence: Flocking Agents
4.6 (86 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
1,137 students enrolled

Game Devs Unleash Artificial Intelligence: Flocking Agents

Artificial Intelligence for Game Devs in Unity to understand & implement the beautiful bird's natural Flocking Behavior
4.6 (86 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
1,137 students enrolled
Created by Razvan Pistolea
Last updated 10/2017
English [Auto]
Current price: $104.99 Original price: $149.99 Discount: 30% off
5 hours left at this price!
30-Day Money-Back Guarantee
This course includes
  • 2.5 hours on-demand video
  • 2 articles
  • 8 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
Training 5 or more people?

Get your team access to 4,000+ top Udemy courses anytime, anywhere.

Try Udemy for Business
What you'll learn
  • Analyze, Decompose and Implement custom Flocking Agents for your own game or movie or personal simulation project
  • Understand and Create Emergence: simple rules that interfere to give rise to complexity
  • Appreciate emergent behaviors in nature around you
  • Gain problem solving skills
  • Understand and use Vectors and Vector Operations successfully in a Game Engine
Course content
Expand all 27 lectures 02:24:40
+ Introduction
2 lectures 02:50

Hi, Razvan Pistolea

What are Artificial Intelligence Agents with Flocking Behavior

Applications of Flocking Behavior in Games, Movies, Engineering and Architectural Simulation

Journey of exploration and implementation

Preview 01:51

Understand how Flocking Behavior appears in nature

Discover the mechanics and equations of Flocking

Implement Flocking

Funny scenario about a Big Movie Producer wanting a flock of sci-fi birds and a big money reward for you if you do it fast and believable

Problem Definition
+ Insights
3 lectures 17:29

Carefully and analytically observe our Earthly flocking birds in their natural habitat

Homework: You must write at least 6 observations

  1. They repeatedly separate and quicksilver
  2. They move like a wave or a fluid
Observe Nature

Questions Answers Insights

Why do you think some birds fly together?

Their movement seems orchestrated somewhat. Does each bird have a sheet music telling it where to go?

Does this behavior seem completely random or do some patterns exist?

Can you think of other animals that are not birds but still "flock" as well?

Relevant questions for our hypothesis:

Does a bird look at all the other birds or just at a few of its nearby neighbors?

Do birds bump into each when they fly or are they separated?

Do birds in the same group or cluster fly in the same direction and with an approximately same speed?

Preview 05:07

Scientific method:

  1. Have a Problem
  2. Gather Relevant Data
  3. Formulate Hypothesis
  4. Empirically Test

  1. Neighborhood radius = abstraction of vision / interest radius
  2. Cohesion Behavior = form a whole
  3. Separation Behavior = avoid collisions
  4. Alignment Behavior = match heading and speed to stay in the flock
  5. Combine all Behaviors in different proportions
+ Implement Basic Flocking in Pseudocode and Unity
14 lectures 01:20:01

Structure our Project in a simple text file using Pseudocode

class Agent{

  1. position vector2 or vector3
  2. rotation vector or quaternion
  3. velocity
  4. acceleration
  5. world reference

  • void update(float t)
  • void render()
  • Vector cohesion() // cohesion behavior
  • Vector separation()
  • Vector alignment()
  • Vector combine() // combine behaviors


class World{

  1. List<Agent> agents
  • void init(int n)
  • void update(float t)
  • List<Agent> getNeighbors(Agent agent, float radius)// neighbors of agent inside radius


class AgentConfig{

  1. float maxV// maximum velocity
  2. float maxA
  3. float Rc, Rs, Ra
  4. float Kc, Ks, Ka


Structure Project in Pseudocode

Create a new project in Unity

Write a simple Move script

Add script statically or dynamically to object

Prefabs in Unity = template, blue print

Structure Project in Unity - Creating a New Project




Spawn Function

Structure Project in Unity - Agent, World, AgentConfig

Equations of motion





trucate acceleration

trucate velocity

Euler forward integration

Rocket science

Stable integration methods, Runge-Kutta

Preview 05:21

Unity uses the metric system

Equations of Motion in Unity

Go towards the center of mass of all nearby neighbors

Cohesion Behavior in Pseudocode

Vector cohesion(){

  1. // cohesion behavior
  2. // return a vector that will steer our curent velocity
  3. // towards the center of mass of all nearby neighbors
  4. // get all my nearby neighbors inside radius Rc of this current agent
  5. // no neighbors means no cohesion desire
  6. // find the center of mass of all neighbors
  7. // steer our velocity towards the COM
  8. // make r have the length 1


Preview 04:55

Individual separation forces combine to give the resultant force

Vector separation(){

  1. // separation behavior
  2. // steer in the opposite direction from each of our nearby neigbhors
  3. // get all my neighbors
  4. // no neighbors no separation desire
  5. // add the contribution of each neighbor towards me
  6. // force contribution will vary inversly proportional
  7. // to distance or even the square of the distance


Separation Behavior in Pseudocode
Separation Behavior in Unity

Match heading and speed in order to stay withing the flock

Alignment Behavior in Pseudocode

Update Prefab


Tokyo Drift

LookAt function

Vector alignment(){

  1. // alignment behavior
  2. // steer agent to match the direction and speed of neighbors
  3. // get all neigbhors
  4. // no neighbors means no one to align to
  5. // match direction and speed == match velocity
  6. // do this for all neighbors


Preview 06:53

Combine all forces at the same time in different proportions

Combine All Behaviors in Pseudocode

Wrap around to keep inside the view

Combine All Behaviors in Unity

Structure problem

Update loop, Euler integration

Pseudocode + Unity = perfect match, best learning

Cohesion, Separation, Alignment

Tweek Parameters

Ideas=Lines of Code=Simulation

Think it! Build it!

Emergence, split, merge, dance


Playground to experiment aspects of Flocking

Summary for Basic Flocking Implementation
+ Refinements for Advanced Flocking Behavior In Pseudocode and Unity
5 lectures 39:23

360 degrees default

180 degrees realistic

angle between 2 vectors

add the refinement to all behaviors

Field of View Refinement in Pseudocode

They move closely together

They are moving like a wave

Field of View Refinement in Unity

A solo creature or a small flock that wanders purposefully on the map

Jitter vs Smooth = Dumb vs Purpose

Generate a small random target that moves on a circle in from of the agent

Project the target from local space to world space

Preview 08:50

Update prefab to have a Default Transform

Warning ! the transform scale influences the projection from local space to world space

Adding Wandering Behavior in Unity

Extend the Agent Class to make a Predator Class

Avoid Enemies Behavior

Flee Behavior

GetPredators Function

Adding Avoid Enemy Behavior in Unity
+ Conclusion
2 lectures 00:36
Student Projects
What's next
+ Valuable Resources
1 lecture 04:20 deep learning platform that offers AI as a service educational Artificial Intelligence courses

Preview 04:20
  • You should already have basic Computer Science skills (minimum 6 months experience)
  • You should already be familiar with any game engine (minimum 3 months experience)
  • Have Unity 3D game engine installed or your own favorite game engine
  • Understand Pseudocode or C# or Java

Learn how to create Artificial Intelligent Agents that have Flocking Behavior and apply them to your projects in games or movies. You have seen Flocking behavior in nature, in games, in movies and in architectural simulations but you might have missed it.

The course is project based with the best teach-apply loop:

  • a theoretical pseudocode (game engine agnostic) implementation
  • followed immediately by a practical implementation and application in Unity 3d

Both pseudocode and Unity C# lectures complement each other giving you a full perspective.

Best video quality 1080p full HD.

You will have access to the course forum where you can discuss each topic with like-minded, A.I. passionate, students like yourself.

With the help of this course you will be able to understand a piece of nature and replicate it, essentially reverse engineer a piece of nature. Invest in yourself and add Flocking to your A.I. skill set! Follow this Unleash A.I. series.

Still unsure? Dive in and learn, and if you are not satisfied you get a 30 day money back guarantee! No questions asked.

Who this course is for:
  • The course is best suited to programmers who want to add realistic bird flocking or fish schooling or other emergent behaviors to their games, movies or simulations.
  • The course is best suited to programmers looking to improve their skills on working with Vectors inside the Unity 3d game engine
  • The couse if partially suited for students who want to learn emergent behaviour but do not have prior programming experience. The must have at least basic math or physics skills.
  • The course is partially suited for students who already know about emergence. They can use it as a refresher.
  • The course is not suited for students who do not have basic math or physics skills.