How to check if on Floor using P2?

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 < {
    c =[i];
    if (c.bodyA === || c.bodyB === {
      d =, yAxis);
      if (c.bodyA === {
        d *= -1;
      if (d > 0.5) {
        result = true;
  return result;




Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.