Jump to content

body.touching and body.blocked


gnack
 Share

Recommended Posts

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

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

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

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

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

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

 Share

  • Recently Browsing   0 members

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