0 votes

Hello, all,

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):

extends Spatial

onready var player = get_parent().get_node('Party/Player')

var playerChunk

func _process(delta):

func get_playerChunk(position):
    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()

func 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.

in Engine by (14 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.