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

Need help with double jumps

P

PantsOfAwesome

Guest
I've started making a platformer but my double jump system does not work for some reason, I was wondering if you could help me fix it (please).
Here is my create code:
Code:
grav = 0.2;
hsp = 0;
vsp = 0;
jumpspeed = 7;
movespeed = 4;
cur_jumps = 0;
And here is my step code:
Code:
//Recieve Input
key_left = -keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check(vk_space);
key_run = keyboard_check(vk_shift);
//Use inputs
move = (key_left + key_right);
hsp = move * movespeed;
if(key_run)
hsp = move * 2 * movespeed;
if(vsp < 10) vsp+=grav;

if(place_meeting(x,y+1,obj_wall))
{
cur_jumps = 0;
}

if(cur_jumps < 2) && (key_jump)
{
cur_jumps += 1;
vsp = -jumpspeed;
}
//Horizontal Collision
if(place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
x+=sign(hsp);
hsp=0;
}
//Vertical Collision
if(place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
y+=sign(vsp);
vsp=0;
}
x+=hsp;
y+=vsp;
Thanks in advance to anyone who tries to help!
 

Phil Strahl

Member
You are using keyboard_check() that returns true in every step the key is held down. You might want to use keyboard_check_pressed() for the jumping instead which only fires once when the key is held down.

Code:
key_jump = keyboard_check_pressed(vk_space);
 
P

PantsOfAwesome

Guest
You are using keyboard_check() that returns true in every step the key is held down. You might want to use keyboard_check_pressed() for the jumping instead which only fires once when the key is held down.

Code:
key_jump = keyboard_check_pressed(vk_space);
Oh well that fixed it, Thank you!
 
Top