From f8bd79042bcd25a48eb139d7177ef86bbf8be712 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Sun, 6 Dec 2026 13:53:52 +0800 Subject: [PATCH] fix(ground-ai): command the turret servo with the wished angle The turret command led the current yaw by one frame's traverse step, so the stock servo crawled: the replay trace measured about 4 deg/s relative to the hull while the barrel was more than 20 deg off, against a median stock traverse of 24 deg/s. Bots kept their barrels on the hull and were mostly denied by aim error at close range. yawLim and pitchLim now carry the wished angles, clipped to the mount's yaw arc and to the elevation sector the barrel is in. A full-traverse command leads the turret by at most 90 deg so it always turns the short way. Secondary mounts use the same command, and the unused frame time argument of their aiming path is dropped. In a lab battle the 90th percentile turret rate rose to 28 deg/s, the median aim error to target fell from 15-22 deg to 2 deg, and moving shots rose from under 20% to 49% of main gun shots. --- game-ai/ground/wto_ai_fire_aux_common.das | 4 +- game-ai/ground/wto_ai_fire_common.das | 2 +- game-ai/ground/wto_ai_traverse_common.das | 49 ++++++++++++----------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/game-ai/ground/wto_ai_fire_aux_common.das b/game-ai/ground/wto_ai_fire_aux_common.das index af55b90..2240389 100644 --- a/game-ai/ground/wto_ai_fire_aux_common.das +++ b/game-ai/ground/wto_ai_fire_aux_common.das @@ -27,7 +27,7 @@ def private wto_aux_group(groupNo : int) : bool return groupNo == int(WeaponTriggerGroups.TRIGGER_GROUP_SECONDARY) || groupNo == int(WeaponTriggerGroups.TRIGGER_GROUP_COAXIAL_GUN) [never_inline] -def public wto_fire_aux_aim(var unit : Unit?; className : string; dt, dist : float; var slot : WtoBotSlot&) : bool +def public wto_fire_aux_aim(var unit : Unit?; className : string; dist : float; var slot : WtoBotSlot&) : bool if !wto_aux_in_range(dist) return false var changed = false @@ -49,7 +49,7 @@ def public wto_fire_aux_aim(var unit : Unit?; className : string; dt, dist : flo var aimPt = base var direction = gunTm[0] let _range = wto_solve_ballistic_aim(gunTm[3], unit.vel, base, mount.shell.speedMps, mount.shell.dragCx, mount.shell.massKg, mount.shell.caliberM, slot, aimPt, direction) - if wto_aim_aux_mount(unit, className, dt, tIdx, direction, mount) + if wto_aim_aux_mount(unit, className, tIdx, direction, mount) changed = true return changed diff --git a/game-ai/ground/wto_ai_fire_common.das b/game-ai/ground/wto_ai_fire_common.das index 1213d5d..b91406a 100644 --- a/game-ai/ground/wto_ai_fire_common.das +++ b/game-ai/ground/wto_ai_fire_common.das @@ -271,7 +271,7 @@ def public wto_fire_update(world : WtoWorldSnap const&; var unit : Unit?; classN if engage let aimBase = slot.perceive.visibleAimPt distToTgt = wto_solve_ballistic_aim(muzzlePos, unit.vel, aimBase, slot.fire.activeSpeedMps, slot.fire.activeDragCx, slot.fire.activeMassKg, slot.fire.activeCaliberM, slot, aimPt, wishWorldDir) - auxAimed = wto_fire_aux_aim(unit, className, dt, distXZ, slot) + auxAimed = wto_fire_aux_aim(unit, className, distXZ, slot) slot.turret.lookReason = WTO_LOOK_ENGAGE else wishWorldDir = wto_turret_look_dir(now, muzzlePos, unit.pos, hFwd, slot) diff --git a/game-ai/ground/wto_ai_traverse_common.das b/game-ai/ground/wto_ai_traverse_common.das index d5b99bb..907ccb6 100644 --- a/game-ai/ground/wto_ai_traverse_common.das +++ b/game-ai/ground/wto_ai_traverse_common.das @@ -123,19 +123,25 @@ def public wto_hull_deg_to_world(yawDeg, pitchDeg : float; hullFwd, hullUp, hull let l = length(dir) return l > 1.0e-5 ? (dir / l) : hullFwd -def private wto_step_mounted_yaw(current, desired, step : float; arc : float2) : float - if wto_full_gun_traverse(arc) - return wto_wrap_deg(current + clamp(wto_wrap_deg(desired - current), -step, step)) - let clampedCurrent = clamp(wto_yaw_in_mount_coordinates(current, arc), arc.x, arc.y) - let clampedTarget = clamp(wto_yaw_in_mount_coordinates(desired, arc), arc.x, arc.y) - return clamp(clampedCurrent + clamp(clampedTarget - clampedCurrent, -step, step), arc.x, arc.y) +// A full-traverse command never leads the turret by more than this, so the stock servo always +// takes the short way round; any value below 180 keeps that, it does not set the speed. +let private WTO_SERVO_MAX_LEAD_DEG = 90.0 -def private wto_track_blocked_pitch(wishPitch, wishYaw, cmdYaw, dtStep : float; pitch : float2; var slot : WtoBotSlot&) +// Yaw command for the stock servo: the wished yaw itself, inside the mount's arc. The servo then +// turns at the vehicle's own traverse speed instead of being led one frame's step at a time. +def private wto_servo_yaw(current, desired : float; arc : float2) : float + if wto_full_gun_traverse(arc) + let lead = clamp(wto_wrap_deg(desired - current), -WTO_SERVO_MAX_LEAD_DEG, WTO_SERVO_MAX_LEAD_DEG) + return wto_wrap_deg(current + lead) + return clamp(wto_yaw_in_mount_coordinates(desired, arc), arc.x, arc.y) + +// `atYaw` is where the barrel points now: elevation counts as blocked only once it is there. +def private wto_track_blocked_pitch(wishPitch, wishYaw, atYaw, dtStep : float; pitch : float2; var slot : WtoBotSlot&) assume fc = slot.fire let pitchSpd = abs(fc.curPitchDeg - fc.prevPitchDeg) / dtStep fc.prevPitchDeg = fc.curPitchDeg let align = WTO_AI_FC_BASE_ALIGN_DEG - let aimedYaw = abs(wto_wrap_deg(cmdYaw - wishYaw)) <= align + let aimedYaw = abs(wto_wrap_deg(atYaw - wishYaw)) <= align let outside = wishPitch < pitch.x - align || wishPitch > pitch.y + align fc.pitchAtLimit = aimedYaw && wto_valid_angle_range(pitch) && outside if slot.perceive.hasClearLos && fc.pitchAtLimit && pitchSpd < 0.8 @@ -172,21 +178,19 @@ def public wto_drive_mounted_gun(var unit : Unit?; className : string; dt : floa if !fc.traverse.known return let yaw = fc.traverse.yaw - let maxYawStep = max(24.0, slot.spec.turretYawSpd * 1.1) * dtStep - let cmdYaw = wto_step_mounted_yaw(fc.curYawDeg, wishYawDeg, maxYawStep, yaw) - let maxPitchStep = max(10.0, slot.spec.turretPitchSpd * 1.1) * dtStep - let pitch = wto_gun_pitch_at_yaw(className, triggerNo, weaponIndex, cmdYaw, fc.traverse) - wto_track_blocked_pitch(wishPitchDeg, wishYawDeg, cmdYaw, dtStep, pitch, slot) - turret.yawLim = cmdYaw + // Elevation limits where the barrel is now; they change by sector as the turret turns. + let hereYaw = wto_yaw_in_mount_coordinates(fc.curYawDeg, yaw) + let pitch = wto_gun_pitch_at_yaw(className, triggerNo, weaponIndex, hereYaw, fc.traverse) + wto_track_blocked_pitch(wishPitchDeg, wishYawDeg, fc.curYawDeg, dtStep, pitch, slot) + turret.yawLim = wto_servo_yaw(fc.curYawDeg, wishYawDeg, yaw) if pitch.x <= pitch.y - let pitchDelta = clamp(wishPitchDeg - fc.curPitchDeg, -maxPitchStep, maxPitchStep) - turret.pitchLim = clamp(fc.curPitchDeg + pitchDelta, pitch.x, pitch.y) + turret.pitchLim = clamp(wishPitchDeg, pitch.x, pitch.y) break // Secondary mounts with their own limits can track independently. Coaxial mounts with no // limits follow the main turret through the stock weapon animation. [never_inline] -def public wto_aim_aux_mount(var unit : Unit?; className : string; dt : float; turretNo : int; +def public wto_aim_aux_mount(var unit : Unit?; className : string; turretNo : int; wishDir : float3; var cached : WtoMountFire&) : bool assume turret = unit.weap.turret[turretNo] let triggerNo = int(turret.triggerNo) @@ -199,13 +203,12 @@ def public wto_aim_aux_mount(var unit : Unit?; className : string; dt : float; t var wishYaw = 0.0 var wishPitch = 0.0 wto_world_to_hull_deg(wishDir, unit.unitTm[0], unit.unitTm[1], unit.unitTm[2], wishYaw, wishPitch) - let step = clamp(dt, 0.005, 0.12) - let cmdYaw = wto_step_mounted_yaw(turret.currentState.yaw, wishYaw, step * 24.0, cached.traverse.yaw) - let pitch = wto_gun_pitch_at_yaw(className, triggerNo, weaponIndex, cmdYaw, cached.traverse) - turret.yawLim = cmdYaw + let arc = cached.traverse.yaw + let hereYaw = wto_yaw_in_mount_coordinates(turret.currentState.yaw, arc) + let pitch = wto_gun_pitch_at_yaw(className, triggerNo, weaponIndex, hereYaw, cached.traverse) + turret.yawLim = wto_servo_yaw(turret.currentState.yaw, wishYaw, arc) if pitch.x <= pitch.y - let pitchChange = clamp(wishPitch - turret.currentState.pitch, -step * 10.0, step * 10.0) - turret.pitchLim = clamp(turret.currentState.pitch + pitchChange, pitch.x, pitch.y) + turret.pitchLim = clamp(wishPitch, pitch.x, pitch.y) return true def public wto_apply_weapon_aim(var unit : Unit?; dt : float)