Game Development Reference
In-Depth Information
Adding NpcRacers to the mission
To make the race compelling and interesting, we will create two NPC racers to chal-
lenge the player. If it turns out well, we can build most of these with the technology we
have already developed.
Each racer will need a spline to follow. Recall from the previous chapter that we deve-
loped a system for placing waypoints in the scene and using the
SplineMgr
script to
generate a smooth curve for an NPC to follow. This will define the smooth path they
traverse from start to finish. To implement the other racers in the level, carry out the
following steps:
1. Create an empty GameObject, and name it
_splineDataA
. Create a series of
sphere game objects, and place them in a path from start to finish. Disable the
mesh renderer of these objects, and then parent them all to
_splineDataA
.
2. Create a second
_splineData
object with different path nodes so that the
second racer will follow a similar but not identical route through the course.
Name it
_splineDataB
.
3. Parent these two
_splineData
objects to the
_level2
root level object's con-
tainer to ensure our level loading strategy remains simple and elegant.
4. As with the player, create a placeholder model for the racers, which is com-
posed of a capsule with a rectangular hat parented to the top. Name them
RacerA
and
RacerB
respectively.
Associated Technology
). Associate
_splineDataA
to the path reference on
this script. Make sure the
DecisionMgr
member is empty; we won't be using
it for the racers' logic. The structure of
RacerA
should then resemble the fol-
lowing figure: