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.