0 votes

Hello everyone, new member here. I need a little help, I asked this question before on reddit but I haven't found a solution yet.

I have a main Scene World, in that I have a TileMap and a Area2D (see here).
TileMap is the brown wall texture, and Area2D is the Godot logo.

My goal here is find whichever tile overlapped by Area2D and remove them. As you can see the Area2D overlap 2 tiles and I able to print the current overlapped tiles which they have the same ID (?).

extends Area2D

func _on_ClearBox_body_entered(body):
    for i in self.get_overlapping_bodies():
        if i is TileMap:

I can't seem to remove the overlapped tile. I tried to use set_cellv but I can't get the position of those tiles, i.global_position() return (0,0)

What I'm missing here? Thanks everyone.

Godot version 3.5.1
in Engine by (12 points)

1 Answer

0 votes

The tilemap counts as one giant body. Since in this case the area is a rectangle, you can use Rect2 methods to find the overlapping cells.

by (8,528 points)

Thank you for your comment. But can you explain further the Rect2 methods?

Use the intersects method

so area_rect.intersects(Rect2(cell_x, cell_y, tile_x, tile_y))

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.