Jump to content

How to check if on Floor using P2?


swissnetizen
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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