Game Development Reference
In-Depth Information
Pathfinding
Pathfinding is how the AI will maneuver around the level. For our AI package, we will
be using two different kinds of pathfinding, NavMesh and waypoints. The waypoint
system is a common approach to create paths for AI to move around the game level.
To allow our AI to move through our level in an intelligent manner, we will use Unity's
NavMesh component.
Creating paths using the waypoint system
Using waypoints to create paths is a common practice in game design, and it's simple
too. To sum it up, you place objects or set locations around the game world; these are
your waypoints. In the code, you will place all of your waypoints that you created in a
container of some kind, such as a list or an array. Then, starting at the first waypoint,
you tell the AI to move to the next waypoint. Once that waypoint has been reached,
you send the AI off to another one, ultimately creating a system that iterates through
all of the waypoints, allowing the AI to move around the game world through the set
paths. Although using the waypoint system will grant our AI movement in the world,
at this point, it doesn't know how to avoid obstacles that it may come across. That
is when you need to implement some sort of mesh navigation system so that the AI
won't get stuck anywhere.
Unity's NavMesh system
The next step in creating AI pathfinding is to create a way for our AI to navigate
through the game world intelligently, meaning that it does not get stuck anywhere. In
just about every game out there that has a 3D-based AI, the world it inhabits has all
sorts of obstacles. These obstacles could be plants, stairs, ramps, boxes, holes, and
so on. To get our AI to avoid these obstacles, we will use Unity's NavMesh system,
which is built into Unity itself.
Setting up the environment
Before we can start creating our pathfinding system, we need to create a level for our
AI to move around in. To do this, I am just using Unity primitive models such as cubes
and capsules. For the floor, create a cube, stretch it out, and squish it to make a rect-
Search WWH ::




Custom Search