Fix: unit Y height drifts upward across moves

Root cause: _animate_unit_move computed unit_above by subtracting
from_tile_top from body.position.y. If a state update arrived before
the board rebuilt (body still mid-tween), that subtraction produced a
value > 0.28 which then compounded each successive move.

Secondary: from_tile_top was typed :int, silently truncating the float
sum of tile_base + tile_h.

Fix: store above_tile as body metadata in _add_unit_mesh (0.28/0.4/0.5
per card type). _animate_unit_move reads the stored constant directly —
it is immune to board rebuild timing.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-16 18:24:23 -04:00
co-authored by Claude Happy
parent eb7a8e57b1
commit a4b390460d
@@ -731,7 +731,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
var mat := StandardMaterial3D.new() var mat := StandardMaterial3D.new()
mat.roughness = 0.65 mat.roughness = 0.65
var y_offset : float var above_tile : float # how far above the tile top the body centre sits
match card_type: match card_type:
"ArchSpirit": "ArchSpirit":
var cyl := CylinderMesh.new() var cyl := CylinderMesh.new()
@@ -743,7 +743,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
var cs := CylinderShape3D.new() var cs := CylinderShape3D.new()
cs.radius = 0.22; cs.height = 0.8 cs.radius = 0.22; cs.height = 0.8
shape.shape = cs shape.shape = cs
y_offset = tile_h + 0.4 above_tile = 0.4
"Ruin": "Ruin":
var bm := BoxMesh.new() var bm := BoxMesh.new()
bm.size = Vector3(0.25, 1.0, 0.25) bm.size = Vector3(0.25, 1.0, 0.25)
@@ -752,7 +752,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
var bs := BoxShape3D.new() var bs := BoxShape3D.new()
bs.size = Vector3(0.25, 1.0, 0.25) bs.size = Vector3(0.25, 1.0, 0.25)
shape.shape = bs shape.shape = bs
y_offset = tile_h + 0.5 above_tile = 0.5
_: _:
var sm := SphereMesh.new() var sm := SphereMesh.new()
sm.radius = 0.28; sm.height = 0.28 sm.radius = 0.28; sm.height = 0.28
@@ -761,7 +761,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
var ss := SphereShape3D.new() var ss := SphereShape3D.new()
ss.radius = 0.28 ss.radius = 0.28
shape.shape = ss shape.shape = ss
y_offset = tile_h + 0.28 above_tile = 0.28
mi.material_override = mat mi.material_override = mat
if exhausted: if exhausted:
@@ -769,7 +769,8 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
body.add_child(shape) body.add_child(shape)
body.add_child(mi) body.add_child(mi)
body.position = wp + Vector3(0, tile_base + y_offset, 0) body.set_meta("above_tile", above_tile)
body.position = wp + Vector3(0, tile_base + tile_h + above_tile, 0)
_units_root.add_child(body) _units_root.add_child(body)
_unit_meshes[iid] = mi _unit_meshes[iid] = mi
_unit_bodies[iid] = body _unit_bodies[iid] = body
@@ -1280,11 +1281,9 @@ func _animate_unit_move(iid: String, from_coord: Vector2i, to_coord: Vector2i,
step_angles.append(atan2(dir.x, -dir.z) - base_angle) step_angles.append(atan2(dir.x, -dir.z) - base_angle)
prev_coord = step prev_coord = step
# Tween the body through each grid step, rotating the model to face each direction. # Tween the body through each grid step, rotating the model to face each direction.
# Compute how far above the tile top this unit sits so we can preserve that # Use the stored "above_tile" constant so rapid state updates cannot skew the
# offset as it moves across tiles of different stagger heights. # height by back-calculating from a mid-tween body position.
var from_key := "%d,%d" % [from_coord.x, from_coord.y] var unit_above : float = body.get_meta("above_tile", 0.28)
var from_tile_top : int = _tile_y_bases.get(from_key, 0.0) + _tile_heights.get(from_key, 1.0)
var unit_above : float = body.position.y - from_tile_top
# Pre-compute per-step Y positions. # Pre-compute per-step Y positions.
var step_ys : Array[float] = [] var step_ys : Array[float] = []
for step : Vector2i in path: for step : Vector2i in path: