59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using UnityEngine;
|
|
|
|
public class PlayerMovement : MonoBehaviour
|
|
{
|
|
[Header("--- 참조 ---")]
|
|
[SerializeField] private Stats stats;
|
|
[SerializeField] private PlayerHealth health;
|
|
[SerializeField] private PlayerAnimator pAnim;
|
|
[SerializeField] private PlayerAttack attackScript; // ⭐ 차징 상태 확인용 추가
|
|
|
|
[Header("--- 차징 감속 설정 ---")]
|
|
[Range(0.1f, 1f)]
|
|
[Tooltip("풀차징 시 원래 속도의 몇 %로 줄일지 설정 (0.3 = 30% 속도)")]
|
|
[SerializeField] private float minSpeedMultiplier = 0.3f; //
|
|
|
|
private Vector3 _moveDir;
|
|
private bool _isSprinting;
|
|
|
|
public void SetMoveInput(Vector3 dir, bool sprint) { _moveDir = dir; _isSprinting = sprint; }
|
|
|
|
private void Update()
|
|
{
|
|
// 💀 사망 시 모든 이동 및 애니메이션 중단
|
|
if (health != null && health.IsDead)
|
|
{
|
|
if (pAnim != null) pAnim.UpdateMove(0f);
|
|
return;
|
|
}
|
|
|
|
// 1. 기본 이동 속도 결정
|
|
float speed = _isSprinting ? stats.CurrentRunSpeed : stats.CurrentMoveSpeed;
|
|
|
|
// 2. ⭐ [추가] 차징 진행도에 따른 점진적 감속 로직
|
|
if (attackScript != null && attackScript.IsCharging)
|
|
{
|
|
// ChargeProgress ($0 \sim 1$)에 따라 1.0(정상)에서 minSpeedMultiplier(최소)까지 부드럽게 감소
|
|
// 예: 풀차징 시 원래 속도의 30%만 사용
|
|
float speedReduction = Mathf.Lerp(1.0f, minSpeedMultiplier, attackScript.ChargeProgress);
|
|
speed *= speedReduction;
|
|
}
|
|
|
|
// 3. 이동 처리
|
|
transform.Translate(_moveDir * speed * Time.deltaTime, Space.World);
|
|
|
|
// 4. ⭐ 애니메이션 연동
|
|
if (pAnim != null)
|
|
{
|
|
float animVal = _moveDir.magnitude > 0.1f ? (_isSprinting ? 1.0f : 0.5f) : 0f;
|
|
|
|
// ⭐ 차징 중이면 걷는 애니메이션 속도도 살짝 늦춰서 묵직함을 더함
|
|
if (attackScript != null && attackScript.IsCharging)
|
|
{
|
|
animVal *= 0.5f;
|
|
}
|
|
|
|
pAnim.UpdateMove(animVal);
|
|
}
|
|
}
|
|
} |