WEBVTT

0
00:09.660 --> 00:15.390
In this lecture, I'll introduce you to a powerful concept using A.I. navigation called Navigation Meshes,

1
00:15.660 --> 00:23.100
or NavMeshes. NavMeshes are a built-in Unity feature and are used to divide an environment up into navigatable

2
00:23.160 --> 00:29.370
areas which the A* algorithm can then be used on for pathfinding. The method (originally called

3
00:29.370 --> 00:32.520
a meta map) was developed for robotic applications

4
00:32.520 --> 00:38.250
in the mid-1980s. It became more popular in the 2000s for use in games.

5
00:38.250 --> 00:43.140
A navmesh divides a model into a series of polygons and assigns a cost to each.

6
00:43.260 --> 00:49.260
This cost is considered in the pathfinding algorithm in determining the best path for an A.I. to take.

7
00:49.320 --> 00:52.560
We call the A.I. using a navmesh an 'Agent'.

8
00:52.590 --> 00:59.940
This is a generic term originating in traditional A.I. where words like NPC, Agent and Bot all mean the same

9
00:59.940 --> 01:01.050
thing.

10
01:01.080 --> 01:08.850
There are four tabs in the Unity navigation system for setting up a navmesh: Agents, Areas, Bake & Object.

11
01:08.940 --> 01:10.740
The first defines an Agent.

12
01:10.830 --> 01:16.590
An agent has 4 main properties that you can set to define the character size and movement abilities.

13
01:16.590 --> 01:21.690
These are used by a navmesh to determine where a character can and can't go in the environment.

14
01:21.690 --> 01:27.120
NOTE: They are not based on the properties you might set in the physics system, nor are they based on

15
01:27.120 --> 01:29.250
the model size you are using,

16
01:29.300 --> 01:35.900
so set these carefully. The size of an agent is defined by a cylinder that the character would fit within.

17
01:36.000 --> 01:42.540
It has a radius for determining how wide your character is and a height. It is generally assumed the character

18
01:42.540 --> 01:48.720
will be navigating across a flat terrain, but in the case of slopes and steps, you need to declare the gradient

19
01:48.810 --> 01:55.240
of slopes accessible by the character, as well as the height of stairs that it can access. The Agents

20
01:55.240 --> 02:00.270
tab will also let you define different sized agents by adding more than one type.

21
02:00.270 --> 02:05.600
This allows you to have many types of agents, all with differing sizes and navigation abilities.

22
02:05.640 --> 02:10.650
The Areas tab is where you can define different costs for different parts of the navmesh.

23
02:10.650 --> 02:16.530
The cost is used by the A* algorithm to calculate the best path across the mesh from one location

24
02:16.530 --> 02:17.340
to another.

25
02:17.520 --> 02:23.370
There are 3 built-in types that are used to set different parts of a mesh to walkable, not walkable

26
02:23.460 --> 02:24.780
and jumpable. To these,

27
02:25.050 --> 02:26.500
you can add your own.

28
02:26.760 --> 02:32.890
Any area type can be included or excluded in an agent's pathfinding search across the terrain.

29
02:33.090 --> 02:38.140
This makes it possible to have some characters unable to traverse water or walk through doorways.

30
02:38.190 --> 02:41.040
The Bake tab turns your meshes into a navmesh.

31
02:41.160 --> 02:46.200
It does this by dividing the mesh into numerous polygons and determines where the agent should be able

32
02:46.200 --> 02:49.200
to travel using the Baked Agent Size.

33
02:49.200 --> 02:55.050
When you create a navmesh in the Bake tab, it uses this agent size and not the sizes you set up in the

34
02:55.080 --> 02:56.770
Agents tab.

35
02:56.850 --> 03:03.570
By default, the 'Humanoid' agent type is the only agent type recognized by the navmesh and even though you

36
03:03.570 --> 03:09.690
can define multiple agent types in the Agent tab, you can only use Humanoid in the set up given to you

37
03:09.690 --> 03:10.980
via Unity.

38
03:10.980 --> 03:16.140
Having said that, there are beta components available that'll allow you to set up different navmeshes

39
03:16.140 --> 03:21.600
for different agent types and we will look at this in later workshops. Other bake settings include

40
03:21.600 --> 03:24.030
being able to generate 'Off Mesh Links'.

41
03:24.060 --> 03:28.550
These define how far across a gap in the mesh an agent can fall or jump.

42
03:28.590 --> 03:34.680
The detail of the navmesh can be set using the 'Manual Voxel Size' setting. Voxels are a data structure used

43
03:34.680 --> 03:38.040
to divide the world up, before the navmesh is constructed.

44
03:38.310 --> 03:42.940
The bigger the voxel size, the less accurate the navmesh as bigger world divisions

45
03:42.990 --> 03:50.580
will miss some of the detail in the mesh. This value is usually set to 3 per Agent Radius. You are aiming

46
03:50.580 --> 03:56.470
for values around 2 and 4. The 'Min Region Area' allows you to move sections of the mesh that

47
03:56.470 --> 04:01.920
were calculated as navigatable but are too small to be of any use and you don't really want them included

48
04:01.920 --> 04:06.540
in the pathfinding. By increasing the minimum region area and rebaking,

49
04:06.570 --> 04:10.950
you can remove these small areas. When a navmesh is generated for a bunch of meshes,

50
04:10.980 --> 04:15.810
it averages out the height and can do things like turning stairs into a slope.

51
04:15.810 --> 04:21.240
If this is not the effect you're after, then you can turn on the 'Height Mesh' box before baking.

52
04:21.240 --> 04:23.920
This will include height values into the mesh.

53
04:24.090 --> 04:27.060
It will also take up more memory and baking time,

54
04:27.060 --> 04:29.170
so don't be too generous with its use.

55
04:29.220 --> 04:35.580
The last tab (the Object tab) is where you can align specific area types to different parts of your mesh.

56
04:35.580 --> 04:38.560
These are the areas defined in the Areas tab.

57
04:38.820 --> 04:44.940
This tab also allows you to specify which parts of your scene you want to create a navmesh for, as

58
04:44.940 --> 04:51.230
well as generating off mesh links that allow you to transition from one navmesh to another. Navmeshes

59
04:51.240 --> 04:56.450
are a powerful system to get your NPCs moving with very little effort on your behalf.

60
04:56.580 --> 05:03.140
With them, you can create all types of scenarios from patrols and crowds, to traffic and flocks. In this section

61
05:03.150 --> 05:08.370
we will examine some of the fundamental elements that make navmeshes work and create some examples

62
05:08.370 --> 05:10.230
that really demonstrate their power.