How to make an area2d collide with tilemaplayer tiles with physics layers?

Godot Version

4.5.stable

Question

I want to use area2ds to detect tiles with collisions on physics layer 2, as well as physicsbody2ds on the same layer. I have physicsbody2d collision working but I can’t figure out how to get the tile collision to work - when I get it to print the overlapping bodies it ignores tiles. I’ve set my physics layers in the editor.

I’m using the get_overlapping_bodies function and I prefer this over a signal.

Any help would be appreciated

Did you add collisions to your tiles in the tileset?

yep. the tiles have collisions on layers 1 and 2 (the area2d is looking at layer 2) and the player collides with stuff on layer 1 so I know collision is working for the tiles.

Collision should be working with the area2ds as well because they collide with physicsbody2ds on layer 2

To be clear, do you want to know exactly which tiles it intersects with, or just the tilemap?

I just tried it and get_overlapping_bodies definitely works. I have an Area2D:

and a TileMapLayer:

The ball (Area2D) calls get_overlapping_bodies()and prints: Ball intersected body: TileMapLayer

Make sure your Area2D has both Monitoring and Monitorable enabled.

Now if you want to know exactly which tiles you are intersection with, you need to figure that out manually. There are numerous posts with other people doing the same thing, for example: https://www.reddit.com/r/godot/comments/s6hh7z/how_can_i_get_a_list_of_tiles_and_subtiles/

or you can ask your favorite agent to give you an example that you can adapt to your liking.

1 Like

Thank you! Turns out the issue was my Area2d didn’t have monitorable enabled - I didn’t know that tilemaplayers counted as monitoring areas.