M
// 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;
basically you'd have a variable like can_double_jump=1 (or true whatever works)thx for info
did't worked properly for me
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,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;
//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);
did't worked, player stuck on top of the wallI 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.
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 saidthx 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);
i followed your instructions ! now the 2nd jump is not workingDude 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
Ughh man what about uploading your project somewhere? I'll check it out once i reach my lapi followed your instructions ! now the 2nd jump is not working
jumps = 2;
if (up) {
if jumps > 0 {
jumps--;
vspd = -16;
}
}
if place_meeting(x, y + 1, solid) {
jumps = 2;
}