22 lines
592 B
GDScript

extends Node3D
@export var scene: PackedScene
@export var noise: Noise
@export var size_x: float
@export var size_z: float
@export var step: float = 1
@export var density: float
@export var position_randomness := 1.0
func _ready():
for x in range(-size_x, size_x, step):
for z in range(-size_z, size_z, step):
if noise.get_noise_2d(x, z) < 1 - density * 2:
continue
var t := scene.instantiate() as Node3D
t.rotation.y = randf() * TAU
t.position.x = x + (randf() - 0.5) * position_randomness
t.position.z = z + (randf() - 0.5) * position_randomness
add_child(t)