GMS 2.3+ Help with wall slide/jump (haven't gotten to jumping yet)

//local var
var onawall = place_meeting(x+1,y,ob_wall) - place_meeting(x-1,y,ob_wall)
//Get the player's input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_down = -keyboard_check(vk_down);
key_jump = keyboard_check_pressed(vk_up);
if health
//React to inputs{
move = key_left + key_right ///NEW KEY CHECK!!!!!!!
xspd = move * movespeed;
if move !=0 {image_xscale=move};

if place_meeting(x,y+1,ob_wall){movespeed=4;if move !=0
{sprite_index=sp_player} else sprite_index=sp_player_stand};

if (yspd < 10) yspd += grav;

if (place_meeting(x,y+1,ob_wall))
{ var jumps
    jumps = true;
    if (key_jump) yspd = -jumpspeed;
    if (key_jump) and jumps {sprite_index=sp_player_jump} else jumps= false;

//Horizontal Collision
if (place_meeting(x+xspd,y,ob_wall))
{   if onawall {if yspd != 0 {sprite_index=sp_player_wall;yspd=0;jumps=true}; if keyboard_check_pressed(key_jump) and onawall {yspd+=1}}
        x += sign(xspd);
     xspd = 0;
x += xspd;

//Vertical Collision
if (place_meeting(x,y+yspd,ob_wall))
       y += sign(yspd);
    yspd = 0;
y += yspd;
if global.hit and alarm[2] <= 0 {
  health -= 5;
  alarm[2] = room_speed;
I've gotten the player to slide down on the right side with the correct sprite - but he doesn't seem to do it on the left side - and I don't know why. The code is in the horizontal collision using the temporary variable 'onawall' to check to see if he's on a wall. But it seems to only check the right side and I'm at a loss as to why.

If anyone can figure out my mistake (read poor coding) or help me figure out my next step, jumping from a wall slide, I would be greatly appreciative. Thanks.


Friendly Tyrant
Forum Staff
The first thing I'd say is TIDY UP YOUR CODE!!!!! There is ZERO reason to do something like this:
if onawall {if yspd != 0 {sprite_index=sp_player_wall;yspd=0;jumps=true}; if keyboard_check_pressed(key_jump) and onawall {yspd+=1}}
Whitespace does NOT make your code less efficient, and it makes it infinitely more readable. YOU may be able to follow it, but anyone coming to a thread and seeing code like that is just going to say "nope!" and go help someone else! :p

That line would be much easier to read like this:
if onawall
if yspd != 0
if keyboard_check_pressed(key_jump) and onawall
This isn't me being pedantic, btw... This is an incredibly important part of becoming a programmer, as code should be visually blocked so that you can quickly and easily see exactly what is happening. This becomes even more important when you are working in a team or sharing your code with others, and it'll also help if you leave the project for a few months/years and then come back to it. So, use tabs, use whitespace, use new lines and let your code breath. :)

As to your problem... I would add a breakpoint into the event and then run the game using the debugger, stepping through the code a line at a time while on a left wall and see what values each of your movement variables has and see if they are what you think they should be. From that you should be able to work out exactly where the issue is and resolve it (or at least tell us what part of the code exactly isn't working).


You are setting onawall to {+1,0,-1} and then check if onawall is true. Anything less than 0.5 is false, so if onawall is -1, onawall is false. When is onawall -1? When the wall is to the left. You must check if onawall != 0 in this situation.


Better yet, don't do numeric math with boolean values. Use || if you want to know whether one of two boolean values is true.