0 votes

I need my explosion to destroy tiles, but when the explosion area collides with the tilemap, it returns: [TileMap:1278], meaning I cannot get an individual tile's position.

in Engine by (74 points)

1 Answer

+1 vote
Best answer

The whole point of a TileMap is that the tiles are batched together and treated as a single image and a single collider. This makes tilemaps much more efficient, but means you can't treat individual tiles as separate objects.

If you want to find which tiles are affected by the explosion, you'll have to find that using the explosion's position - convert it to map coordinates using world_to_map() - and calculating the tiles that are within a certain distance of that point. You can remove a tile by setting its index to -1.

by (20,483 points)
selected by

I already came to that conclusion - I wanted to know if there was a better way.

What's the best way of calculating what tiles were hit? My explosion is circular, so I cannot use Rect2.

The "Midpoint Circle Algorithm" is probably your best bet here. Here's a starting point I found with a quick search: https://gamedev.stackexchange.com/questions/72708/how-can-i-calculate-all-squares-within-r-in-a-natural-looking-manner

Thanks for your help!

In case anyone's interested, I ended up with this:

func purge_circle(pos, radius):       
    for y in range(-radius - 1, radius + 1):
        for x in range(-radius - 1, radius + 1):
            if (x * x) + (y * y) <= (radius * radius):
                set_cellv(pos + Vector2(x, y), -1);
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 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 webmaster@godotengine.org with your username.