Game Development Reference
In-Depth Information
Adding a Collision Event to the Walking State Object
1.
Reopen
obj_pod_walking
and add a
Collision
event with
obj_platform
. Recall that all
the platform objects have
obj_platform
as their parent, so this collision event will be
triggered for collisions between
obj_pod_walking
and any kind of platform.
2.
Include a
Set Variable
action (
control
tab). Type
x
into
Variable
and
xprevious
into
Value
. This sets the x position back to the value it had in the last step.
3.
Include another
Set Variable
action. Type
y
into
Variable
and
yprevious
into
Value
.
This then does the same for the y position.
4.
Include a
Move to Contact
action (
move
tab). Type
direction
into
Direction,
leave
Maximum
as
-1
, and select
all objects
for
Against
. This will find the contact point in
the direction Fishpod is moving. The
Maximum
value indicates the distance (in pixels)
that the action will check for a collision before giving up. A value of
-1
means it will
check for collisions an arbitrary distance away, but sometimes it is useful to be able to
limit this.
5.
Include a
Change Instance
action (
main1
tab). Select
obj_pod_standing
from the
Change Into
menu and
yes
for
Perform Events
. This will put the object into the
standing state after a horizontal collision.
Keep the walking state object open, as we now need to handle the transition from the
walking state to the falling state when there is no longer a platform supporting the character's
feet. We can achieve this using the
Check Object
action.
Adding a Step Event to the Walking State Object
1.
Add a
Step, Step
event to
obj_pod_walking
. We're going to use a
Step
event because the
walking object is constantly moving and the ground could stop supporting it at any
point (a
Begin Step
or
End Step
would have an almost identical effect in this case).
2.
Include a
Check Object
action (
control
tab). Select
obj_platform
for
Object
, leave
X
as
0
, and set
Y
to
1
. Check both the
Relative
and
NOT
options. This checks to see if there
would be a collision with an instance of
obj_platform
if Fishpod was moved down one
pixel and only performs the next action if this is
not
true (that is, if Fishpod is standing
in thin air).
3.
Include a
Change Instance
action (
main1
tab). Select
obj_pod_falling
from the
Change Into
menu and
yes
for
Perform Events
. This will now put the object into the
falling state when it is no longer supported by a platform.
That completes the walking state object, which now has all the state transitions originally
shown in Figure 2-9. Now we've just got the jumping and falling state objects to complete.
Search WWH ::
Custom Search