I am working on a project that has a 3D world. I’ve been thinking of using a similar system to Minecraft regarding how it treats blocks and chunks. The player will be able to interact with the world by placing/destroying blocks.
I have different scenes for each block type that come in various shapes (I’m not using a gridmap). The chunks will be 10x10 as the default 3D grid is. So far, I have made a code that detects which chunk the player is currently on and when he changes chunks (sorry if my code is noobish):
onready var player = get_parent().get_node('Party/Player')
var oldValue = playerChunk
var playerPosition = Vector2(floor(position.x), floor(position.z))
playerChunk = Vector2(floor(playerPosition.x/10), floor(playerPosition.y/10))
if oldValue != playerChunk: load_chunks()
pass # This code will load surrounding chunks when the player moves to a new chunk.
The plan is for every chunk to be a different Spatial node, that loads/unloads whenever the player is close/far.
The next step I plan on being saving and loading the chunks, but I haven’t decided how to do it.
• I’m worried that a single file to store information on all chunks, would get too big on large worlds. Also, wouldn’t it be slow to go though all the file, each time the player changes a chunk (chunks aren’t big after all)?
• I have though of having a folder that has a different file for every chunk, with information on block locations. That would probably be a lot of files in a large world.
• Any other ideas on how to proceed with this plan?
This is the first time I am experimenting with something like this and I am a bit lost ^^
Thanks for reading.