Minecraft Trees?

So I’ve been following a tutorial for voxel world generation by Real Robots, and wanted to add trees. But as someone who is relatively new to Godot I can’t quite figure it out. This is the code where I assume it is supposed to be handled:

func GetBlock(pos : Vector3i):
var n = (noise.get_noise_2d(pos.x, pos.z) + 1) * chunk_size
if n > pos.y: # if the noise is greater than a certian y position.
if cave_noise.get_noise_3d(pos.x, pos.y, pos.z) > -0.5:
return Block.BlockType.Grass
else:
return Block.BlockType.Air
else:
return Block.BlockType.Air

Trees can be placed by a more complex algorithm than only noise. Often placing objects can be done at a local maxima, meaning a high value relative to the surrounding noise samples.

Here’s a great talk on using noise with a timestamp on generating object placements. I’d recommend the whole thing though.

1 Like