From d76c1c8f6452c04dc80a12f0da82f95709d1c9e1 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:00:01 -0400 Subject: [PATCH] fix(TankControllerBase): Removed unused horizontal code --- .../TankController/TankControllerBase.cs | 31 +++---------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/Assets/Mirror/Examples/_Common/Controllers/TankController/TankControllerBase.cs b/Assets/Mirror/Examples/_Common/Controllers/TankController/TankControllerBase.cs index f870fed98..4953d998c 100644 --- a/Assets/Mirror/Examples/_Common/Controllers/TankController/TankControllerBase.cs +++ b/Assets/Mirror/Examples/_Common/Controllers/TankController/TankControllerBase.cs @@ -12,7 +12,7 @@ namespace Mirror.Examples.Common.Controllers.Tank [DisallowMultipleComponent] public class TankControllerBase : NetworkBehaviour { - public enum GroundState : byte { Grounded, Jumping, Falling } + public enum GroundState : byte { Grounded, Falling } [Serializable] public struct MoveKeys @@ -94,7 +94,6 @@ public enum ControlOptions : byte [Serializable] public struct RuntimeData { - [ReadOnly, SerializeField, Range(-1f, 1f)] float _horizontal; [ReadOnly, SerializeField, Range(-1f, 1f)] float _vertical; [ReadOnly, SerializeField, Range(-300f, 300f)] float _turnSpeed; [ReadOnly, SerializeField, Range(-1.5f, 1.5f)] float _animVelocity; @@ -106,12 +105,6 @@ public struct RuntimeData #region Properties - public float horizontal - { - get => _horizontal; - internal set => _horizontal = value; - } - public float vertical { get => _vertical; @@ -213,7 +206,6 @@ protected virtual void Reset() void OnDisable() { - runtimeData.horizontal = 0f; runtimeData.vertical = 0f; runtimeData.turnSpeed = 0f; } @@ -266,10 +258,7 @@ void Update() ApplyMove(deltaTime); // Reset ground state - if (characterController.isGrounded) - runtimeData.groundState = GroundState.Grounded; - else if (runtimeData.groundState != GroundState.Jumping) - runtimeData.groundState = GroundState.Falling; + runtimeData.groundState = characterController.isGrounded ? GroundState.Grounded : GroundState.Falling; // Diagnostic velocity...FloorToInt for display purposes runtimeData.velocity = Vector3Int.FloorToInt(characterController.velocity); @@ -311,21 +300,12 @@ void HandleTurning(float deltaTime) void HandleMove(float deltaTime) { // Initialize target movement variables - float targetMoveX = 0f; float targetMoveZ = 0f; // Check for WASD key presses and adjust target movement variables accordingly if (moveKeys.Forward != KeyCode.None && Input.GetKey(moveKeys.Forward)) targetMoveZ = 1f; if (moveKeys.Back != KeyCode.None && Input.GetKey(moveKeys.Back)) targetMoveZ = -1f; - if (targetMoveX == 0f) - { - if (!controlOptions.HasFlag(ControlOptions.AutoRun)) - runtimeData.horizontal = Mathf.MoveTowards(runtimeData.horizontal, targetMoveX, inputGravity * deltaTime); - } - else - runtimeData.horizontal = Mathf.MoveTowards(runtimeData.horizontal, targetMoveX, inputSensitivity * deltaTime); - if (targetMoveZ == 0f) { if (!controlOptions.HasFlag(ControlOptions.AutoRun)) @@ -337,11 +317,8 @@ void HandleMove(float deltaTime) void ApplyMove(float deltaTime) { - // Create initial direction vector without jumpSpeed (y-axis). - runtimeData.direction = new Vector3(runtimeData.horizontal, 0f, runtimeData.vertical); - - // Clamp so diagonal strafing isn't a speed advantage. - runtimeData.direction = Vector3.ClampMagnitude(runtimeData.direction, 1f); + // Create initial direction vector (z-axis only) + runtimeData.direction = new Vector3(0f, 0f, runtimeData.vertical); // Transforms direction from local space to world space. runtimeData.direction = transform.TransformDirection(runtimeData.direction);