I am trying to create a game where I can double or triple jump, similar to super smash bros. I was wondering how I can make a "double jump" feature using Code.org? This is what I currently have. The variables are defined.
function jumping() {
if (keyWentDown("w")) {
player.setAnimation("playerJump");
player.velocityY = -jumpForce;
setTimeout(function() {
player.setAnimation("player");
setTimeout(function() {}, 400);
}, 400);
}
if (keyWentUp("w")) {
jumpcount = jumpcount + 1;
}
if (jumpcount == 3) {
jumpcount = 0;
}
}
function PlayerGravity() {
player.velocityY += gravity;
}
You may not still need the answer, but here is my take on it:
Create 2 variable: The variable 'maxJumps' which defines the maximum number of jumps at one time, and the variable 'jumpCounter' which defines the current number of jumps. Create a separate function 'isStanding' that checks if the player is standing on the ground, or is in in air. If you have a platform style game, you may need to check multiple platforms to do this. Every iteration of the game, run the 'isStanding' function to tell if the player is standing. If the player is standing, set 'jumpCounter' to 0 and reset the player's velocity. When the player presses the 'w' key, check if 'jumpCounter' is less than 'maxJumps', and run the rest of the code for jumping if so. This is what that looks like: