Check if space is occupied in gridmap

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

Hello i have a gridmap with tiles in different sizes. The user can set cells in this gridmap, but I need to check if the space is occupied before (a tile can reach over to other tiles).

I tried to use an area, but areas can’t detect the collision of staticbodys from a meshlib.

Is there any easy solution or do I need to use raycasts?

Have you tried looking into simple collision detection? For example, I’ve toyed with axis-aligned bounding boxes (AABB). If you can, get an AABB for the potential spot in theGridMap and check it against what the user wants to place there.

Ertain | 2020-05-28 23:43

any other links? i dont understand your idea :slight_smile:

MarcPhi | 2020-05-29 00:51

You wrote that the collisions of Areas can’t detect the StaticBodys of the GridMap cells. Why not have an AABB (the 3D equivalent of the Rect2) which takes the place of any currently-occupied spaces? When a user tries to place a cell in some location, first check the AABB of the potential cell against what may be currently occupying that location.

Ertain | 2020-05-29 04:23

Did you find a solution for it ?

ATHellboy | 2021-12-08 18:16

:bust_in_silhouette: Reply From: jgodfrey

Why not just maintain a simple 2D array that represents the “occupied” state of your map? So, each time a User attempts to drop a tile, you just check the same position in the 2D array to see if it’s empty or not. If it is, allow the tile to be dropped and update the cell in the array to indicate that tile is occupied…

then i would need to calculate the occupied space by an object first, because an object can be bigger than one tile and the tile can also be rotatet.

MarcPhi | 2020-05-28 23:59