Jump to content

[1.1.6] If gravity > velocity, it's impossible to jump?


toto88x
 Share

Recommended Posts

Hi,

 

I'm using 1.1.6 to make a platformer, where you can move a player and make it jump in the world (tilemap).

 



// create()
player.body.gravity.y = 300;

// update()
if (cursor.up.isDown && player.body.blocked.down) 
    player.body.velocity.y = -350;


 

If the player gravity is lower than the player jump velocity (like above), the games works fine. But setting the gravity higher than the velocity makes it impossible to jump. And since I want my player to make small jumps and not to "float in the air while jumping", I'm stuck.

 

Any idea how to solve this?

Thanks!

Link to comment
Share on other sites

Yeah same is happening for me in 1.1.5. Only work around I found for it at the minute is setting the player gravity and velocity and in the jump function as well as resetting the main gravity when finished. My game is heavily reliant on physics and gravity variables but I would prefer a proper work around on this too. Hope this gets an answer though.

Link to comment
Share on other sites

  • 2 weeks later...

Yeah same is happening for me in 1.1.5. Only work around I found for it at the minute is setting the player gravity and velocity and in the jump function as well as resetting the main gravity when finished. My game is heavily reliant on physics and gravity variables but I would prefer a proper work around on this too. Hope this gets an answer though.

Hey Heppell, I'm running into the same issue as the the OP, can you supply a brief code example of your solution?

Link to comment
Share on other sites

Yeah sure, I'm out at the moment and using my phone. I'll can detail what I'm doing to help for now and post code as soon as I'm back.

What I do is have the gravity set as standard. Now I have a jump function, not an update call for jump but its own function. Set up a key for jump (mine is spacebar). Then when spacebar isDown I set the gravity to a specific amount (overriding the world gravity) and set the velocity to suit. So my world grav could be 800. Then in my jump function I'll set the player gravity to 100 and the velocity to 150, then after the jump is complete, set the gravity back to normal. It was the only method I could come up with to work around the bugged physics. I'll post a comment section of code later to iterate :)

Link to comment
Share on other sites

My jump goes like this:

if (jumpButton.isDown && player.body.onFloor() && this.time.now > jumpTimer)            {                jumpTimer = this.time.now + 1000;                player.body.gravity.y = 150;                player.body.velocity.y = -150;            }            if(player.body.velocity.x > 0 || player.body.velocity.x < 0)            {                player.animations.play('walk')            }            if(player.body.velocity.x == 0)            {                player.frame = 0;                player.animations.stop();            }            if (jumpButton.isDown && player.body.gravity.y < 0 && player.body.blocked.up === true && this.time.now > jumpTimer)            {                jumpTimer = this.time.now + 1000;                player.body.gravity.y = -150;                player.body.velocity.y = +150;            }

I set the gravity and the velocity at the same time. So the jump can be a bit more controlled and forgiven considering the physics bug. This has since been fixed in 2.0 of phaser but im in too deep with 1.1.5

But this does the job you require anyway.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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