diff --git a/Assets/01_Scenes/WhaleAdventure_VR/WhaleAttackScene.unity b/Assets/01_Scenes/WhaleAdventure_VR/WhaleAttackScene.unity index 8f472f2e..5a407346 100644 --- a/Assets/01_Scenes/WhaleAdventure_VR/WhaleAttackScene.unity +++ b/Assets/01_Scenes/WhaleAdventure_VR/WhaleAttackScene.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:33a976e0f1efed4f1655f1307a435c47fdcf195e776578f1f9e1cc3f012d5a3c -size 65004 +oid sha256:a83be1212d71adfb0d4630d53f17cd3c1f71ebd4ef069da501b6a09ad9b3dc00 +size 68116 diff --git a/Assets/02_Scripts/Player/PlayerController.cs b/Assets/02_Scripts/Player/PlayerController.cs index 145bb8db..6e050d62 100644 --- a/Assets/02_Scripts/Player/PlayerController.cs +++ b/Assets/02_Scripts/Player/PlayerController.cs @@ -1,50 +1,47 @@ using UnityEngine; +using UnityEngine.XR.Interaction.Toolkit.Locomotion.Movement; -[RequireComponent(typeof(Rigidbody))] -public class PlayerController : MonoBehaviour,ISceneInitializable +public class PlayerController : MonoBehaviour, ISceneInitializable { [Header("점프 설정")] - [SerializeField] private float _jumpForce = 5f; // 점프 세기(임펄스) - [SerializeField] private float _groundCheckDistance = 0.2f; // 바닥 판정 레이 길이 - [SerializeField] private LayerMask _groundLayer = ~0; // 바닥으로 인정할 레이어 + [SerializeField] private float _jumpHeight = 1.2f; - private Rigidbody _rb; + private Vector3 _playerVelocity; + private CharacterController _controller; + private ContinuousMoveProvider _moveProvider; + private float gravityValue = Physics.gravity.y; private void Awake() { - _rb = GetComponent(); + _controller = GetComponentInChildren(true); + _moveProvider = GetComponentInChildren(true); } public void OnSceneLoaded() { - // 중복 구독 방지 후 등록 (씬이 다시 로드돼도 한 번만 구독되도록) + // 씬이 다시 로드돼도 한 번만 구독되도록 중복 제거 후 등록 InputManager.Instance.OnJump_Event -= this.OnJump; InputManager.Instance.OnJump_Event += this.OnJump; } public void OnJump() { - if (_rb == null) + if (_controller == null) return; + if (!_controller.isGrounded) return; + + _playerVelocity.y = Mathf.Sqrt(_jumpHeight * -2f * gravityValue); + } + + private void Update() + { + // 바닥 체크 및 Y축 속도 초기화 + if (_controller.isGrounded && _playerVelocity.y < 0) { - Debug.LogWarning("[PlayerController] Rigidbody가 없어 점프할 수 없습니다.", this); - return; + // 완전히 0으로 두면 바닥 감지가 불안정할 수 있으므로 약간의 음수 값을 유지 + _playerVelocity.y = -2f; } - // 바닥에 닿아 있을 때만 점프 (공중 연속 점프 방지) - if (!IsGrounded()) return; - - // 수직 속도를 초기화한 뒤 위로 임펄스를 줘서 항상 같은 높이로 점프 - Vector3 v = _rb.linearVelocity; - v.y = 0f; - _rb.linearVelocity = v; - _rb.AddForce(Vector3.up * _jumpForce, ForceMode.Impulse); - } - - // 발밑으로 짧은 레이를 쏴서 바닥 접촉 여부 확인 - private bool IsGrounded() - { - Vector3 origin = transform.position + Vector3.up * 0.05f; - return Physics.Raycast(origin, Vector3.down, _groundCheckDistance + 0.05f, _groundLayer, - QueryTriggerInteraction.Ignore); + _playerVelocity.y += gravityValue * Time.deltaTime; + _controller.Move(_playerVelocity * Time.deltaTime); } }