Game Development Reference
cars, Grand Theft Auto requires the player to race away from authorities
or to locations, and Kinect Sports allows players to race in track and field
Racing need not involve people or vehicles moving around a track.
Performing a task within a certain time is racing against the clock . In The Sims ,
for example, a player's Sims can be given packages to deliver downtown or
tasks to perform within a specified time period. If the job gets done, the Sim is
Unity Hands On
In this hands-on session you will create a simple racing game.
Step 1. Download Chapter Four/Racing.zip from the Web site. Unzip
and open the project in Unity. Open the scene called racing . In the
game you will see a terrain and a car.
Step 2. Play. The car can be driven with the arrow keys. The Main
Camera is attached to the car prefab, such that when the car moves,
the camera automatically moves too.
Step 3. Select the car prefab in the Hierarchy. Right-click on it and
select Duplicate. Call the duplicate Player2 . Select Player2 and in the
Scene move it so the cars sit side by side.
Step 4. Select Player2 in the Hierarchy and delete the Car script
component in the Inspector. Also delete the Main Camera object
attached to Player2. This isn't needed as the original car already
has a camera.
Step 5. Add a sphere to the Scene. Select it in the Hierarchy and
delete the Sphere Collider component. Position the sphere in
front of Player2 raised slightly above the ground. We are going
to use a series of spheres as points to specify a path for Player2
to follow. This is a common technique used in games to direct
the movement of nonplayer characters (NPCs). Each sphere acts
as a waypoint.
Step 6. Number and duplicate the sphere; place the duplicate
farther down the road as shown in Figure 4.10 (you may want to
increment the sphere number). Each waypoint should be in line
of sight of the other. Because the NPC is traveling in a straight line
between each waypoint, if they are on the other side of the terrain,
the NPC will travel through the terrain mesh. This won't look real or
be very fair to the human player.
Step 7. Continue duplicating and positioning spheres until the whole
track is covered.