Files
BABA_YAGA/Assets/Scripts/Player Controller/PlayerAirDashState.cs

49 lines
1.4 KiB
C#
Raw Normal View History

2026-04-08 12:38:39 +07:00
using UnityEngine;
2026-03-26 20:27:19 +07:00
namespace OnlyScove.Scripts
{
public class PlayerAirDashState : PlayerBaseState
{
2026-04-08 12:38:39 +07:00
private float dashDuration = 0.3f;
2026-03-26 20:27:19 +07:00
private float dashTimer;
private Vector3 dashDirection;
public PlayerAirDashState(PlayerStateMachine stateMachine) : base(stateMachine) {}
public override void Enter()
{
dashTimer = dashDuration;
2026-04-08 12:38:39 +07:00
stateMachine.Anim.SetTrigger("Dash");
2026-03-26 20:27:19 +07:00
2026-04-08 12:38:39 +07:00
// ĐÚNG: Sử dụng MoveInput đã đồng bộ
Vector2 input = stateMachine.MoveInput;
2026-03-26 20:27:19 +07:00
if (input != Vector2.zero)
{
2026-04-08 12:38:39 +07:00
dashDirection = new Vector3(input.x, 0, input.y).normalized;
2026-04-15 19:53:29 +07:00
dashDirection = stateMachine.CameraRotation * dashDirection;
2026-03-26 20:27:19 +07:00
}
else
{
dashDirection = stateMachine.transform.forward;
}
2026-04-08 12:38:39 +07:00
dashDirection.y = 0;
dashDirection.Normalize();
2026-03-26 20:27:19 +07:00
}
public override void Tick(float deltaTime)
{
dashTimer -= deltaTime;
2026-04-08 12:38:39 +07:00
// Sử dụng hàm Move tập trung
stateMachine.Move(dashDirection * stateMachine.DashForce, 1.0f, deltaTime);
2026-03-26 20:27:19 +07:00
2026-04-08 12:38:39 +07:00
if (dashTimer <= 0)
2026-03-26 20:27:19 +07:00
{
stateMachine.SwitchState(new PlayerFallState(stateMachine));
}
}
public override void PhysicsTick(float fixedDeltaTime) {}
public override void Exit() {}
}
}