You can build collision into your tilemaps.
For the one-way platform tiles, just add a StaticBody2D
with CollisionShape2D
and set the CollisionShape2D
attribute one_way_collision = true
. You can also toggle this from the inspector.
Then all you need is a method which allows your player to drop through such platforms. Here is an example of such a method:
func drop():
position.y += 1
This method moves the player down one pixel. If he is standing flush on a one-way platform, this shift will drop him below the one-way threshold and he will continue falling.
I use a variant of this function in my own platformers, though I check to make sure the player is standing on a one-way platform first. You can build such a check into the drop()
method before you shift the player's position. You can use a short downward raycast to perform such a check.