Files
gamedev-the-steward/world/jajce/jajce_world.gd
T
admin d2eca15ecd fix: camera tracks player elevation; snap all world objects to terrain
Camera: desired_focus_position.y now directly tracks the player's global Y. The existing smooth lerp on focus_position handles interpolation, so the camera follows the player up hills and down slopes without losing vertical sight. Previously only horizontally-deadzoned XZ was tracked.

jajce_world.gd: expanded terrain-snapping coverage to include all nodes under WorldObjects (ResourceNodes, StorageSites, ActivitySites) and the FortressBlockout's children. Added a type guard so non-Node3D children are safely skipped. This prevents houses, activity props, storage crates, and resource nodes from floating above or sinking below the sculpted terrain surface.
2026-07-07 17:07:57 +02:00

36 lines
1.1 KiB
GDScript

extends Node3D
@onready var terrain: Terrain3D = $TerrainRoot/Terrain3D
func _ready() -> void:
call_deferred("_initialize_world_presentation")
func _initialize_world_presentation() -> void:
var active_camera := get_viewport().get_camera_3d()
if active_camera != null:
terrain.set_camera(active_camera)
var groups_to_snap: Array[Node] = []
groups_to_snap.append_array($FoliageRoot.get_children())
if has_node("FortressBlockout"):
groups_to_snap.append($FortressBlockout)
groups_to_snap.append_array($FortressBlockout.get_children())
for child in $VillageRoot.get_children():
groups_to_snap.append(child)
if has_node("WorldObjects"):
var wo := $WorldObjects
for group_name in ["ResourceNodes", "StorageSites", "ActivitySites"]:
if wo.has_node(group_name):
groups_to_snap.append_array(wo.get_node(group_name).get_children())
for item in groups_to_snap:
if not item is Node3D:
continue
var node3d := item as Node3D
var pos := node3d.global_position
var h: float = terrain.data.get_height(pos)
if not is_nan(h):
node3d.global_position.y = h