Legacy GM Ladders are driving me batty, please help!

G

Guest User

Guest
Hello,
I've been working on platform game for a while and wanted to add simple ladders into my game (ladders like in the original donkey kong)

I have followed various tutorials and watched four diferent 'guide' to ladders on youtube, however none of these worked like I want.

I just want a simple ladder that you climb up/down and when you get to the bottom you return to walking and when you get to the top you don't hop, you walk (and you don't fall down the ladder if you walk over the top of it)

Does someone, anyone actually have a working tutorial for this? because I'm getting tired of trying things over and over and none of it works correctly.
 
G

Gillen82

Guest
You need to have a look at finite state machines, instead of specific tutorials for climbing ladders. In a nutshell, a state machine will allow you to cycle through different states, depending on the action(s) taking place at a particular time e.g. Walking, Running, Attacking, Defending, CLIMBING...
On top of that, you will find your code easier to manage, and you can add new/different states easily enough without disrupting the other states that you have.
 

PlayerOne

Member
Like @Gillen82 said state machines are best to maintain what action does what. However, I'll answer by giving you a snippet of code that use in my player state machine to climb up and down ladders.

Code:
case PLAYER.ladder:
 
   if (keyboard_check_pressed(vk_space) || !place_meeting(x,y,oProp_Ladder)){ action=PLAYER.move; }
   
   sprite_index = _climb_ladder;
   image_speed=(1*(key_up+key_down));
   vsp = (4*(key_up+key_down));
   
break;
This code will snap to the player to x position of the nearest ladder giving the impression he/she is climbing. Within the ladder object have the following:

Code:
if (instance_exists(oPlayer))
{
   
   with (oPlayer)
   {
       if (keyboard_check_pressed(ord("E")) && place_meeting(x,y,oProp_Ladder))
       {   
           var Nearest = instance_nearest(x, y, oProp_Ladder);
           x = Nearest.x;
           
           action=PLAYER.ladder;
       }
   
   }
   
}
 
Top