• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Help with wall 'cling' player code

A

AtomicToilet

Guest
Hola!

In messing around with a Wall Climb code, I accidentally made it so that the Player can actually stick to a wall in the place they touch it - which is actually a pretty cool thing, so I want to keep it.

ie. When the Player jumps (or is falling) against a wall and presses right and left together, they stick to the wall. Once either key is released, gravity works like normal and the Player drops down.

My problem is, it only works when the Player object is moving/facing left...! Can anyone help me figure out why? Cheers!

Here's all my move code, up to and including the wall cling:
Code:
//React to inputs
move = key_left + key_right;
hsp = move * spd;
if (vsp < 10) vsp += grav;

if (place_meeting(x,y+1,obj_wall))
{
    on_ground = false;
}

else if (!place_meeting(x,y+2,obj_wall))
{
    on_ground = true;
}

//JUMP CODE
if (!place_meeting(x,y+1,obj_wall))
{
    vsp += grav;
  
   //Control jump height
    if (key_up_released && vsp < -4)
    {
    vsp = -4;
    }
}
else
{
    vsp = 0;
    if (key_up)
    {
    audio_play_sound(snd_jump,5,false);
    vsp = jumpspeed;
    }
}

//Friction
if(!key_right && key_left = 0 && hsp != 0)
{
    hsp = ((abs(hsp)- fric) * sign(hsp));
}
else
{
    hsp = move * spd;
}

//WALL CLING
    if (key_right) && place_meeting(x-2,y, obj_wall) && !place_meeting(x, y+2, obj_wall) && !(key_left)
    {
    vsp = 0;
    sprite_index = spr_player_ledge;
    }
    
    if (key_left) && place_meeting(x+2,y, obj_wall) && !place_meeting(x, y+2, obj_wall) && !(key_right)
    {
    vsp = 0;
    sprite_index = spr_player_ledge;
    }
I have a feeling there's some kind of conflict, maybe, with the jump code...? But I'm not sure. Any suggestions greatly appreciated!
 
D

Danei

Guest
is your key_left meant to be a negative number or a positive one?
 
Top