yanliom Posted December 6, 2014 Share Posted December 6, 2014 Hello, while modifying the phaser tutorial_02 code, and using the arcade physics, I discovered that while "dude" collides with the platform while moving from up to bottom, he passes over it while moving from bottom-to-up.See here a live example: http://83.212.238.173/phaser_tutorial_02/part9_mod.html Is that a problem regarding the Arcade physics? Link to comment Share on other sites More sharing options...
jpdev Posted December 7, 2014 Share Posted December 7, 2014 The problem is, that you are setting the x & y values of the player directly. Arcade physics only works if you use the velocity values.Based on the velocity, the arcade engine moves the sprites itself, and then all collisions work, You (and I) may wonder, why the collision from above did still work in your example.This is because the gravity is still on.(Gravity sets the y velocity to a negative value, the physics collisions happen (that is why it only works on the negative y axis) and then you reset the velocities to 0, so no actual gravity is visible.) The solution for you (I think you are going for a zelda style movement with no gravity right?) is: 1) set gravity to zero2) instead of increasing / decreasing the player.body.x & y set the body.velocity.x / y to values like 100 (while keeping your reset to zero where it is now, so that the player stops if no key is pressed) Link to comment Share on other sites More sharing options...
yanliom Posted December 7, 2014 Author Share Posted December 7, 2014 Thank you very much! Your answer was very explaining.Finally as you proposed, I solved the problem by setting gravity to zero, and moving the player using velocity. I also found a similar solution in the examples: http://examples.phaser.io/_site/view_full.html?d=arcade%20physics&f=sprite+vs+group.js&t=sprite%20vs%20group Link to comment Share on other sites More sharing options...
Recommended Posts