FPS_Tutorial_1.pdf

(2606 KB) Pobierz
FPSTutorialPart1
Creating
a
First
Person
Shooter
(FPS)
Part
1
Author:
Graham
McAllister
Revised
by:
Jeff
Aydelotte
&
Amir
Ebrahimi
Time
to
complete:
3­4
hours
Last
Revision:
10­July­2009
197802958.013.png 197802958.014.png
Contents
1. Part 1: Introduction
Prerequisites

3
Starting
a
new
project

3
Setting
up
the
game
environment

4
Adding
the
Main
Character

4
Adding
a
weapon

5
Create
the
Missile
object

6
Missile
explosions

10
Sound
effects

13
Adding
a
GUI

13
Physics

15
Acknowledgments

19
197802958.015.png
Part
1:
Introduction
This
tutorial
will
detail
how

to
make
a
simple
First

Person
Shooter
(FPS).
It
will

introduce
fundamental
3D

game
programming

concepts
and
give
tips
on

how
to
think
like
a
game

programmer.
Prerequisites
This
tutorial
assumes
that
you
are
familiar
with
the
Unity
interface
and
basic
scripting

concepts.
Starting
a
new
project
Download

FPS_Tutorial.zip,

unzip,
and
open
the

project
folder
in

Unity.
Import
the
Standard

Assets
Unity
Pack­
age
from
your

Standard
Packages

folder
where
Unity

is
installed.
After
importing,
you
will

see
Unity’s
built
in
"Stan­
dard
Assets"
in
the
Project

Panel.
When
we
create
new
assets,
it’s
best
to
put
them
in
folders
that
group
them

according
to
their
function,
e.g.
Rocket,
Explosion,
Audio
,
etc.
197802958.016.png 197802958.001.png 197802958.002.png 197802958.003.png
Setting
up
the
game
environment
Once
the
assets
have
been
imported,
you’ll
notice
there
are
many
folders
in
the
Pro­
ject
panel.
In
the
Projects
panel,
Select
the
mainLevelMesh
from
 Objects/mainLevelMesh/
mainLevelMesh .
In
the
Inspector
panel,
inside
of
the
FBXImporter
options
you’ll
find
the
"Gener­
ate
Colliders"
option.
Toggle
that
option
on.
If
we
don’t
do
this,
the
player
will

simply
fall
through
the
level
(no
collision).
Drag
the
mainLevelMesh
into
the
scene.
 
There
is
no
need
to
add
a
light
to
the
scene,
the
level
is
already
fully
lightmapped.
The

imported
level
uses
lightmaps
for
all
lighting
which
allows
us
to
use
pre­baked
shad­
ows.
Lightmaps
are
very
good
for
performance,
especially
if
you
want
to
create
a

complex
lighting
setup.
You’re
now
ready
to
add
a
character
into
the
environment.
Adding
the
Main
Character
We’re
now
going
to
add
in
a
character
for
the
player
to
control.
Unity
has
a
built
in

prefab
specifically
for
a
first­person
controller.
This
can
be
found
in
the
Project
panel

under
Standard
Assets­>Prefabs.
To
add
the
First
Person
Controller,
click
on
the
arrow
beside
Standard
Assets
in

the
Project
panel,
as
list
of
assets
will
appear.
Find
the folder
called
Prefabs
and

click
on
the
arrow
in
the
left
hand
side.
You
should
now
see
the
First
person

controller
asset.
Drag
this
into
the
Scene
view.
4
197802958.004.png 197802958.005.png 197802958.006.png 197802958.007.png 197802958.008.png
You
should
see
a
cylinder
object
representing
the
player,
3
large
arrows
for
al­
tering
the
location
in
3D
space
for
the
object
(if
you
do
not
see
3
arrows
then

press
the
‘W’
key),
and
a
white
mesh
which
shows
the
object’s
viewport
(where

it
is
currently
looking).
The
FPS
Controller
is
now
the
default
camera,
by
moving

this
object,
you
change
the
current
view
in
the
Game
View.
You’ll
also
notice

that
the
FPS
Controller
has
a
camera
icon
on
top
of
it.
Move
the
character
so

that
it
is
above
ground
level
in
the
environment.
As
we
no
longer
have
any
need
for
the
Main
Camera,
you
can
delete
it.
Press
Play,
you
should
now
be
able
to
move
around
the
level
by
using
the
mouse

and
keyboard
(cursor
keys
to
move
or
W,A,S,D).
 
You’ve
now
created
a
very
simple
FPS,
let’s
give
the
player
a
weapon.
Adding
a
weapon
We’re
now
going
to
give
the
player
a
grenade
type
object
to
throw
in
the
environ­
ment.
To
do
this,
you’ll
need
to
create
some
Javascript
to
tell
Unity
about
the
behavior

of
the
weapon.
So
what
do
we
want
to
do?
We
want
to
allow
the
player
to
shoot
wherever
the
cam­
era
is
pointing.
However,
let’s
first
think
about
our
game
character
and
their
weapons.

Our
game
character
is
seen
through
the
first
person
view,
with
the
camera
positioned

at
eye
level.
If
the
player
fires
a
weapons,
the
weapon
should
be
launched
from
wher­
ever
their
hands
are,
not
from
eye
level.
This
means
we
have
to
add
in
a
game
object

to
represent
the
grenade
launcher,
and
place
it
where
the
player’s
hand
would
be

when
they
hold
this
weapons.
This
ensures
that
the
object
fires
from
the
correct

location. 
5
197802958.009.png 197802958.010.png 197802958.011.png 197802958.012.png
Zgłoś jeśli naruszono regulamin