Generating Procedural Islands in Godot Engine

Godot Engine Logo

Hello! In this article i am going to cover how you can generate procedural islands in Godot Engine. Noises are the most common way to generate maps and worlds. Minecraft is one of the games using perlin noise to generate procedural worlds.

A noice can not guarantee to generate an islan, is only generates a noise between -1 and 1.

FastNoiseLite is the noise generator in Godot Engine. You can find more information from this link.

First of all, you need to generate a noise with FastNoiseLite class:

var gradient_image: Image = gradient.get_image()
	
	var noise: FastNoiseLite = FastNoiseLite.new()
	noise.noise_type = FastNoiseLite.TYPE_SIMPLEX
	randomize()
	noise.seed = randi_range(0,5000)
	while x < map_width:
		while y < map_height:
			var noise_value = noise.get_noise_2d(x * 0.3, y * 0.3) * 2
			image.set_pixel(x, y, Color(noise_value, noise_value, noise_value, 1))
			y += 1
		y = 0
		x += 1

I’ve done a trick in that code calling while noise.get_noise_2d() method, i multiply pixels positions with 0.3, that can be considered as zooming in. After “zooming into” procedurally generated map, i multiply returning value with 2 to make gap between -0.9 and 0.9 bigger.

After generating a few maps, you will see the method above can not guarantee generated world to be an island. You need a gradient like this:

You need to substract gradients value from generated noise.

noise_value -= gradient_image.get_pixel(x, y).r

As a result of this you can generate and island like those:

Godot makes many things simpler for Game Developers, this is definitely one of those. With a little set up and little configuration you can generate an island like those.

Leave a Reply

Your email address will not be published. Required fields are marked *