• 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!

Windows wall jump?

ellumnars

Member
btw sorry english is not my mother language

so im trying to program a wall jump mechanic and it works... well kinda

when i wall jump im trying to make the player jump to the opposite direction

i illustrated what im talking about here

1614285264496.png







GML:
///input

lkey = -(keyboard_check(ord("A")));
rkey = (keyboard_check(ord("D")));
ukey = (keyboard_check_pressed(vk_space));


move = lkey + rkey;
hspd = move * movespd;

///ground check

grounded = place_meeting(x,y+1, objsolid);


if (vsp < maxgrav) vsp += grav;
if grounded jumps = global.maxjumps;

if ukey && jumps > 0
{
    jumps -= 1;
    vsp = -jumpspd
}

///horizontal collision

if (place_meeting(x+hspd, y, objsolid)){
    while (!place_meeting(x+sign(hspd),y,objsolid)){
        x += sign(hspd);
    }
    clingable = true
    hspd = 0;
} else clingable = false
x += hspd;

///vertical collision

if (place_meeting(x, y+vsp, objsolid)) {
    while (!place_meeting(x,y+sign(vsp),objsolid)) {
        y += sign(vsp);
    }
    vsp = 0;
}


y += vsp;

///cosmetic fixes

if move != 0
    image_xscale = move;
    
    
    
if keyboard_check(vk_escape) game_end()

///interaction with other objects
if place_meeting(x,y,Gravity1)
{
   vsp =- 1;
   jumps = global.maxjumps;
}


///wall clings
if grounded = false and clingable = true
{
    clinged = true
    grav = 0.2
} else
{
    grav = 0.4
    clinged = false
}

///wall jump

if ukey and clinged = true
{
    jumps -= 1;
    vsp = -jumpspd
}
 
D

Deleted member 13992

Guest
What are you setting for the direction the sprite is facing?

Say for example you have variable dir which can be either 1 or -1, representing the direction of the sprite, and assuming the sprite faces the wall they're clinging to, you can use it to write the following code for wall jump:

GML:
///wall jump

if ukey and clinged = true
{
    jumps -= 1;
    vsp = -jumpspd
    hspd =  kickback_amount * -dir;     //kick from wall by this amount, times the reverse of sprite direction
}
Keeping a variable that is simply the facing direction (1 or -1) can come in extremely handy in movement code.
 

ellumnars

Member
so if i do for example

GML:
if lkey dir = -1
if rkey dir = 1
and then in the create event
Code:
dir = 0
kickback_amount = movespd
this should work?
 
Top