TileMap Collision Layer

Godot Version

v4.4.1.stable.official [49a5bc7b6]

Question

I have an object that has an Area2D. I also have a tilemap that has patterns of grass, sand etc. I created different collision layer for each pattern (grass or sand). But both patterns can be in a single tile also.
Is it possible to get which collision layer of TileMap is ‘collided’ with object’s Area2D?
I think area_entered and area_exited signals of the Area2D object don’t work with how TileMap physical layer is set. So I can only use body_entered and body_exited. But I can’t get the information of which collision layer of the tile_map is collided with Area2D of the object.

I believe a way to do this is to use multiple Area2Ds, one for each layer, which all have their masks set to only include their own layers.

Then you can make a function for each layer’s signal that passes on its index to some other process:

func _body_entered_layer_1() -> void:
	_body_entered(1)

func _body_entered_layer_2() -> void:
	_body_entered(2)

# ...

func _body_entered(layer: int) -> void:
	print("Body entered layer '%d'" % layer)
1 Like

This sounds like a good workaround. I’ll try that. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.