Offsetting a multidimensional array.

Hi guys!

The title says it all, but to be specific there is a base block at coordinates (0,0,0) which is stored in an array at [0,0,0]. If i add a block to the x axis its position will be (1,0,0) so its position in the array will be [1,0,0]. The problem is if i add a block to (-1,0,0) position i can`t add it to the array because there is no -1 index in an array.

As you can see i can place blocks freely in positive positions.

But if i want to build towards negative directions i can`t add the block to the begining of the array.

I was thinking about a nested for loop that would offset the array by one but i just couldn`t get it to work.

Can you guys please help me solve this problem or push me in the righ direction?

Storing in arrays or collections is necessary to know you data, but you should not represent it as coordinates. Use Vector instead (write your own or use Unity built in Vector3). You might want to consider defining object for each chunk. It might consist of something like this. If you will have a lot of chunks, optimize data per chunk as much as possible.

//pseudocode
ChunkObject{
  Vector3 position
  byte    texture  //index to texture array
}

But by default, Unity gameObject already owns Transform which consists of position.

Use an equation to create the positions. Base it on the index.

You don’t have to spawn item [x,y,z] at position (x,y,z). There’s no reason to. I mean, you know you could even roll a random position for each object?

Say you want them to start at x=-50 and be every 3.7 meters, use -50+x*3.7f.