Jump to content

Ninja physics player touching ground


rjungemann
 Share

Recommended Posts

Good afternoon,

 

I have been dabbling on and off with Phaser for awhile (and I'm a long-time Flixel user). I am making a game, but I need inclines, so I am using the Ninja physics engine. I am building off of the Ninja example provided in the "phaser-examples" repo.

 

Everything is working great, except now I need to know if the player is touching the ground. This works for regular tiles, but for inclines, it is registering the player as touching "none".

 

I have some complicated code to try and determine if the user is touching ground (by looping through the tiles it is touching, averaging the angles, and if it is within some fudge amount of 180 degrees, the player is touching), but it is error-prone.

 

Any suggestions?

Link to comment
Share on other sites

It's not perfect, but here's my current solution. Let me know if there's something better.

var inAirvar sprite1; function create() {  // Some stuff here...   // Setup `sprite1`...    // This will get called when `collideCircleVsTile` is called and collison is reported  var oldCollisionCallback = sprite1.body.circle.reportCollisionVsWorld;  sprite1.body.circle.reportCollisionVsWorld = function(px, py, dx, dy) {    oldCollisionCallback.call(sprite1.body.circle, px, py, dx, dy);     var fudge = Math.PI * 0.33; // Tweak this to your liking    var angle = Math.atan2(dx, dy);     if (angle < 0) {      angle += 2.0 * Math.PI;    }     if (angle < Math.PI + fudge && angle > Math.PI - fudge) {      inAir = false;    }  }    // Some stuff here...} function update() {  inAir = true;  for (var i = 0; i < tiles.length; i++) {    var tile = tiles[i].tile;    sprite1.body.circle.collideCircleVsTile(tile);  }  // Some stuff here...}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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