2026-06-18 많은 플레이어 수정사항
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Unity.XR.CoreUtils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit.Locomotion.Movement;
|
||||
|
||||
@@ -9,12 +10,17 @@ public class PlayerController : MonoBehaviour, ISceneInitializable
|
||||
private Vector3 _playerVelocity;
|
||||
private CharacterController _controller;
|
||||
private ContinuousMoveProvider _moveProvider;
|
||||
private XROrigin _xrOrigin;
|
||||
private float gravityValue = Physics.gravity.y;
|
||||
|
||||
public bool IsSitting { get; private set; } // 앉아있는 동안 true (이동/점프 잠금)
|
||||
private float _standingHeight; // 앉기 전 카메라 높이(일어설 때 복원용)
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_controller = GetComponentInChildren<CharacterController>(true);
|
||||
_moveProvider = GetComponentInChildren<ContinuousMoveProvider>(true);
|
||||
_xrOrigin = GetComponentInChildren<XROrigin>(true);
|
||||
}
|
||||
|
||||
public void OnSceneLoaded()
|
||||
@@ -24,14 +30,62 @@ public void OnSceneLoaded()
|
||||
InputManager.Instance.OnJump_Event += this.OnJump;
|
||||
}
|
||||
|
||||
public void SetHeight(float height)
|
||||
{
|
||||
_xrOrigin.CameraYOffset = height;
|
||||
}
|
||||
|
||||
public void OnJump()
|
||||
{
|
||||
if (_controller == null) return;
|
||||
if (IsSitting) return; // 앉아있는 동안은 점프 금지
|
||||
if (!_controller.isGrounded) return;
|
||||
|
||||
_playerVelocity.y = Mathf.Sqrt(_jumpHeight * -2f * gravityValue);
|
||||
}
|
||||
|
||||
// 앉기 시작: (좌석 지정 시) 그 위치로 이동 후 카메라 높이를 낮추고 이동을 잠근다.
|
||||
public void Sit(Transform sitPoint = null)
|
||||
{
|
||||
if (IsSitting) return;
|
||||
IsSitting = true;
|
||||
|
||||
if (sitPoint != null) TeleportRig(sitPoint); // 좌석 위치/방향으로 순간이동
|
||||
|
||||
_standingHeight = _xrOrigin.CameraYOffset; // 현재 높이 기억
|
||||
SetHeight(1.2f);
|
||||
|
||||
if (_moveProvider != null) _moveProvider.enabled = false; // 이동 잠금
|
||||
}
|
||||
|
||||
// XR 리그(=플레이어 전체)를 target의 위치/방향으로 순간이동.
|
||||
// CharacterController는 켜진 채로 transform을 직접 바꾸면 되돌려지므로 잠시 끈다.
|
||||
private void TeleportRig(Transform target)
|
||||
{
|
||||
Transform rig = _xrOrigin != null ? _xrOrigin.transform : transform;
|
||||
|
||||
bool ccWasEnabled = _controller != null && _controller.enabled;
|
||||
if (_controller != null) _controller.enabled = false;
|
||||
|
||||
// 회전은 수평(yaw)만 적용해 기울어짐 방지
|
||||
rig.SetPositionAndRotation(target.position, Quaternion.Euler(0f, target.eulerAngles.y, 0f));
|
||||
|
||||
if (_controller != null) _controller.enabled = ccWasEnabled;
|
||||
|
||||
_playerVelocity = Vector3.zero; // 텔레포트 직후 누적 낙하속도 튐 방지
|
||||
}
|
||||
|
||||
// 일어서기: 높이 복원 + 이동 잠금 해제.
|
||||
public void StandUp()
|
||||
{
|
||||
if (!IsSitting) return;
|
||||
IsSitting = false;
|
||||
|
||||
SetHeight(_standingHeight);
|
||||
|
||||
if (_moveProvider != null) _moveProvider.enabled = true; // 이동 잠금 해제
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// 바닥 체크 및 Y축 속도 초기화
|
||||
|
||||
Reference in New Issue
Block a user