Game Development Reference
In-Depth Information
Now take a look at Figure 4-4. At the start of this event, Zool is set back to his position before
the collision (
xprevious
and
yprevious
—the blue cross), but then the
Move to Contact
action
moves Zool's
x
and
y
position to the collision point with
obj_solid
(red cross). The variable
vspeed
provides Zool's vertical speed in pixels per step (orange arrow), so
yprevious+vspeed
gives
us the vertical position of Zool if he had never collided with
obj_solid
(black cross). Therefore, by
checking for instances of
obj_solid
at the position
X=
x
,
Y=
yprevious+vspeed
, we are seeing if
there is anything in the way if Zool continues to slide vertically (but not horizontally) after the
collision.
4.
Immediately follow this with a
Speed Vertical
action (
move
tab) that sets
Vert. Speed
to
0
. This makes sure that Zool stops moving vertically if there
is
something in the way,
and leaves Zool's position at the collision point (red cross in Figure 4-4).
5.
Follow that with an
Else
action (
control
tab).
6.
Then include a
Set Variable
action that sets
Variable
y
to
yprevious+vspeed
. This will
move Zool's position to the sliding point (black cross in Figure 4-4) if there isn't
anything in the way and maintain Zool's vertical speed after the collision.
7.
Now we repeat the process for horizontal movement. Include a
Check Object
action to
check for
Object
obj_solid
at a position of
X
=
xprevious+hspeed
,
Y
=
y
. In a similar way,
we are checking if there is anything in the way if Zool continues to slide horizontally
(but not vertically) after the collision.
8.
Immediately follow this with a
Speed Horizontal
action (
move
tab) that sets the
Horiz.
Speed
to
0
.
9.
Follow that with an
Else
action (
control
tab).
10.
And then follow that with a
Set Variable
action that sets
Variable
x
to
xprevious+hspeed
. This will now maintain Zool's horizontal movement if there isn't
anything in the way after the collision.
11.
All of the new actions we've added actually need to take place before the check to see if
Zool is standing on solid ground, so we'll need to move those two actions to the end of
the list again. Click and drag the first
Check Object
action to the end of the actions list.
Now do the same for the (only)
Change Instance
action. You should now have 13
actions in the
Collision
event with
obj_solid
and it should look like Figure 4-5.
Search WWH ::
Custom Search