- Home /
Chunk position algorithm
Hello, I'm making a Minecraft clone but I'm a bit stuck right now.
So first this is what I want to do:
My chunks are 16x16x16 big and I have 10x10x10 loaded chunks.
Because I don't want to instantiate a new Chunk every time, I thought I could "recycle" the old ones.
So when a Chunk gets out of the view range, it is clear that on the other side is missing one. But I can't seem to find a solution of how to compute the new position. Especially when the player walks diagonal.
Right now I'm storing all 10x10x10 Chunks in a static list.
Maybe even that's not the best solution.
Please let me hear what you think.
Answer by Cherno · Sep 14, 2014 at 11:34 PM
Do you actually need to move or instantiate any chunks? I think it's perfectly fine to have all chunks in any position in thegame world, like 0,0,0, and have the 10³ chunks instantiated at game start. After that, it's just a manner of changing a chunk's vertex positions instead of the chunk itself.
I'm curious as to how floating point error may creep in just moving the vertices. Even though when the chunk gets 'moved', the vertices are reassigned anyway so why not.
At the moment, this is not a question more than a theory discussion. Without knowing how your chunks are managed, it is impossible to answer. For example : your world generator makes a grid of chunks :
for ( Z loop )
for ( X loop )
worldPos = Vector3( X * tileSize * chunkSize, 0, Z * tileSize * chunkSize );
worldChunk[x,y] = Instantiate( chunk, worldPos, ....
then it would be a matter of : where is the player in the world; what chunks around the player should be showing; move chunks accordingly; update moved chunks with new position information. Then working out an algorithm to return what chunk the player is standing on, and what are the 8 chunks surrounding that.
Yeah I have to apologize for this question. I really didn't see the obvious and got it working now.
But to come to the point of not moving the chunks, but ins$$anonymous$$d add an offset to the vertices. Does that really make any difference?
Well, since the vertex coordinates are updated anyway, wether they change or not, I see no reason to change the chunk object's transform.position at all.
Okay it seems logic, but it would require a major rewrite of my code, and I don't know if it's worth the pain.
Your answer
![](https://koobas.hobune.stream/wayback/20220613163010im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Import a 513x513 Texture2D (heightmap) 0 Answers
How Do I Fix My Grass? 2 Answers
Make a simple tree 1 Answer
Terrain Chunk loading 1 Answer
Correcting normals along chunk edges 1 Answer