fix(TankControllerBase): Removed unused horizontal code

This commit is contained in:
MrGadget 2024-09-30 08:00:01 -04:00
parent 98d192aa84
commit d76c1c8f64

View File

@ -12,7 +12,7 @@ namespace Mirror.Examples.Common.Controllers.Tank
[DisallowMultipleComponent] [DisallowMultipleComponent]
public class TankControllerBase : NetworkBehaviour public class TankControllerBase : NetworkBehaviour
{ {
public enum GroundState : byte { Grounded, Jumping, Falling } public enum GroundState : byte { Grounded, Falling }
[Serializable] [Serializable]
public struct MoveKeys public struct MoveKeys
@ -94,7 +94,6 @@ public enum ControlOptions : byte
[Serializable] [Serializable]
public struct RuntimeData public struct RuntimeData
{ {
[ReadOnly, SerializeField, Range(-1f, 1f)] float _horizontal;
[ReadOnly, SerializeField, Range(-1f, 1f)] float _vertical; [ReadOnly, SerializeField, Range(-1f, 1f)] float _vertical;
[ReadOnly, SerializeField, Range(-300f, 300f)] float _turnSpeed; [ReadOnly, SerializeField, Range(-300f, 300f)] float _turnSpeed;
[ReadOnly, SerializeField, Range(-1.5f, 1.5f)] float _animVelocity; [ReadOnly, SerializeField, Range(-1.5f, 1.5f)] float _animVelocity;
@ -106,12 +105,6 @@ public struct RuntimeData
#region Properties #region Properties
public float horizontal
{
get => _horizontal;
internal set => _horizontal = value;
}
public float vertical public float vertical
{ {
get => _vertical; get => _vertical;
@ -213,7 +206,6 @@ protected virtual void Reset()
void OnDisable() void OnDisable()
{ {
runtimeData.horizontal = 0f;
runtimeData.vertical = 0f; runtimeData.vertical = 0f;
runtimeData.turnSpeed = 0f; runtimeData.turnSpeed = 0f;
} }
@ -266,10 +258,7 @@ void Update()
ApplyMove(deltaTime); ApplyMove(deltaTime);
// Reset ground state // Reset ground state
if (characterController.isGrounded) runtimeData.groundState = characterController.isGrounded ? GroundState.Grounded : GroundState.Falling;
runtimeData.groundState = GroundState.Grounded;
else if (runtimeData.groundState != GroundState.Jumping)
runtimeData.groundState = GroundState.Falling;
// Diagnostic velocity...FloorToInt for display purposes // Diagnostic velocity...FloorToInt for display purposes
runtimeData.velocity = Vector3Int.FloorToInt(characterController.velocity); runtimeData.velocity = Vector3Int.FloorToInt(characterController.velocity);
@ -311,21 +300,12 @@ void HandleTurning(float deltaTime)
void HandleMove(float deltaTime) void HandleMove(float deltaTime)
{ {
// Initialize target movement variables // Initialize target movement variables
float targetMoveX = 0f;
float targetMoveZ = 0f; float targetMoveZ = 0f;
// Check for WASD key presses and adjust target movement variables accordingly // Check for WASD key presses and adjust target movement variables accordingly
if (moveKeys.Forward != KeyCode.None && Input.GetKey(moveKeys.Forward)) targetMoveZ = 1f; if (moveKeys.Forward != KeyCode.None && Input.GetKey(moveKeys.Forward)) targetMoveZ = 1f;
if (moveKeys.Back != KeyCode.None && Input.GetKey(moveKeys.Back)) 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 (targetMoveZ == 0f)
{ {
if (!controlOptions.HasFlag(ControlOptions.AutoRun)) if (!controlOptions.HasFlag(ControlOptions.AutoRun))
@ -337,11 +317,8 @@ void HandleMove(float deltaTime)
void ApplyMove(float deltaTime) void ApplyMove(float deltaTime)
{ {
// Create initial direction vector without jumpSpeed (y-axis). // Create initial direction vector (z-axis only)
runtimeData.direction = new Vector3(runtimeData.horizontal, 0f, runtimeData.vertical); runtimeData.direction = new Vector3(0f, 0f, runtimeData.vertical);
// Clamp so diagonal strafing isn't a speed advantage.
runtimeData.direction = Vector3.ClampMagnitude(runtimeData.direction, 1f);
// Transforms direction from local space to world space. // Transforms direction from local space to world space.
runtimeData.direction = transform.TransformDirection(runtimeData.direction); runtimeData.direction = transform.TransformDirection(runtimeData.direction);