jopcode Posted January 13, 2017 Share Posted January 13, 2017 Hello, I want to make a double jump but with my code it's really hard the double jump, you need to press the key too fast to make it. any idea ? this.onTheGround = this.player.body.blocked.down; if(this.onTheGround) { this.jumps = 3; this.jumping = false; } // Jump! if (this.jumps > 0 && this.cursors.up.isDown) { this.player.body.velocity.y = -350; this.jumping = true; } // Reduce the number of available jumps if the jump input is released if (this.jumping && this.cursors.up.isDown) { this.jumps--; this.jumping = false; console.log('jumps avalible:' + this.jumps); } Link to comment Share on other sites More sharing options...
jopcode Posted January 14, 2017 Author Share Posted January 14, 2017 Someone can help me? Link to comment Share on other sites More sharing options...
Tom Atom Posted January 14, 2017 Share Posted January 14, 2017 Hi, first part, resetting your jump properties if on ground, is OK: this.onTheGround = this.player.body.blocked.down; if(this.onTheGround) { this.jumps = 3; this.jumping = false; } Second part is problematic. To check if key was just pressed use justDown instead of isDown. Also code logic seems little bit strange to me. In attachment you will find complete small endless runner example. I implemented your triple jump into it. It is written in TypeScript, but you should have no problems to rewrite it into JS, if you need. SimpleRunner.zip Crucial parts are: + define these variables for jumping: // jumping private _nextJumpTime: number = 0; private _jumping: boolean = false; private _jumps: number = 3; + in update see code for jumping (key used for jumping is space in example): let onGround = this.physics.arcade.collide(this._player, this._platforms); let body = <Phaser.Physics.Arcade.Body>this._player.body; let canJump = onGround && this.game.time.time > this._nextJumpTime; let canJumpInAir = this._jumping && this._jumps > 0; if (canJump) { this._jumping = false; this._jumps = 3; } if (this._input.justDown && (canJump || canJumpInAir)) { if (onGround) { this._jumping = true; this._nextJumpTime = this.game.time.time + 250; } --this._jumps; body.velocity.y = -850; } jopcode 1 Link to comment Share on other sites More sharing options...
Recommended Posts