Fix fall-through (spawn on terrain after collision built) and B&W (assign sky env)

This commit is contained in:
dev
2026-11-03 22:28:19 +00:00
parent bfe90a1b11
commit 5c58fad07b
4 changed files with 84 additions and 34 deletions

31
scripts/world/world.gd Normal file
View File

@@ -0,0 +1,31 @@
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)