Godot Tilemap and Area2D Collision

Godot Version

4

Question

I’m trying to use TileMap with an Area2D to detect a collision without having any physical effect but just to call a callback via some signal.

The purpose is having a TileMap of a ladder and the ladder should change the logic of movement rather than actually act as a wall. This can be done either by having a signal on the ladder or on the player detecting the opposite and setting some is_climbing boolean.

TileMap itself does not seem to be detected by an Area2D and putting a collection of scenes seems like a redundant waste of performance.

Am I missing something? How can I get this to work?

If you just want to check if you are in front of a ladder it’s pretty simple to check what tile is at a cell position, using cell_position = tilemap.local_to_map(tilemap.to_local(global_pos))
And then

tile_src_id = tilemap.get_cell_source_id(layer_index, cell_position)
tile_atlas_pos = tilemap.get_cell_atlas_coords(layer_index, cell_position)
if tile_src_id == ATLAS_WITH_LADDER and tile_atlas_pos == LADDER_TILE:
  # On the ladder tile
  ...

If you want to check wider than just the character’s center then test two points to the left and right of the character’s center, it’s a cheap test so you should be able to do it a lot.

1 Like

if there’s more than one ladder tile you can do

if tile_atlas_pos in ARRAY_OF_LADDER_TILES:

Hey, thanks for the reply.

How can I setup ARRAY_OF_LADDER_TILES in an automatic manner

You can’t set it up automatically, but if you want to define it in the tileset rather than the code you can use a “Custom Data Layer” in the tileset, and then loop through the whole atlas at startup to make the array of ladder tiles

1 Like

Sounds like it’ll do the job. Thanks.
Do you know if tilemaps are expected to support Area2D like a physics object in the future to prevent these kind of workarounds?

They should be able to detect tilemap’s physics bodies, for example, see the docs on the body_entered signal in area2D. If it really isn’t working it could be a bug that needs to be reported