swissnetizen Posted April 10, 2016 Share Posted April 10, 2016 Hey, So I need to check whether a sprite is on the floor using P2 physics. Basically something like Arcade.onFloor() but for P2 physics. Link to comment Share on other sites More sharing options...
megmut Posted April 10, 2016 Share Posted April 10, 2016 There is an example in the phaser p2 examples section, see here for more : http://phaser.io/examples/v2/p2-physics/collision-groups Link to comment Share on other sites More sharing options...
swissnetizen Posted April 11, 2016 Author Share Posted April 11, 2016 I don't think you understood. I want to check if it's on a floor outside of an event handler. The example uses event handler with collision groups that's not what I want to do Link to comment Share on other sites More sharing options...
swissnetizen Posted April 13, 2016 Author Share Posted April 13, 2016 For future reference, this is how to detect if the entity is on the floor (I think): var checkIfCanJump = function() { var c, d, i, result, yAxis; yAxis = p2.vec2.fromValues(0, 1); result = false; i = 0; while (i < game.physics.p2.world.narrowphase.contactEquations.length) { c = game.physics.p2.world.narrowphase.contactEquations[i]; if (c.bodyA === player.body.data || c.bodyB === player.body.data) { d = p2.vec2.dot(c.normalA, yAxis); if (c.bodyA === player.body.data) { d *= -1; } if (d > 0.5) { result = true; } } i++; } return result; }; from: http://phaser.io/examples/v2/p2-physics/tilemap-gravity Link to comment Share on other sites More sharing options...
Recommended Posts