2026-06-18 많은 플레이어 수정사항
This commit is contained in:
42
Assets/02_Scripts/Rhythm/RhythmDrumPad.cs
Normal file
42
Assets/02_Scripts/Rhythm/RhythmDrumPad.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
|
||||
// 스네어 위치의 "트리거 콜라이더"에 붙인다.
|
||||
// VR 스틱 끝(RhythmStickTip)이 이 트리거에 들어오면 RhythmManager.OnPlayerInput()을 호출한다.
|
||||
// → 키보드 입력과 완전히 동일한 진입점이라 판정/효과음/노트 소비는 RhythmManager가 그대로 처리한다.
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class RhythmDrumPad : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private RhythmManager _manager;
|
||||
|
||||
[Tooltip("이 속력(m/s) 미만으로 닿으면 무시. 스틱이 패드에 얹히거나 미세하게 떨릴 때 오발 방지. 0이면 비활성")]
|
||||
[SerializeField] private float _minHitSpeed = 0.5f;
|
||||
|
||||
[Tooltip("한 번 타격 후 이 시간(초) 동안 재타격 무시. 트리거 체류·경계 떨림으로 인한 중복 입력 방지")]
|
||||
[SerializeField] private float _hitCooldown = 0.1f;
|
||||
|
||||
private float _lastHitTime = float.NegativeInfinity;
|
||||
|
||||
// 인스펙터에서 콜라이더를 트리거로 바꾸는 걸 깜빡하기 쉬워, 컴포넌트 추가 시 자동으로 켜 준다.
|
||||
private void Reset()
|
||||
{
|
||||
GetComponent<Collider>().isTrigger = true;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (_manager == null) return;
|
||||
|
||||
// 닿은 게 스틱 끝인지 식별 (콜라이더가 자식이어도 부모 쪽까지 탐색)
|
||||
RhythmStickTip tip = other.GetComponentInParent<RhythmStickTip>();
|
||||
if (tip == null) return;
|
||||
|
||||
// 너무 약한 접촉(얹힘/떨림)은 무시
|
||||
if (_minHitSpeed > 0f && tip.Speed < _minHitSpeed) return;
|
||||
|
||||
// 짧은 시간 내 중복 타격 무시
|
||||
if (Time.time - _lastHitTime < _hitCooldown) return;
|
||||
_lastHitTime = Time.time;
|
||||
|
||||
_manager.OnPlayerInput(); // 키 입력과 동일 경로 → 가장 가까운 노트 판정
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Rhythm/RhythmDrumPad.cs.meta
Normal file
2
Assets/02_Scripts/Rhythm/RhythmDrumPad.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6b6ae15947930d41b86403ced8cea59
|
||||
26
Assets/02_Scripts/Rhythm/RhythmStickTip.cs
Normal file
26
Assets/02_Scripts/Rhythm/RhythmStickTip.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
// VR 스틱 끝에 붙이는 마커 + 속도 추적기.
|
||||
// 드럼 패드(RhythmDrumPad)가 "닿은 게 스틱인지" 이 컴포넌트로 식별하고,
|
||||
// 타격 속력을 읽어 패드에 살짝 얹히거나 떨리는 약한 접촉을 무시할 수 있게 한다.
|
||||
[DisallowMultipleComponent]
|
||||
public class RhythmStickTip : MonoBehaviour
|
||||
{
|
||||
public float Speed { get; private set; } // 월드 기준 이동 속력(m/s)
|
||||
|
||||
private Vector3 _lastPos;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_lastPos = transform.position; // 활성화 직후 첫 프레임 속력 튐 방지
|
||||
Speed = 0f;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Vector3 pos = transform.position;
|
||||
if (Time.deltaTime > 0f)
|
||||
Speed = (pos - _lastPos).magnitude / Time.deltaTime;
|
||||
_lastPos = pos;
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Rhythm/RhythmStickTip.cs.meta
Normal file
2
Assets/02_Scripts/Rhythm/RhythmStickTip.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73ace7cbbacfff1498caf66704871f48
|
||||
Reference in New Issue
Block a user