Vieo Posted March 17, 2014 Share Posted March 17, 2014 Hey. Using 2.0 and have a lovely tilemap and collision with a player. Although I want to use something like "player.body.touching.down" for weather or not a player should be able to jump. But dosn't seem to work is there some alternative? Link to comment Share on other sites More sharing options...
valueerror Posted March 17, 2014 Share Posted March 17, 2014 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 More sharing options...
Vieo Posted March 18, 2014 Author Share Posted March 18, 2014 Unfortunately i'm using Arcade physics. Maybe its time to switch.. Link to comment Share on other sites More sharing options...
kass Posted March 18, 2014 Share Posted March 18, 2014 im using arcade and for my game i had to useplayer.body.onFloor()the starstruck example game uses this Link to comment Share on other sites More sharing options...
valueerror Posted March 18, 2014 Share Posted March 18, 2014 with arcade there should be no problem detecting a touch down Link to comment Share on other sites More sharing options...
Recommended Posts