Keyboard turning ramps to full over KeyboardTurnRampTime (0.4 s) so a tap feathers the turn; analog turn passes straight through

Release or reversal starts the ramp again from zero (operator request, 2026-10-29: the Longinus lurches).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-10-29 08:07:30 +01:00
commit 5e2a9efc8a
2 changed files with 16 additions and 1 deletions

View file

@ -201,6 +201,8 @@ public class ActionGameManager : MonoBehaviour
private float3 _viewDirection;
// The player's face-the-aim state (Left Shift held, Caps Lock latched); Ship.Turn is its only output.
private readonly HelmInput _helm = new HelmInput();
// Seconds a held turn key takes to reach full turn rate.
public float KeyboardTurnRampTime = .4f;
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)
@ -1335,7 +1337,9 @@ public class ActionGameManager : MonoBehaviour
{
ship.Command.Movement = Input.Player.Move.ReadValue<Vector2>().ToCultMath();
_helm.Held = Input.Player.FaceAim.IsPressed();
ship.Command.Turn = _helm.Demand(_viewDirection.xz, Input.Player.Turn.ReadValue<float>());
var turnDigital = Input.Player.Turn.activeControl?.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);
}
UpdateMusic();

View file

@ -13,6 +13,17 @@ public class HelmInput
public void Toggle() => Latched = !Latched;
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.
public float TurnAxis(float raw, bool digital, float dt, float rampTime)
{
if (!digital || rampTime <= 0 || raw == 0) return _turnAxis = raw;
if (sign(raw) != sign(_turnAxis)) _turnAxis = 0;
return _turnAxis = sign(raw) * min(abs(raw), abs(_turnAxis) + dt / rampTime);
}
// The turn the player commands: the aim heading, resolved against the hull at each sim step, or the turn axis.
public TurnCommand Demand(float2 aim, float turnAxis) =>
FaceAim ? TurnCommand.Toward(aim) : TurnCommand.OfRate(clamp(turnAxis, -1f, 1f));