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

Double Jump help please.

M

MrAli

Guest
hi here guys !
GM newbie here :)

i am trying to add double jump in my game. i saw some yt videos but their code is does't seem to be working for since i have a different code :(

currently i manage to add a single jump

here is my code
gml issue.PNG

what should i do to add a double jump ? kindly help me :)

Thanks.
 
C

Caloxeno

Guest
I am just a newbie around here, I don´t even know how to make a game, but there´s something I can tell you to help you;
You should actually upload the GMX file so the people that could help you download it and check everything, maybe there is a way of adding double jump that is not in that script.
Hope this helps!
 
L

locklock

Guest
Code:
// create a variable that tracks double jump status:
double_jump = false;

// in the first block of code that checks if you're in the air:
if !(double_jump) { // if you haven't already double jumped..
    if (up) { // and you press up..
        vspd -= 16; // subtract another jump worth of vertical speed
        double_jump = true; // and flag that you double jumped
      
    }
}

// then, once the player is back on the ground, reset the double_jump var:
double_jump = true;
this might take some adjusting to work with your code, but that's the general idea.
 

jazzzar

Member
thx for info :)

did't worked properly for me :(
basically you'd have a variable like can_double_jump=1 (or true whatever works)

In your step event
Code:
if (up && can_double_jump &&!place_meeting(x,y+1,oSolid)
{
      vspd = -16
      can_double_jump=0;
}
//reset that to true once on the ground

if place_meeting(x,y+1,oSolid)
         can_double_jump = 1;
 
M

MrAli

Guest
basically you'd have a variable like can_double_jump=1 (or true whatever works)

In your step event
Code:
if (up && can_double_jump &&!place_meeting(x,y+1,oSolid)
{
      vspd = -16
      can_double_jump=0;
}
//reset that to true once on the ground

if place_meeting(x,y+1,oSolid)
         can_double_jump = 1;
thx alot man it worked,

but there is one problem, i have unlimited numbers of jumps in the air,

Code:
//run State()
var right = keyboard_check(vk_right);
var left = keyboard_check(vk_left);
var up = keyboard_check(vk_up);
var up_release = keyboard_check_released(vk_up);
var down  = keyboard_check(vk_down);
var can_double_jump = keyboard_check_pressed(vk_up);

if (!place_meeting(x, y+1, solid)) {
     vspd += grav;
if (up && can_double_jump &&!place_meeting(x,y+1,solid))
{
      vspd = -16
      can_double_jump=0;
}
//reset that to true once on the ground

if place_meeting(x,y+1,solid)
         can_double_jump = 1;

    
    // Player is in the air
    sprite_index = player_running_spr;
    image_speed = 0;
    image_index = (vspd > 0);

    // Control the jump height
    if (up_release && vspd < -6) {
        vspd = -6;
}
    
} else {
    vspd = 0;
    
    // Jumping code
    if (up) {
        vspd = -16;
        
   }
  // Player is on the ground
    if (hspd == 0) {
        sprite_index = player_standing_spr;
    } else {
        sprite_index = player_running_spr;
        image_speed = .6;
    }
}

if (right || left) {
   hspd += (right-left)*acc;
   hspd_dir = right - left;
  
   if (hspd > spd) hspd = spd;
   if (hspd < -spd) hspd = -spd;
} else {
   apply_friction(acc);
}



if (hspd != 0) {
   image_xscale = sign(hspd);
}



move(solid);
 
T

TaylorBramble

Guest
I think an easier way to handle it is to just give yourself two jumps, not say if you can or not.
Something like
//CREATE
jumps_max = 2
jumps = jumps_max
on_ground = false
jump_speed = 6
grav = .2
ysp = 0


//STEP
key_up = keyboard_check_pressed(vk_up)


//////Check if you're on the ground
if (place_meeting(x, y+1, obj_collision)) /////////////or how you have it set up for solids works too, I just don't prefer those
{
on_ground = true
//////If you are, reset your number of jumps
jumps = jumps_max
}
else
{
on_ground = false
}


/////////If not on the ground, set gravity
if (on_ground = false)
{
ysp += grav
}

/////////Check if you have enough jumps and if you pressed the jump key
if (key_up && jumps>0)
{
/////If you do, jump
ysp -= jump_speed
//////and reduce number of jumps
jumps -=1
}
y+=ysp


Something like that should work, and if you wanted triple jumps or more, it works too.
 
Last edited by a moderator:
M

MrAli

Guest
I think an easier way to handle it is to just give yourself two jumps, not say if you can or not.
Something like
//CREATE
jumps_max = 2
jumps = jumps_max
on_ground = false
jump_speed = 6
grav = .2
ysp = 0


//STEP
key_up = keyboard_check_pressed(vk_up)


//////Check if you're on the ground
if (place_meeting(x, y+1, obj_collision)) /////////////or how you have it set up for solids works too, I just don't prefer those
{
on_ground = true
//////If you are, reset your number of jumps
jumps = jumps_max
}
else
{
on_ground = false
}


/////////If not on the ground, set gravity
if (on_ground = false)
{
ysp += grav
}

/////////Check if you have enough jumps and if you pressed the jump key
if (key_up && jumps>0)
{
/////If you do, jump
ysp -= jump_speed
//////and reduce number of jumps
jumps -=1
}
y+=ysp


Something like that should work, and if you wanted triple jumps or more, it works too.
did't worked, player stuck on top of the wall
 

jazzzar

Member
thx alot man it worked,

but there is one problem, i have unlimited numbers of jumps in the air,

Code:
//run State()
var right = keyboard_check(vk_right);
var left = keyboard_check(vk_left);
var up = keyboard_check(vk_up);
var up_release = keyboard_check_released(vk_up);
var down  = keyboard_check(vk_down);
var can_double_jump = keyboard_check_pressed(vk_up);

if (!place_meeting(x, y+1, solid)) {
     vspd += grav;
if (up && can_double_jump &&!place_meeting(x,y+1,solid))
{
      vspd = -16
      can_double_jump=0;
}
//reset that to true once on the ground

if place_meeting(x,y+1,solid)
         can_double_jump = 1;

   
    // Player is in the air
    sprite_index = player_running_spr;
    image_speed = 0;
    image_index = (vspd > 0);

    // Control the jump height
    if (up_release && vspd < -6) {
        vspd = -6;
}
   
} else {
    vspd = 0;
   
    // Jumping code
    if (up) {
        vspd = -16;
       
   }
  // Player is on the ground
    if (hspd == 0) {
        sprite_index = player_standing_spr;
    } else {
        sprite_index = player_running_spr;
        image_speed = .6;
    }
}

if (right || left) {
   hspd += (right-left)*acc;
   hspd_dir = right - left;
 
   if (hspd > spd) hspd = spd;
   if (hspd < -spd) hspd = -spd;
} else {
   apply_friction(acc);
}



if (hspd != 0) {
   image_xscale = sign(hspd);
}



move(solid);
Dude don't bind can_double_jump to a key, put it to 1 in a create event, no wonder you have unlimited jumps because pressing the jump key will set it to one remove the line where you set can_double_jump to the up key and do excatly as i said
 
M

MrAli

Guest
Dude don't bind can_double_jump to a key, put it to 1 in a create event, no wonder you have unlimited jumps because pressing the jump key will set it to one remove the line where you set can_double_jump to the up key and do excatly as i said
i followed your instructions ! now the 2nd jump is not working :(
 
D

DevNorway

Guest
Intialize variable "jumps".
Code:
jumps = 2;
Compare when you press up that the variable "jumps" is not 0.
Code:
if (up) {
    if jumps > 0 {
        jumps--;
        vspd = -16;
    }
}
Then reset the variable "jumps" when hitting ground.
Code:
if place_meeting(x, y + 1, solid) {
    jumps = 2;
}
 
Top