0 votes

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?

asked May 28 in Engine by MarcPhi (33 points)

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.

any other links? i dont understand your idea :)

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.

1 Answer

+1 vote

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...

answered May 28 by jgodfrey (5,706 points)

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.

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.