GM:S 1.4 Help with wall 'cling' player code

Discussion in 'Programming' started by AtomicToilet, Jun 1, 2019.

  1. AtomicToilet

    AtomicToilet Member

    Joined:
    Jul 6, 2016
    Posts:
    70
    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!
     
  2. Danei

    Danei Member

    Joined:
    Mar 23, 2018
    Posts:
    278
    is your key_left meant to be a negative number or a positive one?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice