extends Node3D ## World controller — M0. ## ## Owns spawn ordering so the player never falls through ungenerated ground: ## waits for the terrain to finish building, then drops the player onto the ## surface height and lets gravity settle them. Also tells the props where the ## ground is so they sit on it instead of floating. @onready var terrain: Node3D = $Terrain @onready var props: Node3D = $Props @onready var player: CharacterBody3D = $Player func _ready() -> void: # Freeze the player until the ground exists. player.set_physics_process(false) if terrain.built: _on_terrain_ready() else: terrain.ready_built.connect(_on_terrain_ready) func _on_terrain_ready() -> void: # Let props place themselves on the surface. if props.has_method("place_on"): props.place_on(terrain) # Spawn the player on the ground at (0,0), a little above so they settle down # onto the collision rather than starting embedded in it. var h: float = terrain.sample_height(0.0, 0.0) player.global_position = Vector3(0.0, h + 2.0, 0.0) player.velocity = Vector3.ZERO player.set_physics_process(true)