The one-sided platform is not a feature in itself, it’s a suggested possible use for the “preCollision” event. It’s actually a standard example suggested in the Box2D manual, but there are probably other uses.
In general, “preCollision” tells you that the objects are close but not yet interacting, so you can then choose to write some game logic. To override an impending collision, you could turn one of the objects into a sensor by setting object.isSensor = true, and to override an impending collision from one direction, you could first compare the object.y values of the platform and the figure to decide which side it’s coming from. That’s the general idea here. The logical flow would probably look like this:
- Receive a “preCollision” event from the character/platform pair
- Check relative vertical position of character
- If character is approaching from below platform, set character to a sensor…
- …and also set a timer of 1-2 seconds so the player has time to jump “through” the platform…
- …then turn off the sensor property so the player interacts with solid objects again and “lands” on the platform.
Note that “close but not yet interacting” is a rather vague boundary, so you can get a LOT of “preCollision” events from the Box2D engine whenever things are sort of close to each other. For this reason, we advise using “preCollision” table listeners inside the specific objects you care about, rather than listening to “preCollision” in the global Runtime. [import]uid: 3007 topic_id: 1920 reply_id: 5879[/import]