Godot Version
Godot v4.3
Question
I’m currently tinkering with a procedurally generated isometric terrain. I want the button to generate new terrain when pressed. However, nothing is happening. This is the code what I have so far:
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
@onready var Generate_World_Button = $Control/VBoxContainer/Generate_World
#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():
noise_height_text.noise
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():
generate_world()
And this is how I have the nodes organized: