가속 추가
This commit is contained in:
parent
07b96c129e
commit
4335c5db05
|
@ -6,6 +6,9 @@ public class PlayerController : MonoBehaviour
|
|||
public float moveSpeed = 5f; // 이동 속도
|
||||
public float dashDistance = 3f; // 대시 거리
|
||||
public float dashCooldown = 1f; // 대시 쿨타임
|
||||
public float maxSpeed = 8f; // 최대 속도 (2~3초 후 최대 속도 도달)
|
||||
public float accelerationTime = 2f; // 2초 동안 가속
|
||||
private float moveTime = 0f; // 이동한 시간
|
||||
public float dashTime = 0.5f;
|
||||
private bool canDash = true; // 대시 가능 여부
|
||||
private Vector2 moveDirection = Vector2.zero; // 현재 이동 방향
|
||||
|
@ -55,10 +58,22 @@ public class PlayerController : MonoBehaviour
|
|||
// 이동 방향이 있을 때만 이동
|
||||
if (isWalking)
|
||||
{
|
||||
transform.position += (Vector3)(moveDirection.normalized * moveSpeed * Time.deltaTime);
|
||||
// 애니메이션 이동 방향 설정
|
||||
animator.SetFloat("moveX", Mathf.Abs(moveDirection.x));
|
||||
animator.SetFloat("moveY", moveDirection.y);
|
||||
moveTime += Time.deltaTime;
|
||||
// 2초 이상 이동하면 즉시 속도를 maxSpeed로 증가
|
||||
float currentSpeed = HandleAcceleration();
|
||||
|
||||
transform.position += (Vector3)(moveDirection.normalized * currentSpeed * Time.deltaTime);
|
||||
// A 또는 D가 눌린 상태라면 Side 애니메이션을 우선 적용
|
||||
if (moveDirection.x != 0)
|
||||
{
|
||||
animator.SetFloat("moveX", 1); // 무조건 Side 애니메이션
|
||||
animator.SetFloat("moveY", 0); // 위/아래는 무시
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.SetFloat("moveX", 0);
|
||||
animator.SetFloat("moveY", moveDirection.y);
|
||||
}
|
||||
|
||||
// 회전 처리
|
||||
if (Mathf.Abs(moveDirection.x) > 0)
|
||||
|
@ -76,12 +91,25 @@ public class PlayerController : MonoBehaviour
|
|||
else
|
||||
{
|
||||
// 이동하지 않으면 Idle 상태를 설정
|
||||
moveTime = 0f;
|
||||
animator.SetFloat("moveX", 0);
|
||||
animator.SetFloat("moveY", 0);
|
||||
animator.SetFloat("idleState", idleState);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
float HandleAcceleration()
|
||||
{
|
||||
if (isWalking)
|
||||
{
|
||||
moveTime += Time.deltaTime;
|
||||
if (moveTime >= accelerationTime)
|
||||
{
|
||||
return maxSpeed; // 2초 이상 이동 시 가속
|
||||
}
|
||||
}
|
||||
return moveSpeed; // 기본 속도
|
||||
}
|
||||
// 대시 처리
|
||||
void Dash()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue