TileMaps: How to check if a body is in tile.

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

I am doing dynamic obstacle avoidance and disabling the tile when a body is detected.
Now I need to figure out how to re-enable the tile. I am storing the disabled tiles ids in an array. I need to figure out if the tiles with these ids still have the physics bodies in them. If not then re-enable.

So any tips on how to do this will be appreciated?

Have the tile locations have been mapped to the array? If that’s the case, change the status of the tile each time the player enters and exits the tile’s collision.

Ertain | 2022-06-07 00:49

It’s mostly the npcs that are being checked. I want to limit too much happening every frame. I think I will just use a timer for now. 2 second timer to re-enable all the tiles in that array and remove them from the array.

Thank you for your comment

Skydome | 2022-06-07 07:39

:bust_in_silhouette: Reply From: Leotti

You could take the body’s position and check if there’s a tile there using get_cell() on the tilemap. You’ll need to use to_local() to get the right vectors.
This might not be super accurate with bigger bodies because the colliders might expand very far from the actual node.

:bust_in_silhouette: Reply From: nukzhy

cant you use an area 2d in each tiles to detect collision?
unless its a big game it probably shouldnt lag

Hi, thanks for answering. I think I will avoid having too many area2Ds in this way. My game I don’t know if it qualifies as big but it’s not small.

Right now I have decided to just re-enable without checking every 2 seconds and it’s working great. So I guess that makes this question moot for me.
Basically things like walls, trees, rocks are disabled in the beginning. These things don’t change so they stay disabled all the time.

But the tiles where NPCs are get disabled when something gets near them. And then this ‘thing’ finds a new path. 2 seconds later this tile gets re-enabled.

Skydome | 2022-06-08 18:41

:bust_in_silhouette: Reply From: Skydome

Right now I have decided to just re-enable without checking every 2 seconds and it’s working great. So I guess that makes this question moot for me.
Basically things like walls, trees, rocks are disabled in the beginning. These things don’t change so they stay disabled all the time.

But the tiles where NPCs are get disabled when someone gets near them. And then this person finds a new path. 2 seconds later this tile gets re-enabled.