Let’s say you have a small grid of the dimensions 4x2x4 that looks like this:
The ‘origin’ of the grid would be the marked blue square, which is stored at index Grid[1][1][1]. Let’s say this Part has been assigned the CFrame CFrame.new(0, 40, 0)
and let’s say that each block has a size of Vector3.new(5, 5, 5)
.
Whether the orange block has been mined would be stored at Grid[4][2][1]. If Grid[4][2][1] equals false (not mined) and any of its surrounding blocks has been mined, you would need to generate that orange block. How do we figure out where the orange block needs to be positioned? Well, we use the indexes multiplied by the size of a block. That would be:
local OrangePosition = Vector3.new(4, 2, 1) * Vector3.new(5, 5, 5)
However, this is an offset relative to the blue block, so we will need to apply the offset afterwards:
OrangeBlock.CFrame = CFrame.new(0, 40, 0) * OrangePosition
That would put the orange block at the correct position relative to the grid’s origin (which is the blue block). This way we don’t need to store the position of each block, we can simply calculate the position based on the indexes in the Grid table!