I'm creating platforms in my game where the player can:
1) Jump through them from the bottom and land on top of them
2) While on top of them, drop down through them
I've been able to get #2 working just by disabling the contact using contact->SetEnabled(false) and this has worked fine. I'm mainly having some issues on the best way to handle #1. Here's the basic idea I have, though there's still some things that I need to concretely figure out. (Note: The logic below is very Box2D specific, but should apply to most physics engines):
- Add 4 sensor fixtures to the 4 sides of the main fixture that extends a small amount past the main fixture
- When the top, left, or right sensor fixtures make contact with a platform, disable the contact by using contact->SetEnabled(false) and set a boolean flag inside the Sprite object indicating that the Player is passing through the platform
- When the bottom fixture ends contact with the platform, disable the boolean flag
This would basically make the top, left, and right fixtures act as enablers for the pass through logic and the bottom fixture act as the disabler. So when the player is falling back down from their jump, the bottom fixture will make contact, but won't disable the contact.
This makes sense on paper, but I can think of a few corner-case issues that might arise from this. Before I start plugging down this path, does anyone have any suggestions that might make my plan better or even a completely different way of doing it?