diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 7f6451934..38a1e1f73 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -203,6 +203,8 @@ public class ActionGameManager : MonoBehaviour private readonly HelmInput _helm = new HelmInput(); // Seconds a held turn key takes to reach full turn rate. public float KeyboardTurnRampTime = .4f; + // Whether the turn axis was last driven by keys; kept while released so the ramp down still applies. + private bool _turnDigital; private TextMeshProUGUI _faceAimMark; private (HardpointData[] hardpoints, Transform[] barrels, PlaceUIElementWorldspace crosshair)[] _articulationGroups; // The outgoing progress indicators on the player's target: one per lock weapon (its Lock, shown only on a hostile target) @@ -1337,8 +1339,9 @@ public class ActionGameManager : MonoBehaviour { ship.Command.Movement = Input.Player.Move.ReadValue().ToCultMath(); _helm.Held = Input.Player.FaceAim.IsPressed(); - var turnDigital = Input.Player.Turn.activeControl?.device is UnityEngine.InputSystem.Keyboard; - var turnAxis = _helm.TurnAxis(Input.Player.Turn.ReadValue(), turnDigital, Time.deltaTime, KeyboardTurnRampTime); + if (Input.Player.Turn.activeControl is { } turnControl) + _turnDigital = turnControl.device is UnityEngine.InputSystem.Keyboard; + var turnAxis = _helm.TurnAxis(Input.Player.Turn.ReadValue(), _turnDigital, Time.deltaTime, KeyboardTurnRampTime); ship.Command.Turn = _helm.Demand(_viewDirection.xz, turnAxis); } diff --git a/Assets/Scripts/ServerShared/HelmInput.cs b/Assets/Scripts/ServerShared/HelmInput.cs index aa9cd3a03..d8ff21efe 100644 --- a/Assets/Scripts/ServerShared/HelmInput.cs +++ b/Assets/Scripts/ServerShared/HelmInput.cs @@ -15,13 +15,16 @@ public class HelmInput private float _turnAxis; - // The turn axis as the helm reads it. A digital input (keys) ramps from zero to full over rampTime so a tap feathers the - // turn; releasing it, or reversing, starts again from zero. An analog input passes straight through. + // The turn axis as the helm reads it. A digital input (keys) ramps up while held and back down while released, both at + // full scale per rampTime, so tapping at a rate holds a gentle turn; reversing cuts to zero and ramps the other way. + // An analog input passes straight through. public float TurnAxis(float raw, bool digital, float dt, float rampTime) { - if (!digital || rampTime <= 0 || raw == 0) return _turnAxis = raw; + if (!digital || rampTime <= 0) return _turnAxis = raw; + var step = dt / rampTime; + if (raw == 0) return _turnAxis = sign(_turnAxis) * max(0f, abs(_turnAxis) - step); if (sign(raw) != sign(_turnAxis)) _turnAxis = 0; - return _turnAxis = sign(raw) * min(abs(raw), abs(_turnAxis) + dt / rampTime); + return _turnAxis = sign(raw) * min(abs(raw), abs(_turnAxis) + step); } // The turn the player commands: the aim heading, resolved against the hull at each sim step, or the turn axis.