Keyboard turning ramps down on release at the same rate it ramps up, so tapping at a rate holds a gentle turn; reversal still cuts to zero

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-10-29 08:09:29 +01:00
commit 633ae3353a
2 changed files with 12 additions and 6 deletions

View file

@ -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<Vector2>().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<float>(), 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<float>(), _turnDigital, Time.deltaTime, KeyboardTurnRampTime);
ship.Command.Turn = _helm.Demand(_viewDirection.xz, turnAxis);
}

View file

@ -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.