CarTutorialSection 1, Tworzenie gier, ! Unity3D v3.x, Tutorials
[ Pobierz całość w formacie PDF ]
“The Car Tutorial” Part 1
Creating a Racing Game
for Unity
unity
“The Car Tutorial”― Creating a Racing Game for Unity, Part 1
Introduction
3
Skidmarks
11
We will show
3
Max Marks
12
Prerequisites
3
Mark Width
12
We will not show
4
Ground Offset
12
Part 1: Assembling the Car
5
Min Distance
13
Adding Collision
6
Texture
13
Shadow settings for the car model
7
Adding Sound
14
Adding the Car’s Components
8
Finalizing the Assembling
15
Adding a blob shadow
10
unity
“The Car Tutorial”― Creating a Racing Game for Unity, Part 1
Introduction
The aim of this tutorial is to show you how to create a racing game with Unity. We are going to
assemble a car from a 3d model, scripts and Components. We provide you with a complete project
of a driving game, where you can play with a fi nished scene and explore how everything is put to-
gether. We also provide you with a scene that has everything ready but the car, which you will then
work on completing.
We will show
Let us begin by talking about what this tutorial will deal with. It is divided into three distinct sec-
tions that can worked on independently of each other:
1. Assembling the Car
How to assemble a Car Prefab from a 3D model, scripts and components. This is the section you are
reading right now.
2. Tweaking the Car
How to tweak the car to behave “better” or in different ways.
3. Under the Hood
A more in-depth look at the actual code that drives the car.
Prerequisites
The tutorial is not intended as an entry point to learning Unity. You should have a basic under-
standing of how Unity is organized, what a GameObject is, what Components are and so on. Some
3
unity
“The Car Tutorial”― Creating a Racing Game for Unity, Part 1
profi ciency in scripting is also recommended. This being said, we will explain a lot of stuff along
the way, basic and advanced.
We will not show
•
All the other scripts.
•
The very basics. We will not go in depth with explaining the basic workfl ow and components in
Unity. For that there are many other resources available at:
The User Manual and the Scripting Reference are valuable companions as you follow along this
tutorial. We suggest that you visit these resources when ever you encounter a built in Component
or function that you’d like to know more about.
The approach taken at fi rst is that of code monkey see, code monkey do: You follow the instruc-
tions we give about putting a car together and changing it’s variables. Hopefully you will be curi-
ous about how it works, learn something from seeing how everything is put together and do some
investigation on your own. Feel free to explore.
In the last and longest section we dive more deeply into the actual code that makes the car drive.
This is not a line-by-line walkthrough, but we will cover most of what is going on. One way to learn
programming or improve ones skills is to look at a lot of code (supplemented by doing a lot of
programming). We are certain that you will learn a lot from following this closely and getting an
understanding of how the code works together.
4
unity
“The Car Tutorial”― Creating a Racing Game for Unity, Part 1
Part 1: Assembling the Car
Start by opening the scene named ‘
CompleteScene
’. This scene has the car already setup, so you
can try it out by pressing the Play button. This will show you the end result of what we are going
to build.
When you are done playing around, open the scene named
‘
TheTrack
’. This scene contains what is needed to race, except the
most important part - a car.
Now drag the car model into the Scene. In the Project view you fi nd it under
Models/Car/catamount.
Depending on where you dragged the car, you probably want to change it’s position to a more
suitable one. I suggest that you change its position in the inspector to something like (860, 102.3,
878) and set it’s y-rotation to 130.
For the rest of the tutorial, this GameObject will be referred to as ‘
Car
’ so you might as well
rename it now.
This is just the 3D model of the car. If you look in the Inspector, you will see that it contains a num-
ber of children such as the car’s body, windows and wheels. It also contains two simple meshes that
5
[ Pobierz całość w formacie PDF ]