2026-03-15 점프,예비착지,착지후 경직

This commit is contained in:
skrwns304@gmail.com
2026-03-15 18:42:02 +09:00
parent a006b708c8
commit 56e9d97827
10 changed files with 284 additions and 4071 deletions

View File

@@ -1 +1 @@
public enum PlayerState { Idle, Walk, Run, Dodge, Jump, Fall, Attack, Charge, Hit, Dead }
public enum PlayerState { Idle, Walk, Run, Dodge, Jump, Fall, Attack, Charge, Hit, Dead, None }

View File

@@ -9,14 +9,32 @@ public class PlayerStateMachine : MonoBehaviour
public Action<PlayerState> OnStateChanged; // 상태가 변했을 때 다른 컴포넌트들이 알 수 있도록 이벤트 제공 (함수 포인터 활용)
public bool IsGrounded { get; set; } //상태 머신이기 때문에 계산은 여기서 안함 (플레이어가 갱신할 수 있도록 set 허용)
public bool IsCloseToGround { get; set; }
public bool IsRunInputPressed { get; set; } //달리기키가 눌린 상태인가
public bool IsPossibleCharge { get; set; } //현재 차지 가능한 상태인가
public bool IsMoveCut { get; set; } //현재 이동 금지 상태인가
public bool IsJumpCool { get; set; } //현재 점프 쿨타임 상태인가
private int _jumpCount = 0;
private int _maxJumpCount = 1;
private void Awake()
{
_anim = GetComponent<Animator>();
}
private void Update()
{
if (IsGrounded)
_jumpCount = 0;
}
public void RecordJump()
{
if(_maxJumpCount > _jumpCount) _jumpCount++;
}
public void ChangeState(PlayerState newState)
{
if (CurrentState == newState) return;
@@ -25,18 +43,27 @@ public void ChangeState(PlayerState newState)
if (CurrentState == PlayerState.Dead) return;
CurrentState = newState;
_anim.SetInteger("playerState", (int)newState);
OnStateChanged?.Invoke(newState);
//Debug.Log($"State Switched to: {newState}");
}
public void SetMaxJumpCount(int maxCount)
{
_maxJumpCount = maxCount;
}
#region
//지상 이동이 가능한가?
public bool CanMove() => IsGrounded && (CurrentState == PlayerState.Idle || CurrentState == PlayerState.Walk || CurrentState == PlayerState.Run);
public bool CanMove() => IsGrounded && !IsMoveCut && (CurrentState == PlayerState.Idle || CurrentState == PlayerState.Walk || CurrentState == PlayerState.Run);
//점프가 가능한 상태인가?
public bool CanJump() => IsGrounded && (CurrentState == PlayerState.Idle || CurrentState == PlayerState.Walk || CurrentState == PlayerState.Run);
public bool CanJump()
{
bool jumpAlreadyMax = (_maxJumpCount <= _jumpCount);
return IsGrounded && !IsMoveCut && !jumpAlreadyMax && (CurrentState == PlayerState.Idle || CurrentState == PlayerState.Walk || CurrentState == PlayerState.Run);
}
//대쉬가 가능한 상태인가?
public bool CanDodge()
{
@@ -49,13 +76,15 @@ public bool CanDodge()
// 피격 상태이거나 죽었을 때 안 되게
if (CurrentState == PlayerState.Hit || CurrentState == PlayerState.Dead) return false;
if (IsMoveCut) return false;
// 스태미나 시스템이 있다면 체크
// if (CurrentStamina < DodgeCost) return false;
return true;
}
//공중에서 조작 가능한 상태인가?
public bool CanControlInAir() => !IsGrounded && (CurrentState == PlayerState.Jump || CurrentState == PlayerState.Fall);
public bool CanControlInAir() => !IsGrounded && !IsMoveCut && (CurrentState == PlayerState.Jump || CurrentState == PlayerState.Fall);
//공격이 가능한 상태인가?
public bool CanAttack()
{