Game Development Reference
In-Depth Information
Note More information on lightmapping in Unity can be found at the Unity online documentation at
http://docs.unity3d.com/Documentation/Manual/LightmappingInDepth.html .
Step 11: Building a Navigation Mesh
Later in this topic, we'll be creating three distinct Enemy characters to which we've been introduced
already. These are the Drone , the Tough Guy , and Mr. Big Cheese To see these characters, check
out Figures 1-2, 1-3, and 1-4 in Chapter 1. As mentioned, these enemies will be “intelligent.” I use
the word intelligent here in a narrow and precise sense. I mean the characters will not simply stand
around the scene motionlessly doing “nothing,” like props or inanimate objects. Instead, they'll move
around and actively search for the Player. This process of “moving around” and “searching” for the
Player involves intelligence.
The scene I've created for CMOD—assembled from environment pieces—consists of larger rooms
connected by narrow and winding corridors, as shown in Figure 2-29 . These corridors have twists
and turns, and they also connect with one another to form junctions, points at which it's possible to
travel in more than one direction. This kind of scene layout means that anytime an Enemy needs to
move, it must make reasoned decisions about where it should go and how it should get there. The
enemy shouldn't simply walk through walls and material objects. It's supposed to avoid these. This
kind of obstacle avoidance is known as navigation . Further, the enemy should move in a determined
and concerted way, travelling from one point to a clear destination elsewhere, as opposed to moving
erratically backward and forward with no sense of direction at all. This kind of route planning is known
as pathfinding . Both of these concepts are achieved in different ways in Unity, but perhaps the most
common is through navigation meshes . The details of implementing navigation and pathfinding are
considered in Chapter 7. However, in getting started with this project, and in generally building the
scene, some preliminary steps must be taken here for pathfinding. Specifically, we'll build or bake a
navigation mesh, much like we baked lighting through lightmaps. The navigation mesh will be used
later in Chapter 7, when creating enemies.
Note Most navigation mesh features are included in the Unity free version, as of Unity 4.3. However,
off-mesh links (for connecting multiple NavMeshes), are a Pro Only feature.
In Unity terminology, an enemy is an agent (or more fully a NavMesh Agent ). A NavMesh Agent is
simply any GameObject that must intelligently move around the scene when required. Whenever an
agent is told to move toward a destination (any Vector3 location within the scene), it first needs to
plan the most sensible route based on its current position, and then to follow that route while avoiding
 
 
Search WWH ::




Custom Search