Detect tiles in Tilemap touching an Area2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Afely

Basically, I’m trying to find specific tiles that are inside of an Area2D and delete them. I have an idea on how I could this, but it would be really complicated and barely functional. Is there any easy way to do this?

:bust_in_silhouette: Reply From: scrubswithnosleeves

Yeah,

I haven’t done this, but I think you should be able to do get_overlapping_bodies() in your Area2D script (returns a list of the bodies in the area). So something like:


func _ready()
    for body in self.get_overlapping_bodies():
         body.queue_free()

This assumes that you have collision shapes on the tiles and that they are on a collision layer that the Area2D interacts with.

But that would delete the whole tilemap, because if you use get_overlapping_bodies() it returns the tilemap node, not individual tiles, right?

Afely | 2020-12-23 08:33