The Beginner's Guide to Artificial Intelligence in Unity.
4.5 (1,586 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.
18,587 students enrolled

The Beginner's Guide to Artificial Intelligence in Unity.

A practical guide to programming non-player characters for games.
4.5 (1,586 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.
18,587 students enrolled
Last updated 6/2020
English, Portuguese [Auto], 1 more
  • Spanish [Auto]
Current price: $15.99 Original price: $19.99 Discount: 20% off
30-Day Money-Back Guarantee
This course includes
  • 10.5 hours on-demand video
  • 12 articles
  • 72 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
  • Design and program NPCs with C# in Unity
  • Explain how AI is applied in computer games
  • Implement AI-related Unity Asset plugins into existing projects
  • Work with a variety of AI techniques for developing navigation and decision making abilities in NPCs
Course content
Expand all 70 lectures 10:48:03
+ Introduction
6 lectures 22:08

This lecture introduces the course by outlining all the content that will be covered with a section by section breakdown.

Preview 03:26

H3D has a bustling online student community.  Here's how to get involved.

Join the H3D Student Community

In this lecture we will get an overview of vectors and why they are an important concept to have an understanding of before you launch into programming the movement of an NPC.

Preview 07:02
Vector Mathematic Basics Cheat Sheet
Test your vector mathematics knowledge
10 questions
Unity uses the FBX file format by default to represent 3D models. Within Unity 2017 and greater the way the files are dealt with has changed slightly and may cause you to lose the textures from your models. Take note of the process in this lecture that will assist you in fixing this issue when you encounter it later in the course.
Important Note Regarding Unity Updates to FBX Model Importing
+ Moving
7 lectures 58:11

In this lecture we will take a quick look at the nature of vectors and then discuss through a practical application how they can be used to move a character forward at a constant speed.

Vectors and Moving in a Straight Line

Follow along in the lecture as we setup a goal location for the character to move towards. You will also be shown how to change the facing direction of a character such that it looks in the direction it is travelling.

Traveling to a Goal Location

In this lecture we will examine a different approach to moving the character. This time instead of setting a vector to travel along we will turn the character towards a goal and then push the character in a forward direction.

Pushing the Character Forward

Instead of snapping a character around to face a goal in a single update you may want more smooth turning behaviour to occur that makes the movement appear more natural. In this lecture we will examine the slerp method for achieving this.


In this lecture we will take a quick look at the difference between animation translation and translating with code. Eitherway is acceptable and it will depend on what you are trying to achieve with the look of your character as to which one is more appropriate.

About Animation and Translation

In this lecture we will look at the simplest form of AI navigation: waypoints. Using the code we've developed thus far by giving the NPC an array of goals we can change its behaviour from chasing to patrolling.

+ Cars
4 lectures 49:40

If you import the Utilities from Unity's included assets you'll find code for setting up waypoints and navigating a circuit. In this lecture we will look at how to integrate these Unity asset's with our own code.

Unity's Waypoint System

In this lecture we will examine how to create a simple car NPC that can accelerate and brake while following a circuit tracker.

Car Racing with Waypoints

Continuing where we left the previous lecture we will add in another car and set about making the properties of the movement behaviour customisable.

Customising Car Behaviours

Inside Unity's Standard Assets you will find the setup for a Waypoint following AI car with many customisable properties. In this lecture we will explore this feature as well as discuss how to add your own custom model into the system.

Unity's Vehicle System
+ Waypoints
5 lectures 39:37

Graph Theory underpins so many AI techniques and it certainly deserves some focussed attention. In this lecture we will examine the structure of graphs and several path searching algorithms will be discussed.

Preview 08:31

In this lecture we will apply the A* algorithm to finding a path through a system of waypoints converted into a graph.

Pathfinding through Waypoints

In part 2 of this hands-on workshop to put together a waypoint graph traversal system using the A * algorithm we will add UI buttons to send location commands to the NPC.

Pathfinding through Waypoints Part 2

This short article will explain how the code for dealing with 3D waypoints can be modified for 2D environments.

Waypoints in 2D
+ NavMeshes
10 lectures 01:29:55

In this lecture we will modify the pathfinding exercise created thus far and introduce the concept of a NavMesh. This will reduce the amount of code we need to write as well as the time taken to setup a waypoint system manually.

Preview 05:11

In this lecture we will turn the previous waypoint system with the tank into a navmesh based project.

From Waypoints to NavMesh

In this lecture we will start taking a closer look at the navmesh agent component and explore the various settings for the baked nav mesh agent that controls how the navmesh is generated.

NavMesh Agents Part 1

Agents can be assigned different areas of the NavMesh through which to travel. In this lecture we will look at how to set up different areas with different costs and associate the agents with them.

NavMesh Agents Part 2

The test of a NavMesh is to try it out with a real character in a real situation. It's then you'll find glitches in the default settings and automatically generated paths. Without having to remodel the environment, off-mesh links can be generated to provide smooth paths were their aren't any. In this lecture we will make a character follow a first person player character around a map while tweaking the NavMesh to handle different situations when gaps and drops appear in the NavMesh.

Following a Player on A NavMesh and Setting-Up Off Mesh Links

This video link describes how to fix textures on imported FBX files from Mixamo.

Fixing Mixamo Textures

In this lecture we will examine how the NavMesh agent code and be coordinated with character animation to provide smooth and believable movement of a character when pathfinding over a NavMesh.

Animating on a NavMesh

In this short lecture I will demonstrate how to sync the animation speed with the nav mesh agent speed.

Syncing Animation Speed with NavMesh Agent Speed

In order to include multiple navmeshes to cater for multiple different navmeshagent sizes we need to turn to some beta code that isn't currently included in Unity but available for download and inclusion. In this lecture we will walk through the setups of creating multiple navmeshes after a quick refresher on setting up humanoid animations with strafe sets.

Multiple NavMeshes for Different Agent Sizes
+ Autonomously Moving Agents
8 lectures 01:31:43

In this video students will follow along to implement simple seek and flee methods for a Nav Mesh agent.

Seek and Flee

In this video students will learn about the differences in dynamics between the seek and pursuit behaviours and add an new method for moving an agent into the code.


In this video students will be challenged to create their own evade method which will see the agent move away from the predicted location of the target.


In this video students will examine one method of producing a wandering behaviour that will have the agent freely walk around the environment with smooth randomness.


In this video students will take a look at the basics behind the hide behaviour.  In it we will create a simple hide method that will have the agent hide behind the closest obstacle in the environment.

Hide Part 1

In this video students complete the development of the hiding behaviour and work to calculate a more accurate hiding location and reduce the number of calls to the method in the update.

Hide Part 2

In this video students will learn how to combine a number of steering behaviours with simple geometric conditions to produce complex behaviours in agents.

Complex Behaviours

In this video students will be challenged to integrate the wander behaviour into the complex behaviour to have the agents go into a wander when the target cop is out of range.

Behaviour Challenge
+ Moving As One
10 lectures 01:39:56

There are many factors to included in a crowd simulation... or are there? Seemingly very complex movement behaviour can be generated for groups of characters with some very simple rules. This lecture will show you how.

Crowd Simulation

In this series of lectures we will set up a city scene with a crowd walking along the sidewalk.

Creating a City Crowd Part 1

This lecture continues on from the last adjusting animation behaviours and speeds to vary from agent to agent as well as introduces the concept of a dynamic obstacle that can move around a navmesh and be avoided by the agents.

Creating a City Crowd Part 2

A behaviour seen in NPC movement is fleeing. This is a technique for steering a character away from danger. In this lecture we will look at the mathematics involved in the movement and apply it to the crowd simulation.


Flocking is capable of producing incredible behaviour from three simple vector calculations. In this lecture you will learn how to apply this to the development of schooling fish.

Flocking Part 1

In this second part of the flocking workshop we will add extra behaviours to the fish by controlling the boundary of their swimming range.

Flocking Part 2

The third part of the flocking workshop will explore ways in which the fish can avoid obstacles in their environment through raycasting and vector calculations.

Flocking Part 3
Challenge 1
Challenge 2
Challenge 3
+ Let's Start Thinking
6 lectures 56:37

In this lecture we will develop an NPC that can detect the presence of a player and act accordingly. We will implement step-by-step this algorithm which is one of the simplest AI techniques used.

Line of Sight

Finite State Machines are a staple AI method used in games as they elegantly segregate the states, behaviours and logic used by NPCs. In part one we will begin looking at how the Unity animation system can be used to create such a machine.

Finite State Machines Part 1

In this second part of the FSM workshop we will add a base NPC class to enable sharing of properties between behaviour scripts and then add in the functionality to move from patrol to chase and back again.

Finite State Machines Part 2

In the final FSM lecture, steping you through the setup for a FSM, we will complete the example by adding in bullet shooting functionality and states onto the NPC tank.

Finite State Machines Part 3

In this short lecture I'll show you how to convert the waypoint system used to move the tank around to have the same FSM work on a navmesh.

Converting the FSM to Work on a Navmesh
+ Behaviour Trees
8 lectures 01:17:30

In this lecture Behaviour Trees will be introduced. Well take a look at their structure and the theory of their execution.

Introduction to Behaviour Trees

This lecture begins by taking you through the setup for our behaviour tree project before starting with a very simple sequencial behaviour tree as a demo.

Sequence Nodes Part 1

We continue our examination of sequences in this lecture by creating a longer set of actions and modifying different behaviour tree specific returns discover what makes sequences run and fail. Towards the end we will start creating a new behaviour tree for attacking and take a look at the wait leaf node.

Sequence Nodes Part 2

In this lecture we will take a look at the while decorator node that allows you to invert the value of an action and also perform logic tests in the tree at a higher level than leaf nodes.

Embedding Logic in Behaviour Trees

This lecture will introduce the selector node. This type of node can be used when any (but only one) of the children nodes need to run.

Selector Nodes

In this lecture we will complete the full set of single behaviour trees that will define all behaviours of the agent by adding the abilities to flee from danger and die.

More Logic for Complex Behaviours

To finish our investigation into Behaviour Trees all the smaller trees made throughout this section will be combined to inform the total behaviour of the agent droid. A final version of the project is attached as a download.

Putting Together a Complex Behaviour Tree
+ Goal-Orientated Action Planning
5 lectures 51:27

Goal-Orientated Action Planning is an AI technique that turns Finite State Machines on their head. It decouples goals from actions and provides for a very dynamic NPC behavioural system.

Introduction to GOAP

In this lecture we will get started with GOAP by setting up a simple scene and adding an agent.

Getting Started with GOAP in Unity

In this lecture the GOAP agent will be given its first set of actions.

Adding Actions to GOAP

To create more complex behaviours in an agent you can add multiple plans that it can execute when the world states are right. In this lecture we will do this by extending the baker behaviour.

Adding Multiple Plans to GOAP

Even more complexity can be added when multiple inventories and agents are introduced to the system. This lecture will take you through the addition of a world inventory as well as a new agent type.

Global States and Multiple Agents
  • You should be familiar with C# and the Unity Game Development Engine.

Do your non-player characters lack drive and ambition?  Are they slow, stupid and constantly banging their heads against the wall? Then this course is for you.  Join Penny as she explains, demonstrates and assists you in creating your very own NPCs in Unity with C#. All you need is a sound knowledge of Unity, C# and the ability to add two numbers together.

In this course, Penny reveals the most popular AI techniques used for creating believable character behaviour in games using her internationally acclaimed teaching style and knowledge from over 25 years working with games, graphics and having written two award winning books on games AI. Throughout, you will follow along with hands-on workshops designed to teach you about the fundamental AI techniques used in today's games.  You'll join in as NPCs are programmed to chase, patrol, shoot, race, crowd and much more.

Learn how to program and work with:

  • vectors

  • waypoints

  • navmeshes

  • the A* algorithm

  • crowds

  • flocks

  • animated characters

  • vehicles

Contents and Overview

The course begins with a detailed examination of vector mathematics that sits at the very heart of programming the movement of NPCs. Following this, systems of waypoints will be used to move characters around in an environment before examining the Unity waypoint system for car racing with AI controlled cars.  This leads into an investigation of graph theory and the A* algorithm before we apply these principles to developing navmeshes and developing NPCs who can find their way around a game environment.  Before an aquarium is programmed complete with autonomous schooling fish, crowds of people will be examined from the recreation of sidewalk traffic, to groups of people fleeing from danger. Having examined the differing ways to move NPCs around in a game environment, their thinking abilities will be discussed with full explanations and more hands-on workshops using finite state machines and behaviour trees.

The follow-along workshops included in the course come with starter Unity asset files and projects complete with solutions.  Throughout, there are also quizzes and challenge exercises to reinforce your learning and guide you to express your newfound knowledge.

At the completion of this course you will have gained a broad understanding of what AI is in games, how it works and how you can use it in your own projects.  It will equip you with a toolset to examine any of the techniques presented in more depth to take your game environments to the next level.

What students are saying about this course:

  • This has been my favourite Udemy-Unity course so far. It took me from literally 0% knowledge of how game AI is achieved, and took me to a whole new level. Waypoints, pathfinding, state machines, etc etc etc are all covered in-depth and will reveal the magic (spoiler alert: it isn't magic) behind making your computer characters seem like they really have a mind of their own.

  • Oh My God. I love her way of teaching things. I haven’t finished this course yet. But all i can say is that it is another brilliant course from her. Artificial intelligence by itself is a tricky thing to do. And before starting this course i never thought that i will understand anything in it. But i was wrong. With her style of teaching, you will learn how to move your characters in an ”intelligent“ way. This course is perfectly sliced and the pace is wonderful.

Who this course is for:
  • Anyone interested in learning how to program their own non-player characters (NPCs).
  • Anyone interested in seeing how artificial intelligence is applied in computer games.