Platform That Can Jump From Below And Land On Top

I’ve been trying this with isSensor = true / false on both the player object and the platform itself (as tried here : http://developer.anscamobile.com/forum/2011/12/23/any-platform-gurus-around)

The sensors solution simply doesn’t work. If a platform is switched to be a sensor, patrolling enemies or static items will fall off.

If the player is switched to be a sensor, should the platform be near a wall, the player being a sensor will go through or get stuck in the wall.

I’d like to use collision filters but they may only be set on creation of a physics body.

I’ve searched for dynamic alteration of physics body collision filters on runtime but none show any solutions (all pointing to a feature request but still nothing yet…) :

http://developer.anscamobile.com/forum/2010/11/08/changing-collision-filters-after-physics-object-created

http://developer.anscamobile.com/forum/2012/01/03/change-filter-criteria-collision

http://developer.anscamobile.com/forum/2011/06/14/set-box2d-collision-filtergroupindex-after-physics-body-added

http://developer.anscamobile.com/forum/2011/02/06/set-collision-filter-after-body-added

I’m using tiles to create the platforms so the current way of dynamically altering filters which is to remove and recreate the physics bodies seems like it will be a crazy thing to do.

Anyone have any better ideas on how to implement this? [import]uid: 118687 topic_id: 22947 reply_id: 322947[/import]

I had exactly this issue before and tried a variety of workarounds but it was oddly broken. I forgot exactly what I did to solve it (and I’m not sure the solution was superbly perfect either) but here’s what I wrote to Corona a year ago, perhaps it helps you (and feel free to email me if you’re interested in my project’s code):

“In the end, what would have been needed in Corona for this is the ability to change a body from collidable to non-collidable “air” while the game runs, but flipping body.isBodyActive is ignored. This doesn’t seem to be possible, and canceling the event bubbling in the preCollision handler also doesn’t work for this purpose. The workaround I had to come up with was pretty big, I believe I ended up using special objects and replacing them with outside objects on the go. I had to give up that game due to speed issues though, so I’m now working on a new other Corona game.”
Also see
http://developer.anscamobile.com/forum/2010/12/04/how-set-so-it-only-detects-collision-top-object
https://developer.anscamobile.com/forum/2010/11/26/how-create-platforms-player-can-jump-otherwise-walk-through-using-precollision [import]uid: 10284 topic_id: 22947 reply_id: 91782[/import]

I think Jon Beebe’s Dungeon Tap game does something like this. Perhaps he has a suggestion?
http://beebegames.kodingen.com/

It’s like Doodle Jump in that you jump through platforms and land on them, but objects on the platforms don’t fall through. [import]uid: 10389 topic_id: 22947 reply_id: 91794[/import]

Oh and I’ll shoot jon beebe a PM and see if he has anything up his sleeve at all in case that isn’t what he did :slight_smile: [import]uid: 118687 topic_id: 22947 reply_id: 91844[/import]

Philipp: Thanks for the insight into those threads, i’ll study them further and come back with what solution I find.

WauloK : It looks like john beebe uses player.isSensor = true on collision and if player.y > platform.y then player.isSensor = false.
This works fine for most circumstances but comes unstuck when you have two platforms in close proximity to each other (notice how far apart all the platforms are from each other in dungeon tap) :

When there is two platforms one on top of the other. Should you go through the bottom one, you come into contact with the platform on top. Since the player is still in contact with a platform (the top one) he will remain a sensor and fall through both platforms.

In the worse case scenario I may have to remove / readd physics bodies in order to adjust bitmask / categoryMask numbers on the fly. My tiles are 64x64 and the player comes into contact with about 3-6 of them at a time. I’m not sure what the performance hit will be to be constantly doing this (nor is it a very pleasant thing to do to reconstruct X tiles and individually setting all the parameters again) but I’ll see should Phillip’s suggestions not work out. [import]uid: 118687 topic_id: 22947 reply_id: 91843[/import]

Hey mattai.

Just to throw another suggestion into the pot, but how about not using physics at all?

I saw a post a while back (possibly from oz apps) warnng on the dangers of forcing yourself to use physics just because it’s already implemented.

How about checking if the hero.x and hero.y overlap those of a platform and stopping him when he’s in the right position?

I did a couple of XNA tutorials a while back. They had to use this method as there was no physics implementation available.

Alternatively, as another suggestion, could you monitor your characters velocity and if hero.veloctiy < 0 then object:isSensor == false.

That’d only allow passage through the platforms whilst jumping, until gravity takes over and he starts falling, then they all become solid.
[import]uid: 67933 topic_id: 22947 reply_id: 91864[/import]

>>monitor your characters velocity and if hero.veloctiy < 0 then object:isSensor == false<<

+1 spider
I was just about to suggest something similar, but dont know if it is possible when an object is in flight.

It seems to me that if you CAN, then when the player’s x velocity is upwards, make all the platforms into sensors and allow him through.
As soon as the apogee is passed, and the x velocity is downwards, switch them into statics and he wont fall back through.

Sorry if that isnt possible using the standard library: its just a thought. [import]uid: 108660 topic_id: 22947 reply_id: 91878[/import]

Thanks for the suggestions spider_newgent. I think the first suggestion will still fall prone to this issue, as does any use of sensors on the player :

http://i.imgur.com/sCmzP.jpg
http://i.imgur.com/sCmzP.jpg

edit: image tags dont seem to work

Utilising sensors on the platform means existing objects sitting on the platform will fall off when the platform becomes a sensor. [import]uid: 118687 topic_id: 22947 reply_id: 91877[/import]

Ah but using sensor switching on platforms makes existing objects sitting on them fall off!

And using sensor switching on the player gives you this issue with platforms placed close together :

http://i.imgur.com/sCmzP.jpg [import]uid: 118687 topic_id: 22947 reply_id: 91880[/import]

>>Ah but using sensor switching on platforms makes existing objects sitting on them fall off!<<

Doh!
Of course it does.
So does making the player a sensor until he starts to fall do the trick?
[import]uid: 108660 topic_id: 22947 reply_id: 91904[/import]

Technically it does, yes. However situation as explained in the top right hand of my diagram :

http://i.imgur.com/sCmzP.jpg

means he will still fall through again (as contact with the upper platform will keep him as a sensor)

Ideally I would want to be able to dynamically change categoryGroup / bitGroup in physics bodies. This is possible in box2d but Corona didn’t expose it in their implementation for some reason. I’ve tagged onto a feature request in the suscriber forum but it hasn’t gotten much attention yet. Heres hoping! [import]uid: 118687 topic_id: 22947 reply_id: 91909[/import]

Ok I think I have a solution.

Make every platform a sensor initially. Allow the hero to move through each platform. Listen for each collision phase. If phase == ended then set that individual platform to Object:isSensor == false.

That way he can only collide with those platforms he’s already passed through, removing your problem.

For the inevitable situation of the hero hitting sensor platforms on the way down simply test for “if hero.y > platform.y then platform:isSensor = false”

For the objects on the platform, the only thing I can think of is to remove then replace them with static versions once they come to rest, (velocity = 0). That presumes they are initially falling/moving. If they don’t move at all, then maybe set the objects up as static to begin with?

Does that make sense? [import]uid: 67933 topic_id: 22947 reply_id: 91914[/import]

Yes it does I think. In essence you are suggesting to do the reverse and make platforms sensors on collision as opposed to the player? I tried that before and it leads to the objects falling through platforms issue.

As for the workaround on that, that would work if the objects were say enemies patrolling a predetermined path or static items, but unfortunately they are enemy objects that patrol and jump freely from platform to platform with a reasonably intelligent AI to chase the player etc.
[import]uid: 118687 topic_id: 22947 reply_id: 92097[/import]

Another possible suggestion:

Use the collision filters, but overlap two different sets of platforms. The baddies interact with one set, your player with another. That way your baddies stay on their platform, but your code can take advantage of the isSensor switching to allow your player to move up. If the platforms occupy the same space but do not interact (via the collision filters) you effectively create one composite platform with different collision filtering rules for the player and the baddies. [import]uid: 64596 topic_id: 22947 reply_id: 92100[/import]

Thats a very interesting solution shane! I’ve gone through it in my head and i can’t see why it couldnt work. I’m tackling another problem at the moment but once I get it done I’ll try implementing your solution and see what comes out of it. Will report back tonight! [import]uid: 118687 topic_id: 22947 reply_id: 92108[/import]

Looks to have done the trick shane. Thanks for the input! And finally a fully complete solution for seems to have been a long standing problem in the community. Many thanks [import]uid: 118687 topic_id: 22947 reply_id: 92315[/import]