Ledge Climbing

Sargonnas

Member
Struggled with this long and hard. My programming level is novice as I'm sure you'll see here.

*I have oWalls (32 x 32 objects) which correctly stop movement in all directions, taken almost directly from a tutorial.
*I have a toe point and a reach point which correctly determine if there is an oWall directly in front of the player at toe height or reach height. This is determined immediately before the following code.
*I have a climbing animation with an Origin set to the same as the standing position after the climbing is completed (for a while this was set at the exact point of ledge I wanted to climb, but I didn't like changing my position twice and it didn't work any better anyways (the way I had it))
*Gravity and momentum effects are suspended while the player action == "climb"
*The following code occurs in the Player object, at the End step, after most other logic but before general movement effects (all of which include action != "climb" to take effect)

When encountering a ledge the character either climbs it correctly then jumps high into the sky at the animations end, or teleports to and climbs another non-existent ledge nearby (usually below and to the left) and then sometimes teleports again after the animation is complete.

Code:
//ESTABLISH ACTION AS "climb" and place sprite in the correct position
if facing == 1 && action != "climb" && (key_right)
{

// if there is a block in front and at your feet, but not above that:
   if block_at_feet == "yes" && block_at_chest == "no"
   {
       sprite_index = sPlayer_Climb_Ledge_R;
//The following bit of code is my attempt to call the instance of the oWall which is in the correct position, and use its position to align my character. An earlier approach is below
       var inst;
       inst = instance_place(reach_x, reach_y+16, oWall);
       if inst != noone
       {
           oPlayer.x = inst.x;
           oPlayer.y = inst.y-61; //This is the standing height over the block
       }
       action = "climb";
       image_speed = 1;
       Climb_count = 1;
       image_index = 0;
       hsp = 0;
       vsp = 0;
       momentum = 0;
   }

// PROCEED WITH CLIMBING ACTION
if action == "climb"
{
   if image_index > image_number -1 Climb_count = 0
   if Climb_count == 0
   {
       y -= 61
//MOVES INTO CRAWLING POSITION if a block appears two spaces above ledge
      if facing == 1 && (position_meeting(x+16,y-40,oWall))
       {
           action = "crawl";
           sprite_index = sPlayer_Crawl_R;
           image_speed = 0;
       }
// MOVES INTO STANDING POSITION if no block appears two spaces above ledge
       if facing == 1 && !(position_meeting(x+16,y-40,oWall))
       {
           action = "stand";
           sprite_index = sPlayer_R;
           image_speed = 0;
       }
}
This is how I was attempting the positioning code before looking up guides online and trying to call the Instance of the block itself for positioning reference. Is this a better approach?
Code:
//Move X and Y to the corner of the ledge, which should be guaranteed to be in front of and below the character origin at this point.
            while !(position_meeting(x+1,y+1,oWall))
            {
                 if !(position_meeting(x+1, y+11, oWall)) x++;
                 if !(position_meeting(x+35, y+1, oWall)) y++;
            }
It seemed easy enough at first but this now feels very over my head. I've been tearing my hair out over this for almost a month. I'll be very thankful to anyone that can help.
 
Top