The Grid is back online!
Now that I have a raycast to go from mouse cursor to 3D coordinates in the XZ plane, I need to be able to place buildings! for that I need the grid to translate the XZ position into grid coordinates, which will bring us back to the realm of 2D and therefore allow us to reuse the code from Fadunn 0.1 with minimal modifications.
It was quite easy to get the function working, I just had to change from cell.x = int(mouse.x / cellsize) * cellsize + (cellsize/2)
to cell.x = round(mouse.x / cellsize) * cellsize
.
The int function truncated the result, leading to a slight but bothering offset in the result, the round() works much better. And the "+ (cellsize/2)" had to go because my 3D blocs don't have the half-cell offset that the 2D tileset had.
Most of the work went into importing the files from the old project, because I didn't use the same file structure and it broke a lot of references, but once that was fixed everywhere it worked like a charm.