in unity any scene with the navmesh can
easily be navigated by a game object
with a nav mesh agent component here we
have a scene in unity the scene already
has a nav mesh baked the scene also has
an empty game object which will be the
target of our navigation finally there
is a capsule which we will apply our nav
mesh agent to the capsule has a sample
agent script attached this script has a
public variable target which is already
set to our empty game object named
target
to add a nav mesh agent click the add
component button in the inspector view
and select navigation nav mesh agent the
agent has several settings which we can
modify to change its behavior the radius
represents the radius of the agent while
the speed is the agents max speed the
acceleration is how quickly the agent
will accelerate and the angular speed is
how quickly the agent can turn the
stopping distance property represents
the distance from the target that the
agent will begin slowing down Auto
Traverse off mesh links dictates whether
or not the agent will utilize off mesh
links automatically more information on
off mesh links can be found in the
lesson linked below Auto braking
determines if the agent will break when
nearing its destination leaving this
checked we'll stop the agent from
overshooting its target auto repast will
allow the agent to rebuild its path if
its current path becomes invalid the
height property is the height of the
agent the base offset is the vertical
offset of the agents Collider the
obstacle avoidance type has several
options at higher qualities avoidance is
more accurate at lower qualities
avoidance is more efficient the
avoidance priority determines which
agents have priority when navigating
agents of a higher priority should have
a lower number finally the navmesh
walkable property tells the agent which
navigation layers it can traverse
for more information on navigation
layers see the lesson on navmesh baking
linked below it is worth noting that
while we can change these properties to
achieve a large range of effects the
default properties will work for most
situations once the nav mesh agent
component is applied and configured we
only need to tell it where to go
in our sample agent script we can see
that we first declare a variable of type
nav mesh agent named agent in the start
method we get a reference to our nav
mesh agent and store it in our agent
variable using the get component
function in order to tell our agent
where to go we use the set destination
method of the nav mesh agent class this
method reads in a single vector 3 in
this instance we will call the set
destination method by typing agent dot
set destination then in the parentheses
we will type target dot position this
tells our agent to move towards the
target game object back in unity we can
run our scene we will notice immediately
that the capsule game object begins
moving and traversing our level the
capsule will eventually reach our target
game object and come to a stop