Game Development Reference
In-Depth Information
This is how the road navigation mesh setup should look.
This should have been pretty quick to recreate, but depending on the character size
settings and the amount of geometry in the scene, this can take a bit of time. We will
discuss navigation meshes more and the algorithm behind how they are generated
in Chapter 11 , Advanced NavMesh Generation .
Note
NavMeshAgent is the built-in Unity component to create characters that move
on a navigation mesh. Smart Car uses this internally. We won't be using this
class directly but you can if you want to try more of Unity's built-in navigation sys-
tem; it is a good class to look at.
Setting up waypoints
The final step to get a car driving is to set up waypoints for the car to follow. The
NavMesh we created defines the area that the car can navigate to and the waypoints
define the general path the car should follow. Create a new empty game object and
name it Road Waypoints . Then, create a few more empties with the names way-
point 1 , waypoint 2 , waypoint 3 , and so on. Place the waypoint empties at different
parts along the road. Note that the NavMesh for the road will define how to get from
one waypoint to the next, so the line between waypoints doesn't have to go through
the road. For instance, you could have one waypoint at the start of a curve and the
second at the end and the car would still go around the curve through the waypoints.
In the Smart AICar script, set the empties to the Waypoints field. After doing this,
Search WWH ::




Custom Search