Fix lobby/HUD UI pinned at (0,0); shrink player hitbox below visual size
ci / verify (push) Successful in 45s
ci / verify (push) Successful in 45s
The lobby connect menu and three pieces of the HUD (hit-flash overlay, boss bar centering, death-message centering, hint label) were all silently broken by the same Godot gotcha: set_anchors_preset(preset) with the default keep_offsets=false does NOT zero the offsets to the preset's margins -- it recomputes them to preserve the control's *current* rect, which for a freshly constructed Control is (0,0). Anchors end up correct; the actual rect stays pinned to the top-left corner regardless. Fixed by switching to set_anchors_and_offsets_preset() everywhere a Control is built in code, and by using offset_left/offset_top (anchor-relative) instead of .position (absolute) for the HUD hint label. Documented as gotcha #5 in CLAUDE.md. Also split PLAYER_RADIUS into two constants: PLAYER_RADIUS (6.0, the authoritative hitbox used by SimWorld) and PLAYER_VISUAL_RADIUS (13.0, view-only, used by world_view.gd). The client renders every ship a little late relative to the server -- interpolation delay, reconciliation smoothing -- so a hitbox that matched the sprite would let bullets connect against a ship the player watched dodge clear of them. A smaller hitbox means the occasional bullet visibly clips the sprite without a hit, which reads as more forgiving of latency than the reverse. Verified headlessly: a throwaway scene instantiating MainMenu/HUD under a real 1280x720 viewport, asserting the panel is centered and _canvas.size / hint position resolve correctly, before and after each fix. check.sh, test.sh (78/78) and smoke.sh all pass.
This commit is contained in:
@@ -103,8 +103,13 @@ func _draw_local_player() -> void:
|
||||
_draw_escape_ring(client.predicted_pos, client.my_escape, COL_LOCAL)
|
||||
|
||||
|
||||
## Drawn at PLAYER_VISUAL_RADIUS, larger than the PLAYER_RADIUS hitbox actually
|
||||
## used for hits -- see the comment on those constants in sim_config.gd. The
|
||||
## mismatch is deliberate, not a placeholder: a bullet can visibly clip the
|
||||
## sprite without registering a hit, which reads as more forgiving of latency
|
||||
## than the reverse.
|
||||
func _draw_ship(pos: Vector2, aim: float, col: Color, alive: bool) -> void:
|
||||
var r := SimConfig.PLAYER_RADIUS
|
||||
var r := SimConfig.PLAYER_VISUAL_RADIUS
|
||||
draw_circle(pos, r, Color(col, 0.4 if alive else 0.2))
|
||||
draw_arc(pos, r, 0.0, TAU, 20, col, 2.0)
|
||||
if alive:
|
||||
@@ -115,5 +120,5 @@ func _draw_ship(pos: Vector2, aim: float, col: Color, alive: bool) -> void:
|
||||
## The escape channel is drawn on the player, not just in the HUD, so other
|
||||
## players can see someone is about to leave and react.
|
||||
func _draw_escape_ring(pos: Vector2, progress: float, col: Color) -> void:
|
||||
draw_arc(pos, SimConfig.PLAYER_RADIUS + 8.0, -PI * 0.5,
|
||||
draw_arc(pos, SimConfig.PLAYER_VISUAL_RADIUS + 8.0, -PI * 0.5,
|
||||
-PI * 0.5 + TAU * progress, 32, Color(col, 0.9), 3.0)
|
||||
|
||||
Reference in New Issue
Block a user