Hello.. I am currently writing code to transform a zero-based, 1D array into a 2D array to visualize my terrain grid.
Currently, it creates a square grid with as many rows/columns equal to grid_size.
while (...)
var x = index % grid_size
var z = index / grid_size
var offset = (grid_size - 1) / 2
var grid_pos = Vector2i(x - offset, offset - z)
Then I multiply the instances grid_pos by its size to space them evenly ...
instance.position = Vector3(grid_pos.x * CHUNK_SIZE, 0, grid_pos.y * CHUNK_SIZE)
Odd
My current grid is 3x3 (an odd grid_size) and it produces these 2d coordinates:
(-1, 1)
(0, 1)
(1, 1)
(-1, 0)
(0, 0)
(1, 0)
(-1, -1)
(0, -1)
(1, -1)
... This is great, because an odd grid has a center tile which is positioned at 0, 0.
Even
When the grid_size is an EVEN number, no one tile can be at the center. -meaning:
... the 0 coordinate should be taken by the four adjacent tiles that are around the center.
e.g. (-1, 1), (1, 1), (-1, -1), (1, -1)
Instead; I get these 2d coordinates which produces an un-centered grid:
(0, 0)
(1, 0)
(0, -1)
(1, -1)
EDIT:
I am mainly trying to map the grid pos to integer coordinates!
If the grid size is even, no grid_pos output should be at x=0 or y=0.
😵💫