Godot Version
4.5.1
Question
tried to generate a 16x16 later also 32x32 an mayby 64x64 tile large map procedurally from a isometric sprite using a 2D sprite. For that, I used the following code. But somehow the hills look very weird. I’ve already played around with some variables in the codes. But it didn’t get any better. Later, I still want to look for small lakes, and I’m slowly getting very desperate. Could someone give me a tip?
extends Node2D
@export var tile_size: Vector2 = Vector2(32, 32)
@export var world_width: int = 16
@export var world_height: int = 16
@export var max_height_blocks: int = 3
@export var noise_resource: Resource
var grass_texture: Texture2D
func _ready():
grass_texture = preload("res://assets/tiles/grass_block.png")
generate_world(world_width, world_height)
func generate_world(width: int, height: int):
var heights = []
for x in width:
heights.append([])
for y in height:
heights[x].append(0)
for x in width:
for y in height:
var left_height = 0
var top_height = 0
if x > 0:
left_height = heights[x - 1][y]
if y < 0:
top_height = heights[x][y - 1]
var new_height
if left_height == top_height and left_height < 3:
if randi() % 100 < 10:
new_height = left_height + 1
else:
new_height = left_height
else:
if left_height != top_height and left_height < 3 and top_height < 3:
new_height = max(left_height, top_height)
else:
if left_height == 3 or top_height == 3:
new_height = 3
new_height == clamp(new_height, 0, 3)
heights[x][y] = new_height
var screen_x = (x - y) * 16
var screen_y = (x + y) * 8 - new_height * 16
create_tile(Vector2(screen_x, screen_y))
func create_tile(pos: Vector2):
var tile = Sprite2D.new()
tile.texture = grass_texture
tile.position = pos
add_child(tile)

