alessa Posted June 19, 2018 Share Posted June 19, 2018 Hello, I am working on an endless runner that sees a dolphin swimming on the surface level, and when the player presses up the dolphin jumps and holding the down key makes it go under water. Currently, I have almost solved the issue with the following code: /* * * CONTROLS * * */ this.duck.body.velocity.x = this.speed*60; if (this.cursors.up.isDown) { this.duck.body.velocity.y = -200; } else if (this.cursors.down.isDown) { this.duck.body.velocity.y = 200; } else { // set velocity to 0 when player stops pressing keys, but keep moving forward console.log('duck starting point: ' + this.world.centerY+50); console.log('duck Y: ' + this.duck.y); if(this.duck.y >= this.world.centerY+50){ this.duck.body.velocity.y = -200; } else if(this.duck.y < this.world.centerY+50){ this.duck.body.velocity.y = 200; } else { this.duck.body.velocity.y = 0; } } However, this doesn't look like a natural "jump", but it changes suddenly from pressed / non-pressed states. I saw the Phaser tutorial and there they check the collision with the ground to make it smoother and avoid infinite jumping capabilities. In my case, I cannot activate collision with the water, otherwise I cannot have the player go underneath it.. Any idea on how to solve this issue? Link to comment Share on other sites More sharing options...
Recommended Posts