toto88x Posted March 3, 2014 Share Posted March 3, 2014 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 More sharing options...
Heppell08 Posted March 3, 2014 Share Posted March 3, 2014 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 More sharing options...
CarrotIsland Posted March 13, 2014 Share Posted March 13, 2014 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 More sharing options...
Heppell08 Posted March 13, 2014 Share Posted March 13, 2014 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 More sharing options...
Heppell08 Posted March 14, 2014 Share Posted March 14, 2014 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.5But this does the job you require anyway. Link to comment Share on other sites More sharing options...
CarrotIsland Posted March 14, 2014 Share Posted March 14, 2014 I totally see what you're talking about now. Great workaround!Coincidentally Phaser 2.0 dropped today so, I'm going to try that out first. If somehow I still can't get the jump right, I mayl work your method in. Thanks again! Link to comment Share on other sites More sharing options...
Heppell08 Posted March 14, 2014 Share Posted March 14, 2014 The 2.0 has a fix on physics and jumping and I'm actually in the long and hard process of migrating over to 2.0 to remove my workaround and have a 'proper' method. But yeah my method does work well if it was ever needed then its there. Link to comment Share on other sites More sharing options...
Recommended Posts