Tinkering with procedural generators with different settings

Godot Version

4.3

Question

I’ve been tinkering with procedural generation and I am trying to make a game where you can generate different terrain with the click of a button. I discovered that you can have a terrain with lakes or a terrain with rivers, depending on the fractural type and lacunarity used. I am trying to make the game where it generates a basic terrain, but has the OPTION to generate terrain with a river in it. So I made the noise generator where it has the FBM fractural type in the Insector settings:


Where the code I wrote would change the fractural type to “ridged” when one wants to generate a river. I wrote the following code to see if the scene would “switch” between the two noise generator settings, but it doesn’t do so. I just keeps generating new terrain with the FBM factural type, despite my code calling for ridged. Code below (what do I need to change so the scene would switch between the two noise generators?):

extends Node2D

@export var noise_height_text : NoiseTexture2D
var noise = FastNoiseLite.new()

var width : int = 50
var height : int = 100

@onready var tile_map = $TileMap

#Stores the terrain tiles into variables
var source_id = 0
var water_atlas = Vector2i(0, 11)
var land_atlas = Vector2i(1, 11)
var sand_atlas = Vector2i(3, 11)

#Called when the node enters the scene tree for the first time.
func _ready():
	#Sets the seed number to a random 32 digit integer, allowing for new terrain to be generated
	noise.seed = randi()
	generate_world()

func _ready_river():
	#Sets the seed number to a random 32 digit integer, allowing for new terrain to be generated
	noise.noise_type = FastNoiseLite.TYPE_SIMPLEX_SMOOTH
	noise.seed = randi()
	noise.frequency = 0.01
	noise.fractal_type = FastNoiseLite.FRACTAL_RIDGED
	noise.fractal_octaves = 5
	noise.domain_warp_fractal_lacunarity = 0
	noise.fractal_gain = 0.5
	generate_world()

func generate_world():
	for x in range(width):
		for y in range(height):
			#Gets the noise value to determine that tile to place
			var noise_val : float = noise.get_noise_2d(x, y)
			if noise_val >= 0.0:
				#Determines the noise values to place the land tile
				tile_map.set_cell(0, Vector2(x,y), source_id, land_atlas)
			elif noise_val > -0.1 and noise_val < 0.0:
				#Determines the noise values to place the sand tile
				tile_map.set_cell(0, Vector2(x,y), source_id, sand_atlas)
			elif noise_val <= -0.1:
				#Determines the noise values to place the water tile
				tile_map.set_cell(0, Vector2(x,y), source_id, water_atlas)

func _on_generate_world_pressed():
		_ready_river()


func _on_check_button_toggled(toggled_on: bool) -> void:
	pass # Replace with function body.

Could you explain what you expect to happen vs what really happens? I don’t see the connection between fractal type “Rigid” and not generating negative numbers, it certainly will create negative numbers.

what happens is it generates the terrain with the settings shown in the screenshot. However, I was expecting to see terrain generated with a river (hence the _ready_river() function) when clicking on the “_on_generate_world_pressed()” button.

Can you show a before and after? What does a river look like to you? What is missing from your current generated world?

Well I can’t show an after, since it doesn’t generate terrain with a river.

This screenshot is an exmaple of the terrain it generates, even after pressing the “Generate World” button:

Let’s remove this line and try generating one with and without “river?”

func _ready_river():
	noise.noise_type = FastNoiseLite.TYPE_SIMPLEX_SMOOTH
	## noise.seed = randi() ## Do not change seed to test RIDGED ##
	noise.frequency = 0.01
	noise.fractal_type = FastNoiseLite.FRACTAL_RIDGED
	noise.fractal_octaves = 5
	noise.domain_warp_fractal_lacunarity = 0
	noise.fractal_gain = 0.5
	generate_world()

Ok, so I removed that function and changed to the following settings:

As it turns out, the terrain doesn’t seemed to have changed. What the heck? Do I need to change my noise values in the generate_world() function so it looks more like a river? The black and white noise map does generate the look I was going for.

strange for those properties to not change the resulting noise values. Maybe worth print testing? See if any of these prints change value, for me Pre-set is different from post-set.

func _ready_river():
	print("Pre-set: ", noise.get_noise_2d(25, 50))

	noise.noise_type = FastNoiseLite.TYPE_SIMPLEX_SMOOTH
	noise.frequency = 0.01
	noise.fractal_type = FastNoiseLite.FRACTAL_RIDGED
	noise.fractal_octaves = 5
	noise.domain_warp_fractal_lacunarity = 0
	noise.fractal_gain = 0.5

	print("Post-set: ", noise.get_noise_2d(25, 50))

	await get_tree().process_frame

	print("Post-frame-set: ", noise.get_noise_2d(25, 50))

Yeah, that worked. I got the following results:

And the tiles successfully do change if the seed changes by adding back noise.seed = randi()? I feel like the problem must be elsewhere, not noise based but updating the map is failing somehow.

The noise.seed = randi() does cause a change in tiles, yes. It seems the problem is elsewhere, I’ll keep looking.