fix(TankControllerBase): Turning is now persisted when AutoRun is enabled.

This commit is contained in:
MrGadget 2024-09-17 22:33:23 -04:00
parent e467be0d90
commit d67a087265

View File

@ -246,13 +246,17 @@ void HandleTurning(float deltaTime)
{ {
float targetTurnSpeed = 0f; float targetTurnSpeed = 0f;
// Q and E cancel each other out, reducing targetTurnSpeed to zero. // TurnLeft and TurnRight cancel each other out, reducing targetTurnSpeed to zero.
if (moveKeys.TurnLeft != KeyCode.None && Input.GetKey(moveKeys.TurnLeft)) if (moveKeys.TurnLeft != KeyCode.None && Input.GetKey(moveKeys.TurnLeft))
targetTurnSpeed -= maxTurnSpeed; targetTurnSpeed -= maxTurnSpeed;
if (moveKeys.TurnRight != KeyCode.None && Input.GetKey(moveKeys.TurnRight)) if (moveKeys.TurnRight != KeyCode.None && Input.GetKey(moveKeys.TurnRight))
targetTurnSpeed += maxTurnSpeed; targetTurnSpeed += maxTurnSpeed;
turnSpeed = Mathf.MoveTowards(turnSpeed, targetTurnSpeed, turnAcceleration * maxTurnSpeed * deltaTime); // If there's turn input or AutoRun is not enabled, adjust turn speed towards target
// If no turn input and AutoRun is enabled, maintain the previous turn speed
if (targetTurnSpeed != 0f || !controlOptions.HasFlag(ControlOptions.AutoRun))
turnSpeed = Mathf.MoveTowards(turnSpeed, targetTurnSpeed, turnAcceleration * maxTurnSpeed * deltaTime);
transform.Rotate(0f, turnSpeed * deltaTime, 0f); transform.Rotate(0f, turnSpeed * deltaTime, 0f);
} }