Hello, I created the code nessecary to generate a random blocky 250x250 terrain using a gridmap and FastNoiseLite. Now, I want to make it generate procedurely. With that expression I mean, having a 250x250 grid terrain around the player at all time.
So I modified my code to look like this:

func _physisc_process(delta : float) -> void:
  for x in range (-player.global_position.x, player.global_position.x):
    for y in range(20):
      for z in range(-player.global_position.z, player.global_position.z):
        if not Vector3i(x,y,z) in tiles:
          if y < noise.get_2d_noise(x,z) * 20 + 10:
            set_cell(x,y,z)
            tiles.append(Vector3i(x,y,z))

Note: As I'm typing it on my phone, I may have made a syntax mistake or a misspelled a function name, but in the original code there were no errors

The code is running with no errors or even warnings, but the terrain is not being generated and after 5 seconds it says the program isn't responding. Please help

  • Bilal
    Maybe you can seperate the world into each "chunk", a chunk is a N*N*N part generate by noise.

    You generate 9 chunks on game start with the player as the center, and when you go to the border chunk, move and regenerate the 3 chunk behind to your front, to ensure you always in the center of the 9 chunks.

    So then you don't need to generate chunk at each frame, you just move and regenerate 3 chunk when you reach a new chunk.

    However I haven't deployed that, so the details may be different. 😃

    What's more, you may be interested in some open source godot voxel game, such as:

    https://github.com/Zylann/godot_voxel

    You can find their build for godot 4 with voxel addon in their github Actions

I don't know why you put your generation code into _physisc_process(delta). It certainly slow down your frame rate.

I use this for test, godot version v4.0.rc4.official [e0de3573f], don't find problem.

extends GridMap

@export var noise : FastNoiseLite

# Called when the node enters the scene tree for the first time.
func _ready():
	for x in range (20):
		for y in range(20):
			for z in range(20):
				if y < noise.get_noise_2d(x,z) * 20 + 10:
						set_cell_item(Vector3i(x,y,z),0,0)

    CheapMiao I don't know why you put your generation code into _physisc_process(delta). It certainly slow down your frame rate.

    Perhaps more importantly _physisc_process(delta) is a misspelling. It would have to be _physics_process(delta).

    CheapMiao I also use this code for my terrain generation, but now I want it to PROCEDURLY generate, meaning the map is a 250 by 250 grid around the player.

      Bilal
      Maybe you can seperate the world into each "chunk", a chunk is a N*N*N part generate by noise.

      You generate 9 chunks on game start with the player as the center, and when you go to the border chunk, move and regenerate the 3 chunk behind to your front, to ensure you always in the center of the 9 chunks.

      So then you don't need to generate chunk at each frame, you just move and regenerate 3 chunk when you reach a new chunk.

      However I haven't deployed that, so the details may be different. 😃

      What's more, you may be interested in some open source godot voxel game, such as:

      https://github.com/Zylann/godot_voxel

      You can find their build for godot 4 with voxel addon in their github Actions