UnrealScript Game Programming Cookbook

(Chris Devlin) #1

AI and Navigation


112

NavigationPoints are laid on a map by the designer, and are used to illustrate where they do
and do not wish for pawns to be able to move to. When the level is built, the NavigationPoints
will produce ReachSpecs between them. The ReachSpec data is then used by the game's
pathfinding, which in turn allows AI to pathfind from one point to the next and judge the most
efficient way of maneuvering about it. Path searches are initialized from Anchors, which
are navigation points that the AI can reach directly, without having to perform pathfinding.
Pathfinding starts by searching for a start and end point and then calculating the most
efficient way to navigate the points between the two to reach the end goal.


WayPoints make use of the FindPathToward function, which will determine the path
network route from the anchor to goal. First, it checks to see if the pawn is valid and then
takes a glance at all of the nodes across a path. This information is then stored in the
RouteCache of the AI Controller.


PathNodes can be anything from a PlayerStart (subclass of NavigationPoint), as well as any
of those pickups we've created in the previous tutorials. As a general rule, PathNodes should
be less than 1200 Unreal units apart to prevent issues with the AI not being able to find
the path, although this can be modified in MAXPATHDIST, which is an internal variable of
NavigationPoint. Essentially, level designers want to place PathNodes throughout an entire
map in order to allow the AI to better navigate the playable area and not waste any time
creating art and assets that players will never see or use.


Benefits of WayPoints


While WayPoints may be a bit more work and cause a bit more clutter on a map, they are
great when you want to tell the AI precisely where to go. For example, if you wanted to create a
scenario where you have AI pawns flanking on either side of you, this could easily be arranged
by assigning them to make use of pre-set WayPoints when you run over a trigger.


Moreover, WayPoints are great for when you have actors of different sizes making use of
a tight environment. Perhaps you only want pawns to be able to access an area and not a
vehicle. Well then, WayPoints are the way to go for relaying this information to the game.


Above all else, WayPoints are all about precision and allow you to have complete control
over how pawns can traverse an environment. You tell them exactly where they can and
cannot explore.


NavMeshes


NavMeshes take an alternative approach to pathfinding. NavMeshes attempt a more accurate
representation of an AI's configuration space via a connected graph of convex polygons, as
opposed to representing the world as a series of connected points. Through the use of a node,
which is essentially a polygon, the AI can maneuver from any point in that node, or any other
point in any connected node, due to its convexity.

Free download pdf