How do I create "Fall-Through" platforms?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bobbydickins

I am using a tilemap and would like some of the tiles to be “fall-through” so that the player can fall through them when the down arrow is pressed.

The problem with this is I am unsure how to disable collisions on just one tile. Some people have suggested to just have different tilemaps for different types of tiles but even in that case I would run into problems if there were a fall-through platform directly under another one. I think it would be bad to disable the collisions on the whole tilemap because there would be no way to tell when the player lands on the next fall-through platform. Having the disabled collisions on a timer also seems like a very hacky and inefficient way to do things.

Does anyone have any solutions for something like this?

:bust_in_silhouette: Reply From: Diet Estus

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.