gnack Posted April 24, 2014 Share Posted April 24, 2014 Hi guys, I'm trying to create a very, very basic platformer where the player is able to pass through platforms in every direction other than down. In other words, they can land on platforms, but they can also jump up to a platform from below and then land on that platform on the way back down. Think Sonic the Hedgehog for example. So, I guess my question is simple - how would I check for collision in only one direction on a platform? If looked at using the collision processor but I can't using the body.touching and body.blocked objects in there because they don't get set until AFTER collision has already occured. Link to comment Share on other sites More sharing options...
Heppell08 Posted April 24, 2014 Share Posted April 24, 2014 In update set all the body blocked positions to false except the down position. That 'should' be what you're looking for. Link to comment Share on other sites More sharing options...
valueerror Posted April 24, 2014 Share Posted April 24, 2014 using arcade physics you can define a custom collision handler.. if this one returns true a collision happens. so in this handler function you can check your player movement if (player.body.velocity.y > 0) {return true;} return false; this way it will only collide if the player is falling down and not jumping up. Link to comment Share on other sites More sharing options...
gnack Posted April 24, 2014 Author Share Posted April 24, 2014 In update set all the body blocked positions to false except the down position. That 'should' be what you're looking for. Not sure what you mean, this doesn't work. I might not have explained what I want to do properly. Basically I want to only collide with the platform if the player is falling from above the platform. using arcade physics you can define a custom collision handler.. if this one returns true a collision happens. so in this handler function you can check your player movement if (player.body.velocity.y > 0) {return true;} return false; this way it will only collide if the player is falling down and not jumping up. This is sooooo close. It works almost perfectly but unfortunately the player still collides with the sides of the platform while falling (since velocity.y is > 0). In other words if you're jumping to the left or right and on the way down you hit the side of a platform, you'll get blocked. I can't figure out how to work around this issue. Link to comment Share on other sites More sharing options...
valueerror Posted April 24, 2014 Share Posted April 24, 2014 you could make the rectangle that describes the physics body of the platform really slim.. more like a thick line than a rectangle.. that way there are allmost no sides to collide with .. ?? (at least in p2 physics this would cause some problems because if the platform is too thin the player falls through... ) do you have a online example ? id really like to test this Link to comment Share on other sites More sharing options...
gnack Posted April 24, 2014 Author Share Posted April 24, 2014 you could make the rectangle that describes the physics body of the platform really slim.. more like a thick line than a rectangle.. that way there are allmost no sides to collide with .. ?? (at least in p2 physics this would cause some problems because if the platform is too thin the player falls through... ) do you have a online example ? id really like to test this Sure, don't laugh, it's just a test game http://gnack.me/games/doobie Link to comment Share on other sites More sharing options...
valueerror Posted April 25, 2014 Share Posted April 25, 2014 you could disable collision down left and right for the platform completely... platform.body.checkCollision.down =false Link to comment Share on other sites More sharing options...
Heppell08 Posted April 25, 2014 Share Posted April 25, 2014 you could disable collision down left and right for the platform completely... platform.body.checkCollision.down =falsePretty much the same as blocked or touching set to false except the on side necessary for collision Link to comment Share on other sites More sharing options...
valueerror Posted April 25, 2014 Share Posted April 25, 2014 @heppel i don't think i understand you .. is this good or bad? i thought if you would set this on the platform not on the player this could be a way to go.. without a special collision handler .. but i didn't try it Link to comment Share on other sites More sharing options...
Heppell08 Posted April 25, 2014 Share Posted April 25, 2014 It the same both ways. Makes no real difference really. If it works then it works Link to comment Share on other sites More sharing options...
gnack Posted April 26, 2014 Author Share Posted April 26, 2014 It the same both ways. Makes no real difference really. If it works then it works I get what you were saying now, my apologies. Unfortunately doing it on the player wouldn't work because I still want to collide on the left and right of the player so he doesn't run through the walls. But yeah, I can disable collision for the platform's unnecessary sides so thanks to both of you for the answers! Link to comment Share on other sites More sharing options...
Heppell08 Posted April 26, 2014 Share Posted April 26, 2014 Easiest answer to that is to set blocked up to false and that would be it. Left and right would collide and the bottom would collide too. But there is multiple ways of making this work and whichever works, go with Link to comment Share on other sites More sharing options...
Recommended Posts