Jump to content

Tilemap - Player collision


Vieo
 Share

Recommended Posts

not that i know of right now..  but you can solve this with this function for now...

 function touchingDown(player){        var yAxis = p2.vec2.fromValues(0,1);    var result = false;    for(var i=0; i<game.physics.p2.world.narrowphase.contactEquations.length; i++){    var c = game.physics.p2.world.narrowphase.contactEquations[i];        if(c.bi === player.body.data || c.bj === player.body.data){            var d = p2.vec2.dot(c.ni,yAxis); // Normal dot Y-axis            if(c.bi === player.body.data) d *= -1;            if(d > 0.5) result = true;        }    }    return result;}

or for the left side :

function touchingLeft(player){    var xAxis = p2.vec2.fromValues(1,0);    var result = false;    for(var i=0; i<game.physics.p2.world.narrowphase.contactEquations.length; i++){    var c = game.physics.p2.world.narrowphase.contactEquations[i];        if(c.bi === player.body.data || c.bj === player.body.data){            var d = p2.vec2.dot(c.ni,xAxis);            if(c.bi === player.body.data) d *= -1;            if(d < 0) result = true;        }    }    return result;}

if you want  touchingRight just change the < 0 in the last if statement to > 0    (be aware that changing d > 0.5 to something smaller like d > 0 will lead to false touchingDown positives..  

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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