it has to be something with the tileset. You can test the following code and see for yourself that it works:
@tool
extends Node2D
@export_tool_button("Test") var generate: Callable = generate_world
@export var noise: Noise
var width: int = 100
var height: int = 100
var island_radius = 50
func _ready():
generate_world()
const WATER_THRESHOLD = 0.3
const SAND_THRESHOLD = 0.45
const TILE_SIZE: int = 32
var water_cells
var sand_cells
var grass_cells
func generate_world():
water_cells = []
sand_cells = []
grass_cells = []
for x in range(-width/2, width/2):
for y in range(-height/2, height/2):
var noise_val = noise.get_noise_2d(x, y)
if noise_val < WATER_THRESHOLD:
water_cells.append(Vector2i(x, y))
elif noise_val < SAND_THRESHOLD:
sand_cells.append(Vector2i(x, y))
else:
grass_cells.append(Vector2i(x, y))
queue_redraw()
func draw(coords: Vector2i, color: Color) -> void:
draw_rect(Rect2(coords * TILE_SIZE, Vector2.ONE * TILE_SIZE), color)
func _draw() -> void:
for cell: Vector2i in water_cells:
draw(cell, Color.BLUE)
for cell: Vector2i in sand_cells:
draw(cell, Color.YELLOW)
for cell: Vector2i in grass_cells:
draw(cell, Color.GREEN)
This draws tiles instead of using the tilemap
You can try to click on these and draw by hand to check if the tileset is working correctly
1 Like
it looks like this
also this is how my tileset is working
Okay try this code, just this time you dont draw water_tiles. Choose simplex_smooth with a frequency = 0.0158:
@tool
extends Node2D
@export_tool_button("Test") var generate: Callable = generate_world
@export var noise: Noise
@onready var tilemap = $Ground
var width: int = 100
var height: int = 100
func _ready():
generate_world()
const WATER_THRESHOLD = 0.25
const SAND_THRESHOLD = 0.35
const TILE_SIZE: int = 32
var water_cells
var sand_cells
var grass_cells
func generate_world():
noise.seed = randi()
water_cells = []
sand_cells = []
grass_cells = []
for x in range(-width/2, width/2):
for y in range(-height/2, height/2):
var noise_val = noise.get_noise_2d(x, y)
if noise_val < WATER_THRESHOLD:
water_cells.append(Vector2i(x, y))
elif noise_val < SAND_THRESHOLD:
sand_cells.append(Vector2i(x, y))
else:
grass_cells.append(Vector2i(x, y))
#tilemap.set_cells_terrain_connect(water_cells, 0, 3) # Water Cells
tilemap.set_cells_terrain_connect(sand_cells, 0, 2) # Sand Cells
tilemap.set_cells_terrain_connect(grass_cells, 0, 1) # Grass Cells
it also randomizes the seed everytime you click on the “Test” button now
1 Like
actually this time was the best cuz its almost ideal with terrains
This is still wrong though…
@tool
extends Node2D
@export_tool_button("Test") var generate: Callable = generate_world
@export var noise: Noise
@onready var tilemap = $Ground
var width: int = 100
var height: int = 100
func _ready():
generate_world()
const WATER_THRESHOLD = 0.25
const SAND_THRESHOLD = 0.35
const TILE_SIZE: int = 32
var water_cells
var sand_cells
var grass_cells
func generate_world():
noise.seed = randi()
water_cells = []
sand_cells = []
grass_cells = []
for x in range(-width/2, width/2):
for y in range(-height/2, height/2):
var noise_val = noise.get_noise_2d(x, y)
if noise_val < WATER_THRESHOLD:
water_cells.append(Vector2i(x, y))
elif noise_val < SAND_THRESHOLD:
sand_cells.append(Vector2i(x, y))
else:
grass_cells.append(Vector2i(x, y))
tilemap.clear()
tilemap.set_cells_terrain_connect(sand_cells, 0, 2, false) # Sand Cells
tilemap.set_cells_terrain_connect(grass_cells, 0, 1, false) # Grass Cells
Can you maybe try this?
okay but i dont understand why we got this problem with terrains if manually it works fine but when is is being gnenereated it looks like this
Why is it drawing water-tiles for you? It shouldnt draw water-tiles anymore since we commented that out…
Could it be that the order is wrong of your terrains?
Can you go to your tileset on the inspector and show the list of your terrains?
actually i was curious too why it was drawing water if you said it should not but i said maybe i dont undertanding why )
Oh my god… i messed up the indices
try this:
@tool
extends Node2D
@export_tool_button("Test") var generate: Callable = generate_world
@export var noise: Noise
@onready var tilemap = $Ground
var width: int = 100
var height: int = 100
func _ready():
generate_world()
const WATER_THRESHOLD = 0.25
const SAND_THRESHOLD = 0.35
const TILE_SIZE: int = 32
var water_cells
var sand_cells
var grass_cells
func generate_world():
noise.seed = randi()
water_cells = []
sand_cells = []
grass_cells = []
for x in range(-width/2, width/2):
for y in range(-height/2, height/2):
var noise_val = noise.get_noise_2d(x, y)
if noise_val < WATER_THRESHOLD:
water_cells.append(Vector2i(x, y))
elif noise_val < SAND_THRESHOLD:
sand_cells.append(Vector2i(x, y))
else:
grass_cells.append(Vector2i(x, y))
tilemap.clear()
tilemap.set_cells_terrain_connect(sand_cells, 0, 1) # Sand Cells
tilemap.set_cells_terrain_connect(grass_cells, 0, 0) # Grass Cells
no problem, now there is no water
Yeah now we can try to add the water:
@tool
extends Node2D
@export_tool_button("Test") var generate: Callable = generate_world
@export var noise: Noise
@onready var tilemap = $Ground
var width: int = 100
var height: int = 100
func _ready():
generate_world()
const GRASS_THRESHOLD = 0.0
const SAND_THRESHOLD = 0.2
const TILE_SIZE: int = 32
var water_cells
var sand_cells
var grass_cells
func generate_world():
noise.seed = randi()
water_cells = []
sand_cells = []
grass_cells = []
for x in range(-width/2, width/2):
for y in range(-height/2, height/2):
var noise_val = noise.get_noise_2d(x, y)
if noise_val < GRASS_THRESHOLD:
grass_cells.append(Vector2i(x, y))
if noise_val < SAND_THRESHOLD:
sand_cells.append(Vector2i(x, y))
water_cells.append(Vector2i(x, y))
tilemap.clear()
tilemap.set_cells_terrain_connect(water_cells, 0, 2) # Water Cells
tilemap.set_cells_terrain_connect(sand_cells, 0, 1) # Sand Cells
tilemap.set_cells_terrain_connect(grass_cells, 0, 0) # Grass Cells
i changed the threshold logic a bit
1 Like
I dont understand why there are holes and the water is not drawn?
actually the id numbers was wrong as i understand and i changed them to this
tilemap.set_cells_terrain_connect(water_cells, 0, 3) # Water Cells
tilemap.set_cells_terrain_connect(sand_cells, 0, 2) # Sand Cells
tilemap.set_cells_terrain_connect(grass_cells, 0, 1) # Grass Cells
my grass tileset stats from 1
but yeah there are holes and no water, maybe there is the problem ?
if noise_val < GRASS_THRESHOLD:
grass_cells.append(Vector2i(x, y))
if noise_val < SAND_THRESHOLD:
sand_cells.append(Vector2i(x, y))
water_cells.append(Vector2i(x, y))
No these tile ids dont matter. They are just the ids of the atlas, but you need the id of the terrains.
So it has to stay like this:
tilemap.set_cells_terrain_connect(water_cells, 0, 2) # Water Cells
tilemap.set_cells_terrain_connect(sand_cells, 0, 1) # Sand Cells
tilemap.set_cells_terrain_connect(grass_cells, 0, 0) # Grass Cells
1 Like
mmmm idk why at first i tried with 0 1 2 and there was with holes and no water after that i tried with my id numbers and it was same as you said it does not matter and after you said that i changed it back and run the sceen and THERE is this perfect world but when i was running same code with test button it was not like this, after running the scene and pressing the test button it again created the wolrd like this, also to get more island shaped world i need to change the noise type ?
1 Like
You CAN change the noise-type, but as i said you need to find fitting thresholds to your noise.
For example SIMPLEX_SMOOTH returns values in the range of -0.5 - 0.5 and the thresholds are in between this range.
For different noise the range might differ.
What you can try to do is first play around with the thresholds. Then try to play around with the frequency of the noise.
If this still doesnt fit your needs you can try different noise-types
1 Like
okay so as i understand i don’t need to code anything to have island generated world also i did want to ask what you think is this thing
created because my tileset is wrong? or just smth else ?
jhon
July 16, 2025, 8:11am
60
O.M.G this is the longest help thingy ever !!!
The procedural terrain looks cool ,
Also the light house
1 Like