fix(ai): map team-relative rotation actions

This commit is contained in:
Josh Creek
2026-08-08 14:54:27 +01:00
parent 7e217df898
commit 57a298dc06
4 changed files with 38 additions and 3 deletions
+18
View File
@@ -8,6 +8,13 @@ extends RefCounted
# "do not fork this logic" role for observations; the train/inference seam
# broke once before over exactly this kind of divergence (commit 8c15c46).
#
# Ship thrust is body-local, so its axes must not be mirrored for team 1.
# Ship rotation, however, is applied directly as world-space torque in
# Ship.apply_rotation_forces(). Team 1 observes a canonical frame rotated
# 180 degrees about world Y, so its canonical pitch/roll outputs must be
# rotated back to world space before they reach the ship. apply_team_frame()
# is the shared training/inference seam for that conversion.
#
# Curriculum generation 4 replaces the old continuous Gaussian action space
# (Box(7), see the "continuous" path below) with a per-axis MultiDiscrete
# space: PPO's Gaussian std reliably collapsed to ~0.13-0.15 within the first
@@ -100,6 +107,17 @@ static func from_logits(logits: Array, noise: float) -> ShipAction:
return result
# Map a policy's canonical-frame rotation intent back into the physical
# team's world frame. A 180-degree Y rotation negates X and Z and leaves Y
# unchanged. Translation remains untouched because Ship applies it through
# the ship's local basis rather than as a world-space vector.
static func apply_team_frame(action: ShipAction, team: int) -> ShipAction:
if team == 1:
action.rotation.x = -action.rotation.x
action.rotation.z = -action.rotation.z
return action
# Legacy continuous decode — moved verbatim from ai_ship_controller.gd so
# every model exported before generation 4 (no "action_space" block in its
# JSON, e.g. Game/bots/promoted/easy.json) keeps behaving byte-identically.