Wall Jump Help Needed

NovaOzuka

Member
So yeah, my only reason for making an account here is because I'm trying to make a Platformer in Game Maker. I hit a snag in the coding, and I'm having trouble getting any help. Heck I can't even sign in here at home because of reCaptcha. Anyway, the code I'm using is right here.
//Wall Jump
if (place_meeting(x-1,y,obj_wall)) and (!place_meeting(x+1,y,obj_wall))
{
if (key_jump) and (!place_meeting(x,y+1,obj_wall))
{
vsp = -7;
hsp = -5;
}
}

if (place_meeting(x+1,y,obj_wall)) and (!place_meeting(x-1,y,obj_wall))
{
if (key_jump) and (!place_meeting(x,y+1,obj_wall))
{
vsp = -7;
hsp = 5;
}
}
The problem here is that no matter what I do, the player isn't pushed off the wall, so they can just ascend the wall quickly and endlessly with no need of a second wall. They don't even leave the wall unless the player presses the arrow key to get off the wall. This happens no matter what I make hsp equal. If anyone has any idea how to fix this, please let me know.
 

samspade

Member
So yeah, my only reason for making an account here is because I'm trying to make a Platformer in Game Maker. I hit a snag in the coding, and I'm having trouble getting any help. Heck I can't even sign in here at home because of reCaptcha. Anyway, the code I'm using is right here.
//Wall Jump
if (place_meeting(x-1,y,obj_wall)) and (!place_meeting(x+1,y,obj_wall))
{
if (key_jump) and (!place_meeting(x,y+1,obj_wall))
{
vsp = -7;
hsp = -5;
}
}

if (place_meeting(x+1,y,obj_wall)) and (!place_meeting(x-1,y,obj_wall))
{
if (key_jump) and (!place_meeting(x,y+1,obj_wall))
{
vsp = -7;
hsp = 5;
}
}
The problem here is that no matter what I do, the player isn't pushed off the wall, so they can just ascend the wall quickly and endlessly with no need of a second wall. They don't even leave the wall unless the player presses the arrow key to get off the wall. This happens no matter what I make hsp equal. If anyone has any idea how to fix this, please let me know.
Can't say for sure without seeing the rest of your code, but it sounds like you set horizontal movement something like one of these:

Code:
hsp = (right - left) * speed;
 
//Or perhaps

if (left) {
    hsp = -walkspeed;
} else if (right) {
    hsp = walk_speed;
}
Essentially, it sounds like you're setting your hsp with an = sign. This will overwrite your wall push. There's a few ways around this. First, you could look into state machines and have a wall jump state, where when you jump off a wall, it doesn't let you redirect for a couple frames or so. Alternatively, you could convert to an acceleration based horizontal movement then the force will be added to your hsp and it won't be reset. Finally, you could create a separate variable, called wall_push, and add it to hsp after hsp is set like this:

Code:
hsp = (right - left) * speed;

if (place_meeting(x-1,y,obj_wall)) and (!place_meeting(x+1,y,obj_wall))
{
    if (key_jump) and (!place_meeting(x,y+1,obj_wall))
    {
        vsp = -7;
        wall_push = 5;
    }
}

if (place_meeting(x+1,y,obj_wall)) and (!place_meeting(x-1,y,obj_wall))
{
    if (key_jump) and (!place_meeting(x,y+1,obj_wall))
    {
        vsp = -7;
        wall_push = -5;
    }
}

//apply 'friction' to wall_push so it reduces and add it to hsp
if (abs(wall_push) > 0.2) {
    wall_push *= 0.95;
    hsp += wall_push;
}
while this one requires the smallest modification to code, it's probably the least flexible. I would recommend option 1 or 2.
 
Last edited:
D

Delirious

Guest
Well from the code you have provided, it makes sense that the player object isn't being pushed away from the wall, because you aren't setting the hsp to a value that would move the player object away from the wall.

I know you said you tried setting hsp to many different values with no success, but I just want to check if you tried flipping the hsp values in the wall jump code i.e. multiplying these values by -1.
 
Last edited by a moderator:

NovaOzuka

Member
Huh, I actually got logged in here at home finally. anyway....
Well from the code you have provided, it makes sense that the player object isn't being pushed away from the wall, because you aren't setting the hsp to a value that would move the player object away from the wall.

I know you said you tried setting hsp to many different values with no success, but I just want to check if you tried flipping the hsp values in the wall jump code i.e. multiplying these values by -1.
Swapping the positive and negative values worked, but now there's a new problem. The code just pushes the player however many pixels off the wall that hsp is set to. Setting it to a value that does so significantly, like 30 for example, makes the wall jump work more like a weird teleport. In other words, it needs to push the player a significant distance from the wall without doing so in a way that acts almost like X = X + 30.
 
D

Delirious

Guest
Well considering you most likely have
Code:
x += hsp
somewhere in your step event, it makes sense that setting hsp to 30 is acting like x = x + 30 because the two pieces of code would actually be equivalent.

I'm not quite sure what the issue is now though; I thought that you wanted the player to move away from the wall at a speed equal to hsp?

If I'm understanding you correctly, it sounds like all you need to do is lower the hsp.
 
Last edited by a moderator:

NovaOzuka

Member
Well considering you most likely have
Code:
x += hsp
somewhere in your step event, it makes sense that setting hsp to 30 is acting like x = x + 30 because the two pieces of code would actually be equivalent.

I'm not quite sure what the issue is now though; I thought that you wanted the player to move away from the wall at a speed equal to hsp?

If I'm understanding you correctly, it sounds like all you need to do is lower the hsp.
Actually, I have that nowhere in my code. It also isn't as simple as just lowering hsp. The issue now is distance and speed. Basically what happens is if hsp is set for 30 or -30, the player is moved that many pixels instantly and stops unless the arrow key is held, which well be likely the case as I intend to have them be able to wall jump only while wall sliding, which I can probably fix later possibly with states. I only made it 30 instead of 5 like in the original code because that only moved the player over by 5 pixels. Basically I need hsp to be lower, but be constant long enough to move the player further than the number of pixels that hsp is set to.

tl;dr hsp is acting as both speed and distance, which need to be independent of each other in the case of wall jumping
 
D

Delirious

Guest
Okay, then how do you update your x position if it's not x += hsp; in the step event?

It seems like you need your hsp to be working over time, but it's not. I would need to see how you update your x position.
 

samspade

Member
Actually, I have that nowhere in my code. It also isn't as simple as just lowering hsp. The issue now is distance and speed. Basically what happens is if hsp is set for 30 or -30, the player is moved that many pixels instantly and stops unless the arrow key is held, which well be likely the case as I intend to have them be able to wall jump only while wall sliding, which I can probably fix later possibly with states. I only made it 30 instead of 5 like in the original code because that only moved the player over by 5 pixels. Basically I need hsp to be lower, but be constant long enough to move the player further than the number of pixels that hsp is set to.

tl;dr hsp is acting as both speed and distance, which need to be independent of each other in the case of wall jumping
See my reply to understand why this is happening and what you can do to fix it.
 
D

Delirious

Guest
True. Listen to what samspade said. If you have something like
Code:
hsp = (right - left) * speed;
to control your movement, then you would be resetting your hsp to 0 on the next step if you aren't pressing any arrow keys (or 'A' or 'D').
 

NovaOzuka

Member
I think I figured out my own solution by creating two new variables called lwjtimer and rwjtimer. By replacing hsp in the lines with the respective timer, I can make hsp maintain its speed for however many steps I want like this:

code said:
//Wall Jump
if (place_meeting(x-1,y,obj_wall)) and (!place_meeting(x+1,y,obj_wall))
{
if (key_jump) and (!place_meeting(x,y+1,obj_wall))
{
vsp = -5;
lwjtimer = 16;
}
}

if (place_meeting(x+1,y,obj_wall)) and (!place_meeting(x-1,y,obj_wall))
{
if (key_jump) and (!place_meeting(x,y+1,obj_wall))
{
vsp = -5;
rwjtimer = 16;
}
}

//Wall Jump Timer
if (lwjtimer > 0)
{
lwjtimer = lwjtimer - 1;
hsp = 8;
}

if (rwjtimer > 0)
{
rwjtimer = rwjtimer - 1;
hsp = -8;
}
Funny thing is, the problem I was having with the code was also the solution, being that hsp was being overridden the next step. Mine probably isn't the best solution, but at least it's something I know how to do without asking/looking around. The transition could probably be made to look smoother with some tweaks. Might basically be the the same as the third solution listed earlier.
 
Top