fix: correct default modelFacingDirection to south for Blender GLB units

Units were facing 180° away from the nearest enemy because
modelFacingDirection defaulted to "north" (base=0) when the asset
field was absent. Blender-exported GLBs natively face +Z (south,
base=π), so the rotation formula was inverted for all models without
an explicit facing override.

Also improves _idle_rotation diagnostics: push_warning on fallback
with body/ownership counts, and tightens the XZ direction guard to
check (x != 0 or z != 0) instead of 3D length_squared which could
pass spuriously when only the Y component was non-zero.

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-04-14 09:17:52 -04:00
co-authored by Claude Happy
parent fa180a1673
commit e204cdf74e
@@ -1604,7 +1604,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
return
# Asset-level config (model-file specific).
var facing_dir : String = str(model_asset.get("modelFacingDirection", "north"))
var facing_dir : String = str(model_asset.get("modelFacingDirection", "south"))
# Card-level config (visual identity of this card, not the shared mesh file).
var model_scale : float = float(def.get("modelScale", 1.0))
var tint_str : String = str(def.get("modelTintColor", ""))
@@ -1840,19 +1840,29 @@ func _idle_rotation(iid: String) -> float:
var my_pos : Vector3 = my_body.global_position
var best_sq : float = INF
var best_dir : Vector3 = Vector3.ZERO
var enemy_ids : Array = _enemy_unit_ids.keys() if _is_enemy_unit(iid) == false \
var is_enemy_unit : bool = _is_enemy_unit(iid)
var enemy_ids : Array = _enemy_unit_ids.keys() if not is_enemy_unit \
else _friendly_unit_ids.keys()
var found_bodies : int = 0
for eid in enemy_ids:
var eb := _unit_bodies.get(eid) as StaticBody3D
if not is_instance_valid(eb): continue
found_bodies += 1
var d : Vector3 = eb.global_position - my_pos
var sq : float = d.x * d.x + d.z * d.z
if sq < best_sq:
best_sq = sq
best_dir = d
if best_sq < INF and best_dir.length_squared() > 0.001:
if best_sq < INF and (best_dir.x != 0.0 or best_dir.z != 0.0):
var flat := Vector3(best_dir.x, 0.0, best_dir.z).normalized()
return atan2(flat.x, -flat.z) - base
# Log why closest-enemy failed.
push_warning("[IdleRot] FALLBACK iid=%s is_enemy=%s enemy_ids=%d bodies_found=%d best_sq=%s dir_xz=(%s,%s)" \
% [iid.substr(0,8), str(is_enemy_unit), enemy_ids.size(), found_bodies,
str(best_sq), str(best_dir.x), str(best_dir.z)])
else:
push_warning("[IdleRot] FALLBACK iid=%s — body not in _unit_bodies (friendly=%d enemy=%d)" \
% [iid.substr(0,8), _friendly_unit_ids.size(), _enemy_unit_ids.size()])
# Fallback: fixed north/south heuristic.
var flip : bool = bool(_needs_face_rot.get(iid, false))
var dir := Vector3(0, 0, 1) if flip else Vector3(0, 0, -1)