Why isnt this procedural generation code working?

Godot Version

newest version


It just returns blank, maybe the set_cell isnt being used properly?

extends TileMap

@export var noise = FastNoiseLite.new()
@export var tileset : TileSet
@export var width : int = 10
@export var height : int = 10
@export var threshold1 : float = 0.3
@export var threshold2 : float = 0.6
@export var grassTile : int = 0
@export var grassWithFlowersTile : int = 1
@export var otherTile : int = 2

func _ready():

func generate_map():
	noise.seed = randi()
	for x in range(width):
		for y in range(height):
			var noise_value = noise.get_noise_2d(x,y)
			var tile_index = map_noise_to_tile_index(noise_value)
			var index = y * width + x
			var coords = Vector2i(x, y)
			set_cell(0, coords, -1, Vector2i(-1, -1), tile_index)
func map_noise_to_tile_index(value):
	if value < threshold1:
		return grassTile
	elif value < threshold2:
		return grassWithFlowersTile
		return otherTile

It appears to be a problem with set cell your sourceid should be 0 most likely not -1
also your atlas coordinates are -1 and -1 indicating empty

I must have mistyped or something i cant believe I made that mistake lol, im trying to remake a game I made in python and im kinda new to godot so thanks for helping out

1 Like