GMS 2 [SOLVED]How to make a proper double jump?

I

IcyZ1ne

Guest
So I am trying to make my character to double jump, but I either make him only jump once or jump for as many times as they want. Here is my code:

jumps = 0;
jumpsmax = 2;
if(onGround)
{
jumps = jumpsmax;
}
if(jump && !jumpHold && jumps > 0)
{
jumps -= 1;
ySpeed = jPower;
squash_stretch(0.7,1.3);
}
With the code above my player only jumps once.(perhaps that when you are no longer onGround jumps goes back to 0?)
And here is the code that somewhat works, but makes my player jump forever :

jumps = 0;
jumpsmax = 2;
if(onGround)
{
jumps = jumpsmax;
}
else
{
jumps = 1
}
if(jump && !jumpHold && jumps > 0)
{
jumps -= 1;
ySpeed = jPower;
squash_stretch(0.7,1.3);
}

Please help me out to make it work properly! Thank you.
 

marasovec

Member
Here is the code I use. Hope it helps
Code:
CREATE
djump = false;

STEP
var jk = keyboard_check_pressed(vk_space);
if (onground)
    {
    djump = true; // reset double jump
    if (jk)
        {
        vspd = -jumpspd; // jump
        }
    }
else
    {
    if (jk and djump)
        {
        vspd = -jumpspd; // double jump
        djump = false; // disable double jump
        }
    }
 

Zabicka

Member
Try this
Code:
jumps = 0;
jumpsmax = 2;

if (onGround)
{
jumps = 0; //This will reset your jumps, that means, when you land, you can double jump again
}

if (jump && !jumpHold && jumps <= jumpsmax) // You can jump until your "jumps" variable is reached your "jumpsmax" variable
{
jumps += 1; //Adds to your jump
ySpeed = jPower;
squash_stretch(0.7,1.3);
}
Hope it helps (I hope i didn't do any mistakes, I wrote it a bit quick).
 
I

IcyZ1ne

Guest
Try this
Code:
jumps = 0;
jumpsmax = 2;

if (onGround)
{
jumps = 0; //This will reset your jumps, that means, when you land, you can double jump again
}

if (jump && !jumpHold && jumps <= jumpsmax) // You can jump until your "jumps" variable is reached your "jumpsmax" variable
{
jumps += 1; //Adds to your jump
ySpeed = jPower;
squash_stretch(0.7,1.3);
}
Hope it helps (I hope i didn't do any mistakes, I wrote it a bit quick).
Thank you very much, it worked!
 
Top