Jump to content

Double jumping with phaser


Recommended Posts

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

  1. player hits jump while on the ground -(jump set equal to one)
  2. 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


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;
			player.body.velocity.y = -200;
		if (!onTheGround && jumps == 1) {
			jumps = 2;
			//jump again
	    	player.body.velocity.y = -500;
		jumps = 0;


Link to comment
Share on other sites

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.



Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...