Game Development Reference
In-Depth Information
Move On Top
Load shadows1.gmk and open the new script resource called move_on_top_of . This version of
the script only has two arguments, as it is always assumed that the direction of movement is 270
degrees. Other than that, it is practically identical to move_to_contact_with , except that it uses
the script check_standing_on instead of the built-in function place_meeting .
This is the important line:
if( check_standing_on( contact_obj, 1, 0 ) == true ) then return true;
So in practice, this script moves the instance pixel by pixel until it finds the required object
within the 1-pixel high rectangle beneath the bounding box. This contrasts with the approach of
move_to_contact_with that checks whether the entire bounding box overlaps with the object and
then returns the previous position. As a result, we have a script that isn't affected by ledge
objects that are already inside the character's bounding box when the script is called.
We can now use this new script in place of move_to_contact_with in all the places where
Flynn is moved directly downward following a collision (so any kind of ramp or slope collision
as well as conditional statements that move Flynn down to keep him walking on top of
platforms). This prevents situations where Flynn gets stuck between two ledges such as that
shown on the left of Figure 11- 7, but doesn't improve the situation shown on the right. This is
because the airborne collision event with platforms has to use the more general
move_to_contact_with scr i pt, to cope wi th col l i si on s i n a l l di r e cti on s tha t ca n ha ppe n i n mi d- a i r .
We'll need to give that some more thought.
Ignoring Ledges in the Air
You might think that the Collision event between obj_flynn_air and obj_ledge is all you need to
worry about when considering collisions with ledges in the air. Unfortunately it's not as simple
as that because ledges are also a kind of obj_solid , and as such are also included in collision
checks wherever the move_to_contact_with script is used. So even if the original collision event
was not with a ledge, ledges still get included in the way that collision is resolved.
Open up the obj_solid Collision event of obj_flynn_air and remind yourself of how it
works. It is a general-purpose collision event that uses the move_to_contact_with scr i pt to cope
with collisions in all directions, and thus is vulnerable to the ledge problem. Unfortunately, we
can't replace it with move_on_top_of , as this wouldn't work for horizontal collisions with solid
objects, such as when Flynn jumps into the side of a platform (it would actually transport him
down onto the floor when he did so). However, there is another way to make sure ledges are
ignored in such a collision and that is simply to deactivate them. Game Maker provides a range
of functions that allow you to deactivate certain instances, so that they simply behave as if they
don't exist anymore, yet can be brought back into existence at a later point. The following
listing shows how we've used the instance_deactivate_object function to deactivate all
instances of a obj_ledge (whi ch i n cl ude s l i fts) a t the sta r t of the col l i si on code a n d
instance_activate_object to reactivate them again afterward.
 
Search WWH ::




Custom Search