Important Notice:

On July 31st, 2017 the Digital-Tutors library will be retired along with Digital-Tutors concurrent licensing. Effective August 1, 2017 any active group plans will be redirected to www.pluralsight.com. Each group plan will receive one individual user license on Pluralsight for each active Digital-Tutors license. Please contact your account representative for any additional questions.
Unity Mobile Game Development: Enemy AI and Waypoints
See Details
Released Mar 1, 2012
Chris Glick

Pluralsight

Chris Glick
In this series of Unity tutorials, we'll demonstrate how to setup our waypoints in order to allow our enemies to seek and destroy the player. We'll also discuss how to create a basic AI for our enemies. Having a computer understand our level is one of the most pertinent problems facing any game developer. Waypoints are a quick and powerful way to create a simple model of a level that an AI can understand. Once we have our waypoints set-up and working, we'll create an enemy AI that can find and attack the player.
Introduction and project overview
1

Introduction and project overview

 
01:04
Mapping out the problem of entities moving around our level
2

Mapping out the problem of entities moving around our level

 
05:21
Waypoint ideas, concepts and our implementation
3

Waypoint ideas, concepts and our implementation

 
07:25
Creating an initial Waypoint prefab and setting it up
4

Creating an initial Waypoint prefab and setting it up

 
08:01
Filtering nearby objects to other waypoints with a layer mask
5

Filtering nearby objects to other waypoints with a layer mask

 
07:36
Coding a variable distance with a while loop
6

Coding a variable distance with a while loop

 
10:14
Building in line-of-sight with layer masks
7

Building in line-of-sight with layer masks

 
05:57
Relaying information to neighbors without infinite loops
8

Relaying information to neighbors without infinite loops

 
11:53
Initializing a Generic List of waypoints to get to the player
9

Initializing a Generic List of waypoints to get to the player

 
12:52
Creating an initialize function and removing the countdown
10

Creating an initialize function and removing the countdown

 
09:47
Using conditionals to check if we want to update the list
11

Using conditionals to check if we want to update the list

 
10:58
Creating a controller script that gathers all the waypoints
12

Creating a controller script that gathers all the waypoints

 
07:30
Locating the closest waypoint to any point in space
13

Locating the closest waypoint to any point in space

 
13:16
Coding a function to return a random waypoint
14

Coding a function to return a random waypoint

 
10:37
Using a While True Yield loop to update every few seconds
15

Using a While True Yield loop to update every few seconds

 
08:50
Creating a Spawner script to create new enemies
16

Creating a Spawner script to create new enemies

 
08:51
Using a Spawn Controller to randomly spawn enemies
17

Using a Spawn Controller to randomly spawn enemies

 
05:16
Controlling the number of enemies spawned
18

Controlling the number of enemies spawned

 
09:27
Creating a basic enemy script to use our waypoints
19

Creating a basic enemy script to use our waypoints

 
08:49
Moving with the Smooth Damp method
20

Moving with the Smooth Damp method

 
10:39
Deciding when to go to the next waypoint
21

Deciding when to go to the next waypoint

 
07:51
Using Rotate Towards and Look Rotation to rotate the enemy
22

Using Rotate Towards and Look Rotation to rotate the enemy

 
12:47
Refactoring our code into a new function
23

Refactoring our code into a new function

 
12:30
Updating the Player Location list so the enemies don't stop
24

Updating the Player Location list so the enemies don't stop

 
09:07
Refactoring into an infinite loop function to update waypoints
25

Refactoring into an infinite loop function to update waypoints

 
08:23
Creating a basic Finite State Machine to run our enemy AI
26

Creating a basic Finite State Machine to run our enemy AI

 
09:09
Using a Switch statement to run code based on the enemy state
27

Using a Switch statement to run code based on the enemy state

 
07:27
Creating a function to check for transitions
28

Creating a function to check for transitions

 
06:41
Adding a distance check before the enemy starts following
29

Adding a distance check before the enemy starts following

 
08:09
Transforming the enemy forward in the start state
30

Transforming the enemy forward in the start state

 
11:11
Importing our final geometry and splitting animations
31

Importing our final geometry and splitting animations

 
08:19
Updating our enemy prefab with the new geometry
32

Updating our enemy prefab with the new geometry

 
11:18
Changing our enemy animation in code with animation play
33

Changing our enemy animation in code with animation play

 
09:29
Coding an attack decision into our transition function
34

Coding an attack decision into our transition function

 
10:13
Telling our Spawn Controller when an enemy has died
35

Telling our Spawn Controller when an enemy has died

 
10:00
Changing our movement speed based on the current state
36

Changing our movement speed based on the current state

 
07:47
Refactoring our code to be more readable and user friendly
37

Refactoring our code to be more readable and user friendly

 
05:58
Playtesting our enemy AI and hunting down bugs
38

Playtesting our enemy AI and hunting down bugs

 
06:48
Using random values to create more realistic movement
39

Using random values to create more realistic movement

 
08:03
Adding a collider to our prefab for hit testing
40

Adding a collider to our prefab for hit testing

 
06:24
Testing if we have been attacked or hit
41

Testing if we have been attacked or hit

 
09:08
Coding for other notifications to work in our game
42

Coding for other notifications to work in our game

 
08:03
Stopping the animations from playing while paused
43

Stopping the animations from playing while paused

 
08:52
Stopping the logic from running when the game is over
44

Stopping the logic from running when the game is over

 
06:36