Double jump! ..while using variable jumping

L

L1NDHOLM

Guest
Hello. I'd like to add a double jump for my obj_player but i can't seem to make it work with the ledge assistance, jump input buffering and variable jumping i'm currently using. I'd like to have two jumps if i jump off the ground but only one jump if i walk off a platform. I'll send my create and step event code.

Create
Code:
//Initialize Variables

grav = 0.5; //gravitation
gravmax = 10;
hsp = 0;    //horizontal speed
vsp = 0;    //vertical speed
movespeed = 3;



jumpspeed_normal = 6;
jumpspeed_powerup = 10;

jumpspeed = jumpspeed_normal

//for ledge assistance
grace_jump_time = 4; //number of grace period frames after leaving the ground you can still jump
grace_timer = grace_jump_time;

//for input buffering
jump_buffer = 2; //number of grace period frames between player pressing jump and hitting the ground when they will still jump
jump_buffer_timer = jump_buffer;
Step
Code:
// Get the players input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space); //original non-variable jumping
key_jump_held = keyboard_check(vk_space); //for variable jumping
is_on_ground = false; //for ledge assistance
jump_is_inside_buffer = false; //for jump input buffering

//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < gravmax) vsp+= grav;

//For Ledge Assistance with input buffering
if (place_meeting(x,y+1,obj_parentblock))
{
    is_on_ground = true;
    grace_timer = grace_jump_time;
}
else
{
    is_on_ground = false;
    grace_timer--;
}

//Jump Input Buffering
if (key_jump)
{
    jump_buffer_timer = jump_buffer;
}


if (jump_buffer_timer > 0)
{
    jump_is_inside_buffer = true;
}
else
{
    jump_is_inside_buffer = false;
}

//this is sort of a failsafe for when the buffer frames are set to 0, just use the old jump
if (jump_buffer = 0)
{
    jump_is_inside_buffer = key_jump;
}

if(jump_is_inside_buffer)
{
    if (is_on_ground || grace_timer >0)
    {
        //vsp = key_jump * -jumpspeed;
        vsp = -jumpspeed;
        grace_timer = 0;
        jump_buffer_timer = 0;
    }
    jump_buffer_timer--;
}

//for variable jumping
if(vsp <0 && !key_jump_held) vsp = max(vsp,0)


//Horizontal Collision
if (place_meeting(x+hsp, y, obj_parentblock))
{
    while(!place_meeting(x+sign(hsp),y,obj_parentblock))
    {
        x+= sign(hsp);
    }
    hsp=0;
}
x += hsp;

//Vertical Collision
if (place_meeting(x, y+vsp, obj_parentblock))
{
    while(!place_meeting(x,y+sign(vsp),obj_parentblock))
    {
        y+= sign(vsp);
    }
    vsp=0;
}
y += vsp;
Thank you
 

Bentley

Member
Ex code:
if (key_jump)
{
if (on_ground)
{
can_double_jump = true;
vspd = jump_height;
}
else
{
if (can_double_jump)
{
vspd = jump_height;
}
}
}
 
Top