Home and Learn: Games Programming Course
Using the project in the last lesson, click on your Capsule in the Hierarchy to select it. In the Inspector on the right, take a look at the Nav Mesh Agent settings:
The agent itself is an upright cylinder surrounding your character. When your character moves, the cylinder moves with it. With that in mind, here are the settings you can change.
Agent Type - Default is Humanoid. But you can add other types by clicking the dropdown and selecting the option Open Agent Settings:
You'll see this dialogue box:
Click the plus button to add a new agent type. But here, you can set a few things for your new character:
Radius - How wide a cylinder do you
want for your character
Height - How high should your cylinder be
Step Height - How high the steps should be that the character can
climb up. Set this to a low value and the character won't be able to climb
stairs.
Max Slope - The angle in degrees that a character can walk up.
Set this to 0 if you don't want a character to be able to walk up a slope.
Drop Height - the highest distance
a character can drop from one height to another
Jump Distance - the longest distance a character can jump from
one point to another
Now back to the Nav Mesh Agent Settings.
Base offset - Sometimes, your characters have an origin or anchor point that's different from normal. Change the Base offset if your character is not moving as it should.
Steering
Speed - how fast character can move
Angular Speed - how fast a character can turn, measured in degrees
per second
Acceleration - the maximum acceleration, measured in world units
per second squared
Stopping Distance - stopping distance from the destination
Auto Break - agent slows down when approaching destination. Uncheck
this if you don't want agents slowing down when reaching the destination
Obstacle Avoidance
Radius - distance from obstacles.
(Usually the same as the Radius you saw above.)
Height - height distance from obstacles. (Usually the same as the
Height you saw above.)
Quality - helps so that agents don't overlap with obstacles. The
higher the quality the more processing time
Priority - agent ignores other agents with a lower priority
Path Finding
Auto Traverse OffMesh Links - used
for linking to other areas of the mesh, such as platform the character
can jump onto but enemies can't. Unity recommends turning this off if
you have some other way to traverse off mesh links.
Auto Repath - recalculates to get to destination in shortest possible
time
Area Mask - Areas agent can walk on
Now let's look at the settings for the NavMeshSurface itself
Take a look at the settings for the Nav Mesh Surface:
The blue cylinder is the one we talked about earlier, the one surrounding the character. This surface allows characters to climb stairs with a step height of up to 0.75 and a slope of up to 45 degrees. It's set up for Humanoid agent types with a radius is 0.5 and a height of 2. So any characters walking on this surface should be able to squeeze through narrow arches, but they may have to duck, as they could be too tall.
The default Area is set to be Walkable, meaning all characters using this surface can walk upon it. Click the dropdown and you'll see the other options: Non-Walkable, Jump. You can also open the area settings to create customizable areas.
Let's go through the other settings:
Generate Links: Check this if you
want a character to be able to navigate things like platforms with different
heights. You can then set up NavMeshLinks.
Use Geometry - the two options are Render Meshes and Physics
Colliders. Basically, an agent can move closer to objects with a collider
attached to it than they can if there is no collider but just the mesh.
Object Collection (Which Game Objects do you want to Bake into the surface)
Collect Objects - You have four options
here: All Game Objects, Volume, Current Objects Only, NavMeshModifier
Components Only. The Volume refers to a bounding volume you can
set up. Current Objects Only are objects you select in the Hierarchy,
and NavMeshModifier Components Only are game objects that you have
set up to have a Nav Mesh Modifier Component.
Include Layers - lets you select which of your layers you want
to include in the Bake.
Advanced
Override Voxel Size - (A voxel is like a pixel but in 3 dimensions.) Large, open areas can be slow to bake, so you can set a lower voxel size like 1 or 2 to speed up baking. But the baking accuracy suffers. Indoor areas are usually quick to bake so you can set a higher voxel size of 4 to 6. This gives better accuracy for baked objects. Unity doesn't recommend going higher than 8 for your voxel size as there is no benefit to doing so.
Override Tile Size - If you look at a baked surface, you should be able to see some white lines. This is because the baked area is split up into different sections called Tiles. The white lines are tile boundaries. 256 is the default size and it's a value measured in voxels. Basically, the higher the figure here the more memory your game will consume. The lower the figure the worse your characters will be when traversing the NavMesh.
Minimum Region Area - used to cull
surfaces that you don't really care about. Best just leave this on the
default of 2.
Build Height Mesh - This is a good box to check for greater accuracy when
characters are climbing things like stairs. Unchecked, and it will look
like your characters just glide up the stairs. Checked, you will see your
characters actually walk up the stairs more realistically.
Now that you know how to move an AI character to a destination, let's get an AI Character to patrol. We'll do that in the next lesson below.
<--Back to the Unity 3D Course Contents Page
Email us: enquiry at homeandlearn.co.uk