# How should I go about developing a in-game grid?

Hello, I’m making a game similar to the likes of WorldBox, I’m currently trying to calculate movement of parts that will represent people.

How would I make a grid?

Can you please elaborate? I have never heard of WorldBox. But, to make a grid, you can specify how many studs are in each grid point. You can have…say a 4x4x4 grid where each grid spot is 4x4x4 studs and every part is sized to 4x4x4. You also do that with the coordinates. Something like this:

``````local function convertWorldToGrid(worldPoint)
local gridPoint = Vector3.new(
math.floor(worldPoint.X / 4),
math.floor(worldPoint.Y / 4),
math.floor(worldPoint.Z / 4))
return gridPoint
end

local function convertGridToWorld(gridPoint)
local worldPoint = Vector3.new(
math.floor(gridPoint.X * 4),
math.floor(gridPoint.Y * 4),
math.floor(gridPoint.Z * 4))
return worldPoint
end
``````

Could you possibly explain the math? I haven’t done this before, so I have a low understanding of what’s going on.

I think `math.floor` rounds down, but I’m not sure what the Grid Point and WorldPoint is…

The math is simple. `math.floor()` rounds down to the nearest integer. For a 4x4x4 grid, to convert from world coordinates (worldPoint) to grid coordinates (gridPoint) you divide (x, y, z) by 4. To convert back from grid coordinates to world coordinates, you multiple (x, y, z) by 4.

So, internally, your representation is your grid coordinates. But to do anything with the blocks, you must convert the coordinates to world coordinates to manipulate the block in the world.

1 Like