From 27c6a959adaf823f8be78334945462e44d947c72 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Wed, 16 Sep 2026 00:49:11 +0800 Subject: [PATCH] fix(uxassist): improve warp steering responsiveness Top up the warp heading toward the requested direction after game rotation so the actual heading achieves the 1.6-degree-per-tick turn step. Reduce warp speed control during large heading errors while preserving manual warp speed input. --- AGENTS.md | 2 +- UXAssist/Patches/PlayerPatch.cs | 58 +++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 2b4c108..67871b1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -160,7 +160,7 @@ The sync is implemented as an inline PowerShell `Exec` step inside the `ZipMod` - **Auto-construct planner:** `AutoConstructPatch` keeps a construction-site plan while drones work, chooses among a fixed candidate set using the native 120-target construction capacity, total drone travel cost, and player travel cost, then refines the strongest candidates to an actual ghost nearest the target-group center. Candidate scoring uses the planned flight altitude when evaluating build-range coverage. It replans before the current site is empty when the remaining local workload no longer covers the next flight. Candidate evaluation has fixed limits and uses allocation-free arrays; local construction checks scan actual hash entries instead of trusting stale module counters and include ghosts whose materials can be delivered from the mecha package. - **Auto-construct final pass:** When at most eight eligible construction ghosts remain, the planner bypasses site-hold hysteresis and routes directly to the nearest remaining ghost. The final-pass count is capped at nine during the existing prebuild scan, so large construction queues do not incur an additional unbounded performance cost. - **Auto-construct maintenance:** Planner scan reset, final-pass nearest-ghost routing, and route-arrival/recovery transitions use shared state helpers; no-op UI lifecycle forwarding is removed. -- **Auto-navigation:** UXAssist now exposes one auto-cruise implementation through `PlayerPatch.AutoNavigation`; the former legacy cruise path and algorithm-selection branch are removed. The shared `ToggleAutoCruise` key and in-game button control the session state. The configuration entry is presented as `Enable auto-cruise`, and its navigation options are grouped beneath it as indented 13-point sub-options. Steering follows the original `PlayerMove_Sail.GameTick` interpolation cap of 1.6 degrees per tick and explicitly chooses a stable turn plane for antiparallel velocity and target directions. Target resolution is validated once and applied atomically for both the UI and tick path; moving-target velocity is converted to universal coordinates; direct sail steering only runs while the player is sailing. Target state and reusable obstacle data are reset through one navigation lifecycle path. Satellite targets use a target corridor: an orbiting parent is ignored when the direct player-to-target segment is clear, shrinks its avoidance radius so it cannot contain the target, and otherwise follows a current-heading-selected tangent around the parent before returning to the satellite. +- **Auto-navigation:** UXAssist now exposes one auto-cruise implementation through `PlayerPatch.AutoNavigation`; the former legacy cruise path and algorithm-selection branch are removed. The shared `ToggleAutoCruise` key and in-game button control the session state. The configuration entry is presented as `Enable auto-cruise`, and its navigation options are grouped beneath it as indented 13-point sub-options. Steering follows the original `PlayerMove_Sail.GameTick` interpolation cap of 1.6 degrees per tick for the ordinary sail velocity and explicitly chooses a stable turn plane for antiparallel velocity and target directions. During warp, the added displacement uses `currentWarpVelocity` along mecha heading; after the game's heading update, a postfix tops up the warp heading toward the requested direction so the actual heading reaches the same 1.6-degree-per-tick minimum instead of lagging behind the ordinary velocity vector. Auto-navigation also reduces `warpSpeedControl` toward the game's 0.2 floor as heading error grows; manual warp speed controls take precedence. Target resolution is validated once and applied atomically for both the UI and tick path; moving-target velocity is converted to universal coordinates; direct sail steering only runs while the player is sailing. Target state and reusable obstacle data are reset through one navigation lifecycle path. Satellite targets use a target corridor: an orbiting parent is ignored when the direct player-to-target segment is clear, shrinks its avoidance radius so it cannot contain the target, and otherwise follows a current-heading-selected tangent around the parent before returning to the satellite. - **Auto-cruise flight input:** In the original `PlayerMove_Fly.GameTick`, `PlayerController.input0.y = 1` matches manual forward movement and `input1.y = 1` matches manual upward thrust. The auto-cruise `Fly` handler must preserve these signs so the mecha leaves a planet with the same orientation and motion as manual control. - **Shortcut input timing:** UXAssist dispatches mod shortcuts from a postfix of the original `VFInput.OnUpdate`, after DSP has refreshed its current modifier and UI input state. Do not move shortcut polling back to an independent plugin `Update()` or a logic-tick callback: CommonAPI `PressKeyBind.keyValue` combines Unity's current-frame `Input.GetKeyDown()` with `CombineKey` modifier caches refreshed by `VFInput.OnUpdate`. Polling before that refresh can miss a shortcut when a modifier changes in the same frame, which is easier to encounter at low frame rates. Keep the typing/menu guards and per-frame registry guards. - **UI clone initialization and text measurement:** UXAssist UI factories and dependent mods' direct UI clones treat runtime DSP objects as style sources only; after `Instantiate`, they explicitly reset stateful `UIButton`, `Text`, `Image`, `InputField`, `Slider`, and `UIComboBox` fields that can otherwise carry source state. Use `UXAssist.UI.Util.GetPreferredWidth` for dynamic text width because it invalidates DSP's custom text-generator cache before reading `preferredWidth`; do not replace it with a generic `TextGenerator` or canvas-wide rebuild without validating the rendered result. diff --git a/UXAssist/Patches/PlayerPatch.cs b/UXAssist/Patches/PlayerPatch.cs index d2637af..165470f 100644 --- a/UXAssist/Patches/PlayerPatch.cs +++ b/UXAssist/Patches/PlayerPatch.cs @@ -359,6 +359,7 @@ public class PlayerPatch : PatchImpl private const double ResidualCompensationMaxDistance = GalaxyData.AU * 0.5; private const double ResidualCompensationSpeedRatio = 0.5; private const double ResidualCompensationMinSpeed = 100; + private const float WarpTurnDegreesPerTick = 1.6f; private static bool _enabled; private static Text _uiTipText; @@ -372,6 +373,9 @@ public class PlayerPatch : PatchImpl private static readonly List Obstacles = new(64); private static bool _wasSailing; private static bool _followModeLock; + private static bool _warpSteeringPending; + private static Quaternion _warpHeadingBeforeRotation; + private static VectorLF3 _warpTargetDirection; public static bool IsActive => _enabled; @@ -487,6 +491,9 @@ public class PlayerPatch : PatchImpl _targetId = 0; _wasSailing = false; _followModeLock = false; + _warpSteeringPending = false; + _warpHeadingBeforeRotation = Quaternion.identity; + _warpTargetDirection = default; _targetUniversePosition = default; _targetUniverseVelocity = default; _targetType = default; @@ -956,6 +963,12 @@ public class PlayerPatch : PatchImpl stepSpeed = Math.Max(0, (currentVel - dVelocityBrake).magnitude); } + _warpSteeringPending = player.warping && targetDir.sqrMagnitude > Epsilon; + _warpHeadingBeforeRotation = player.uRotation; + _warpTargetDirection = _warpSteeringPending ? targetDir : default; + + AdaptWarpSpeedControl(controller, targetDir); + // Smooth velocity changes. VectorLF3 targetVelocity = targetDir * stepSpeed; float angle = Vector3.Angle(targetVelocity, currentVel); @@ -970,6 +983,51 @@ public class PlayerPatch : PatchImpl UpdateRotation(controller: controller); } + [HarmonyPatch(typeof(PlayerController), "UpdateRotation")] + [HarmonyPostfix] + private static void PlayerController_UpdateRotation_Postfix(PlayerController __instance) + { + if (!_enabled || !_warpSteeringPending) + return; + + _warpSteeringPending = false; + Player player = __instance.player; + if (player == null || __instance.movementStateInFrame != EMovementState.Sail || !player.warping) + return; + + Vector3 previousDirection = _warpHeadingBeforeRotation * Vector3.forward; + Vector3 currentDirection = player.uRotation * Vector3.forward; + Vector3 targetDirection = (Vector3)_warpTargetDirection; + float appliedAngle = Vector3.Angle(previousDirection, currentDirection); + float targetAngle = Vector3.Angle(currentDirection, targetDirection); + float remainingAngle = Mathf.Min(targetAngle, Mathf.Max(0f, WarpTurnDegreesPerTick - appliedAngle)); + if (remainingAngle < 0.01f) + return; + + Vector3 turnAxis = GetStableTurnAxis(currentDirection, targetDirection); + player.uRotation = Quaternion.AngleAxis(remainingAngle, turnAxis) * player.uRotation; + } + + private static void AdaptWarpSpeedControl(PlayerController controller, VectorLF3 targetDir) + { + Player player = controller.player; + if (!player.warping || VFInput._sailSpeedUp || controller.input0.y < 0f) + return; + + Vector3 warpDirection = player.uRotation * Vector3.forward; + float turnAngle = Vector3.Angle(warpDirection, targetDir); + double turnSeverity = Clamp((turnAngle - 15.0) / 45.0, 0.0, 1.0); + double targetControl = 1.0 - turnSeverity * turnSeverity * (3.0 - 2.0 * turnSeverity) * 0.8; + double controlDelta = Clamp( + targetControl - controller.actionSail.warpSpeedControl, + -0.02, + 0.02); + controller.actionSail.warpSpeedControl = Clamp( + controller.actionSail.warpSpeedControl + controlDelta, + 0.2, + 1.0); + } + private static VectorLF3 SmoothVelocity( VectorLF3 currentVelocity, VectorLF3 targetVelocity,