Game Development Reference
In-Depth Information
Fall Down
Now the only missing state behavior is for the falling state object. It's not particularly
complicated, as it just needs to be affected by gravity. However, the Set Gravity action in Game
Maker continues to increase the speed of an object indefinitely, so we must be careful not to
break our collision detection by making the object move too fast (refer back to Figure 2-14).
Anyway, we'll begin with the Create event, which sets up the default object behavior:
Adding a Create Event to the Falling State Object
1. Reopen the obj_pod_falling object and add a Create event.
2. Include a Set Gravity action ( move tab) in the actions list. Set Direction to 270
(downwards) and Gravity to 2 .
3. Include a Test Variable action ( control tab) and check that facing is equal to
FACE_RIGHT .
4. Include a Change Sprite action ( main1 tab) and select spr_pod_fall_right (leave the
other settings as they are).
5. Include another Test Variable action ( control tab) and check that facing is equal to
FACE_LEFT .
6. Include a Change Sprite action ( main1 tab) and select spr_pod_fall_left (leave the
other settings).
Next, we will copy the collision event from the jumping state object, and implement the
transition back into the standing state when Fishpod is supported by a platform (see Figure 2-9).
This collision needs to check whether there is actually a platform beneath Fishpod's feet, as he
may have fallen diagonally into the side of a platform after making a jump.
Copying a Collision Event for the Falling State Object
1. Reopen obj_pod_jumping and select the Collision event with obj_platform (left-click on
it) so that the actions for this event are visible in the actions list.
2. Right-click anywhere in the actions list and choose Select All from the menu. Right-
click again and choose Copy .
3. Reopen obj_pod_falling and add a Collision event with obj_platform .
4. Right-click anywhere in the actions list and choose Paste from the menu. All five
actions from obj_pod_jumping should be copied over.
5. Double-click the Change Instance action in the actions list to reopen it. Change the
Change Into option to obj_pod_standing and set Perform Events to yes .
6. Include a Check Object action ( control tab) directly above the Change Instance action.
Set Object to obj_platform , set Y to 1 , and check the Relative option. This will now only
switch to the standing state if Fishpod is supported after colliding with the platform.
This is important in the situation where Fishpod falls sideways into a platform as it
doesn't make sense for him to change state when that happens.
Finally, we need to handle the problem of gravity making Fishpod fall too fast for the
collision detection. We'll do this in a Step event, as this will constantly keep the speed in check.
 
Search WWH ::




Custom Search