Add Area2D behaviour in a Tilemap

Godot Version

Godot 4.2.2

Question

I currently make a 2d platformer and I want to have a door at the end as a tile. When the player touches the door, I want him to win. I only know about Physics Collision that Tilemap provides. Is there something similar but as a sensor only(like Area2D). Thanks in advance!

i might not understand the question but…

A TileMapLayer can hold images or scenes. If you make a Door scene that is a Sprite2D + Area2D + custom script that makes you win you can add that as a tile. Then in the tile map painter you can paint winning doors all over the place.

You’ll need an Area2D with a CollisionShape2D, and an on_body_entered signal to trigger whatever code you want. I’m using that for the doorways in my RPG demo. I hope this is a good start.

1 Like

I was just wondering if you could do the same with a tile inside a tilemap. But thanks for the alternative!

Thanks for the answer, but I use Godot 4.2.2. I think TileMapLayer is in Godot 4.3, so I don’t understand it properly.

Not a problem. TileMap in 4.2 works the same way.

i went ahead and made a demo for you:

Here’s how it works:

  1. Create a Door scene. Sprite2D with an Area2D. Give it script.
  2. Create a TileMap.
  3. In the TileSet editor, clik on the + (bottom left, next to the trash can) and create a Scenes Collection.
  4. Drag Door to the drag and drop area (right half of the window).
  5. In Tile Map painter, paint a door on your TileMap.

In the example, Player is collision layer 2 so Door’s collision mask is set to 2. When he bumps a Body he pops up a window to let you know.

Screenshot 2024-10-01 080138

2 Likes

Awesome work. 11/10.

There are very few questions i can answer and i ask so very, very many. If i can (finally) answer a question, i want to do my best. As a thank you to everyone who put up with my questions.

1 Like

Now I get it. Thanks for the help. Really appreciate it.