fix(hud): have game mode hand HUD its target ship instead of group lookup

HUDController found its ship via get_first_node_in_group("ship"), a group
that has 2+ members once a match has an AI opponent — it only worked
because the player ship happened to spawn first. spawn_camera_rig now
wires the HUD's ship the same way it already wires the camera rig's
target.
This commit is contained in:
Josh Creek
2026-08-04 19:54:55 +01:00
parent 5193776d86
commit 884b7799a0
4 changed files with 19 additions and 10 deletions
+10 -7
View File
@@ -1,7 +1,9 @@
# HUD Controller - discovers the ship/camera/game mode via groups and routes
# their signals to the display widgets. All flight data is rendered by
# aircraft-style instruments (attitude indicator, heading tape, bar gauges) —
# this node is only the wiring hub; the instruments are dumb displays.
# HUD Controller - receives its target ship from the game mode (see
# GameMode.spawn_camera_rig), discovers the camera rig/game mode via groups,
# and routes their signals to the display widgets. All flight data is
# rendered by aircraft-style instruments (attitude indicator, heading tape,
# bar gauges) — this node is only the wiring hub; the instruments are dumb
# displays.
extends CanvasLayer
class_name HUDController
@@ -33,10 +35,11 @@ func _ready():
_initialize_hud()
func _initialize_hud():
# Find the ship
ship = get_tree().get_first_node_in_group("ship")
# `ship` is assigned by the game mode (GameMode.spawn_camera_rig) before
# this runs — not discovered via group, since the "ship" group can have
# 2+ members and there's no reliable way to tell which one is "ours".
if not ship:
push_error("HUDController: No ship found in 'ship' group")
push_error("HUDController: No ship assigned")
return
print("HUDController: Found ship: ", ship.name)
+7 -1
View File
@@ -13,6 +13,7 @@ extends Node3D
const CAMERA_RIG_SCENE = preload("res://scenes/ship_camera_rig.tscn")
var arena: Arena
var hud: HUDController
var ball: RigidBody3D
var ships: Array[Ship] = []
var _ship_spawn_transforms := {}
@@ -30,7 +31,8 @@ func _ready():
for child in get_children():
if child is Arena:
arena = child
break
elif child is HUDController:
hud = child
if not arena:
var path := _get_arena_scene_path()
if not path.is_empty():
@@ -99,6 +101,10 @@ func spawn_camera_rig(target: Ship) -> ShipCameraRig:
var rig: ShipCameraRig = CAMERA_RIG_SCENE.instantiate()
add_child(rig)
rig.target = target
# Also wires the scene's static HUD (if any) to the same ship, rather
# than letting it guess via the "ship" group.
if hud:
hud.ship = target
return rig