using UnityEngine; namespace OnlyScove.Scripts { public class PlayerMoveState : PlayerBaseState { public PlayerMoveState(PlayerStateMachine stateMachine) : base(stateMachine) {} public override void Enter() { stateMachine.AnimationHandler.SafeResetTrigger("Jump"); stateMachine.AnimationHandler.SafeResetTrigger("Fall"); stateMachine.AnimationHandler.ForceLocomotion(); stateMachine.Input.OnDodgeEvent += OnDodge; stateMachine.Input.OnCrouchEvent += OnCrouch; stateMachine.Input.OnInteractEvent += OnInteract; } public override void Tick(float deltaTime) { Vector2 input = stateMachine.MoveInput; float moveAmount = Mathf.Clamp01(Mathf.Abs(input.x) + Mathf.Abs(input.y)); if (moveAmount <= 0.01f) { stateMachine.SwitchState(new PlayerIdleState(stateMachine)); return; } if (stateMachine.IsSprintHeld) { stateMachine.SwitchState(new PlayerDashState(stateMachine)); return; } Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized; Vector3 moveDirection = stateMachine.CameraRotation * inputDir; moveDirection.y = 0; moveDirection.Normalize(); Vector3 velocity = moveDirection * stateMachine.WalkSpeed; if (stateMachine.IsGrounded && stateMachine.VelocityY < 0) { stateMachine.VelocityY = -2f; } else { stateMachine.VelocityY += stateMachine.Gravity * deltaTime; } velocity.y = stateMachine.VelocityY; stateMachine.Move(velocity, 0.7f, deltaTime); stateMachine.Rotate(moveDirection, deltaTime); } public override void PhysicsTick(float fixedDeltaTime) {} public override void Exit() { stateMachine.Input.OnDodgeEvent -= OnDodge; stateMachine.Input.OnCrouchEvent -= OnCrouch; stateMachine.Input.OnInteractEvent -= OnInteract; } private void OnDodge() => stateMachine.SwitchState(new PlayerDodgeState(stateMachine)); private void OnCrouch() => stateMachine.SwitchState(new PlayerCrouchState(stateMachine)); private void OnInteract() => stateMachine.SwitchState(new PlayerInteractState(stateMachine)); } }