Node231 Posted May 17, 2016 Share Posted May 17, 2016 Hey all! I'm writing a program where I'm attempting to get my character to double jump in phaser. I've run into some issues. The logic of my code goes as follows player hits jump while on the ground -(jump set equal to one) if jump is set equal to one and the player is not on the ground, jump again. however, I cannot get my code to enter the second stage, and I'm not sure why. I've tried several different solutions but to no avail. I believe the problem may be within declaring var onTheGround = player.body.touching.down; and then !onTheGround for my second if statement. Any help would be appreciated, here is the full jump portion of my code: // Set a variable that is true when the player is touching the ground var onTheGround = player.body.touching.down, // (jumps is defined as 0 at the top of the code) // Allow the player to jump if they are touching the ground. if (cursors.up.isDown || upKey.isDown) { if (onTheGround && jumps == 0) { jumps = 1; console.log(jumps); //jump player.body.velocity.y = -200; } if (!onTheGround && jumps == 1) { jumps = 2; console.log(jumps); //jump again player.body.velocity.y = -500; } jumps = 0; } Link to comment Share on other sites More sharing options...
Skeptron Posted May 17, 2016 Share Posted May 17, 2016 Well maybe it's because you set jumps = 0; no matter what. At the very end of your code snippet, you shouldn't do that, but instead put that line into some kind of 'else' condition. Link to comment Share on other sites More sharing options...
Node231 Posted May 17, 2016 Author Share Posted May 17, 2016 9 hours ago, Skeptron said: Well maybe it's because you set jumps = 0; no matter what. At the very end of your code snippet, you shouldn't do that, but instead put that line into some kind of 'else' condition. it would be easy to see where to put it if I could get my code to go into the second jump, I'll try fixing this first though. Thanks! Link to comment Share on other sites More sharing options...
SignalSin Posted May 18, 2016 Share Posted May 18, 2016 Game Mechanic Explorer has an example of double jumping in Phaser, among several other useful things. Tilde 1 Link to comment Share on other sites More sharing options...
Node231 Posted May 20, 2016 Author Share Posted May 20, 2016 On 5/18/2016 at 7:59 PM, SignalSin said: Game Mechanic Explorer has an example of double jumping in Phaser, among several other useful things. thanks! I found a way to fix my method, but this is helpful! Appreciate it Link to comment Share on other sites More sharing options...
Recommended Posts