+2 votes

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?

in Engine by (30 points)

1 Answer

+4 votes

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.

by (1,567 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.