FPS_Tutorial_3.pdf

(2170 KB) Pobierz
FPSTutorialPart3
Creating
a
First
Person
Shooter
(FPS)
Part
3
Author:
Graham
McAllister
Revised
by:
Jeff
Aydelotte
&
Amir
Ebrahimi
Time
to
complete:
3­4
hours
Last
Revision:
10­July­2009
197804000.021.png 197804000.022.png
Contents
1. Part 3: Advanced FPS
Prerequisites

3
Setting
up

3
Waypoints

3
Robot
AI

4
Robot
Damage

5
Ragdolls

6
Sound

7
GUI

8
Finally...

9
The
end
of
the
beginning...

10
197804000.023.png
Part
3:
Advanced
FPS
This
advanced­level
tutorial

extends
upon
the
previous

FPS
tutorials
by
introducing

game
elements
such
as

waypoints,
enemy
AI,

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

concepts.
Additionally,
you
should
already
be
familiar
with
the
concepts
discussed
in

Part
1
and
2
of
the
FPS
tutorial
series.
Setting
up
We’re
going
to
build
upon
the
previous
FPS
tutorial,
so
we’ll
begin
by
opening
that:
Open
the
previous
project
(FPS
Tutorial
2).
Waypoints
This
section
will
introduce
waypoints
to
our
game,
these
are
used
to
inform
the
robots 

of
the
path
that
they
can
walk
around. 
Let’s
add
three
waypoints
to
our
game:
Create
an
empty
game
object
and
rename
this
to
Waypoint. 
Make
sure
the

game
object
is
placed
approximately
one
meter
above
the
ground
level.
Add
AutoWayPoint
script
to
Waypoint. 
Notice
how
the
empty
game
object
now

displays
a
W
in
the
Scene
View.
Duplicate
the
WayPoint
game
object
twice
and
arrange
the
waypoints
in
a
tri­
angle
shape
(position
quite
far
apart).
197804000.024.png 197804000.001.png 197804000.002.png 197804000.003.png 197804000.004.png
Check
that
the
waypoints
are
visible
to
each
other
by
firstly
clicking
on
any
way­
point
then
selecting
Update
Waypoint
from
the
context
menu
of
the
AutoWay­
Point
script
(the
right­most
button
on
the
component
in
the
Inspector
View). 
A

green
line
will
be
drawn
between
visible
waypoints,
a
red
line
for
those
which

don’t
have
a
clear
line
of
sight.
We
have
now
described
the
path
that
an
enemy
can
walk
around,
now
let’s
add
an

opponent
to
the
scene.
Robot
AI
This
section
will
add
an
enemy
robot
to
our
scene.
Select
Robot
Artwork/robot
and
drag
it
into
the
Scene
View
making
sure
all
of

the
robot
is
above
the
ground.
Let’s
give
the
robot
some
behavior.
Add
WeaponsScripts/AI
to
robot. 
In
the
AI
script
section
or
robot,
assign
the
FPS

controller
as
the
target
(so
the
robot
knows
who
to
hunt
down).
Add
the
AIAnimation
script
to
the
robot. 
This
controls
the
animation
of
our
ro­
bot
(when
to
run,
when
to
aim
etc). 
This
communicates
with
the
AI
script
to

find
out
what
the
AI
script
is
currently
doing,
e.g.
are
we
running,
shooting
etc. 

It
then
crossfades
the
animations
to
provide
a
smooth
transition.
Now
we
need
to
make
the
robot
controller
object
a
little
larger
so
that
he
doesn’t
in­
tersect
with
the
ground. 
This
is
because
the
character
controller
which
is
used
to
pre­
vent
the
enemy
from
moving
through
walls
is
using
a
capsule
to
represent
the
AI. 
We

need
to
make
this
capsule
a
little
larger
to
match
the
actual
graphics,
this
way
he
will

not
intersect
with
the
ground
anymore.
Select
the
robot,
then
in
the
Inspector
View
modify
the
height
and
radius
values

of
the
Character
Controller
component
so
that
it
encloses
the
robot. 
Press
play

to
make
sure
it
works
correctly. 
4
197804000.005.png 197804000.006.png 197804000.007.png 197804000.008.png 197804000.009.png 197804000.010.png
Try
making
the
height
and
radius
values
smaller
and
larger
to
see
the
difference.
Now
we
need
to
give
the
robot
the
ability
to
fire
his
gun. 
The
robot
is
continuously

moving
and
animating. 
When
he
shoots
his
gun
we
play
an
animation
on
the
hands

and
the
graphical
gun
then
spawn
the
rocket
from
transform
relative
to
the
robot.

This
transform
does
not
animate,
it
is
simply
placed
approximately
at
the
point
where

the
gun
will
be
when
the
shoot
animation
fires
the
rocket.
Create
an
empty
game
object
and
make
it
a
child
of
the
robot
(use
the
hierarchy

view).
Rename
the
game
object
gun_spawn.
Now
we
need
to
place
it
properly. 
In
the
transform
inspector
select
Reset
from

the
context
menu,
then
move
it
forward
in
the
z­axis.
Add
the
rocket
launcher
script
to
the
gun_spawn
game
object. 
Assign
the

rocket
prefab
to
the
projectile
variable.
Make
a
prefab
of
this
robot,
call
it
Robot. 
This
will
allow
you
to
create
more

enemies
easily.
Play
the
game
and
check
that
the
robot
fires
at
you.
Although
you
can
shoot
the
robot,
it
is
not
configured
to
take
damage,
we’ll
remedy

this
in
the
next
section.
Robot
Damage
Attach
the
CharacterDamage
script
to
the
Robot
prefab.
Play
the
game,
shoot
the
robot
with
the
machine
gun
and
he
should
disappear.
5
197804000.011.png 197804000.012.png 197804000.013.png 197804000.014.png 197804000.015.png 197804000.016.png 197804000.017.png 197804000.018.png 197804000.019.png 197804000.020.png
Zgłoś jeśli naruszono regulamin