構えの処理を追加
This commit is contained in:
58
Assets/Scripts/VRInputPoseDetector.cs
Normal file
58
Assets/Scripts/VRInputPoseDetector.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class VRInputPoseDetector : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform headTransform;
|
||||
[SerializeField] private Transform rightHandTransform;
|
||||
[SerializeField] private Transform leftHandTransform;
|
||||
[SerializeField] private float minForwardDistance = 0.15f;
|
||||
[SerializeField] private float maxForwardDistance = 0.5f;
|
||||
[SerializeField] private float minHeightOffset = -0.35f;
|
||||
[SerializeField] private float maxHeightOffset = -0.1f;
|
||||
[SerializeField] private float requiredPoseTime = -0.3f;
|
||||
private float poseTimer = 0f;
|
||||
private bool isPoseMainTained = false;
|
||||
public bool IsPosing => isPoseMainTained;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(headTransform == null || rightHandTransform == null || leftHandTransform == null) return;
|
||||
|
||||
//両手の世界座標を頭を中心としたローカル座標に変換
|
||||
Vector3 localRightHand = headTransform.InverseTransformPoint(rightHandTransform.position);
|
||||
Vector3 localLeftHand = headTransform.InverseTransformPoint(leftHandTransform.position);
|
||||
|
||||
//両手が構え範囲に入っているかチェック
|
||||
bool isRightHandGuarding = CheckHandPosition(localRightHand);
|
||||
bool isLeftHandGuarding = CheckHandPosition(localLeftHand);
|
||||
|
||||
//両手が構え範囲にある場合のタイマー処理
|
||||
if(isRightHandGuarding && isLeftHandGuarding)
|
||||
{
|
||||
poseTimer += Time.deltaTime;
|
||||
if(poseTimer >= requiredPoseTime && !isPoseMainTained)
|
||||
{
|
||||
isPoseMainTained = true;
|
||||
Debug.Log("kamaeseikou");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
poseTimer = 0f;
|
||||
if(isPoseMainTained)
|
||||
{
|
||||
isPoseMainTained = false;
|
||||
Debug.Log("kamaesippai");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
private bool CheckHandPosition(Vector3 localHandPos)
|
||||
{
|
||||
bool inForwardRange = localHandPos.z >= minForwardDistance && localHandPos.z <= maxForwardDistance; //Z軸:頭より前に手があるか
|
||||
bool inHeightRange = localHandPos.y >= minHeightOffset && localHandPos.y <= maxHeightOffset; //Y軸:手の高さが適切か
|
||||
|
||||
return inForwardRange && inHeightRange;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/VRInputPoseDetector.cs.meta
Normal file
2
Assets/Scripts/VRInputPoseDetector.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba5d2c8447b183c40ad8183575ee0b8e
|
||||
@@ -10,6 +10,8 @@ public class VRInputPunch : MonoBehaviour
|
||||
|
||||
[SerializeField] private XRNode controllerNode = XRNode.RightHand;
|
||||
|
||||
[SerializeField] private VRInputPoseDetector poseDetector;
|
||||
|
||||
[SerializeField] private float minPunchSpeed = 2.0f; //パンチとして判定する最低速度 (m/s)
|
||||
|
||||
[SerializeField] private float damageMultiplier = 10.0f; //ダメージ倍率
|
||||
@@ -56,10 +58,18 @@ public class VRInputPunch : MonoBehaviour
|
||||
if (damageble != null)
|
||||
{
|
||||
DamageInfo info = new DamageInfo();
|
||||
info.amount = speed * damageMultiplier;
|
||||
if(poseDetector.IsPosing)
|
||||
{
|
||||
info.amount = (speed * damageMultiplier) * 2f;
|
||||
info.isPoseBonus = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
info.amount = speed * damageMultiplier;
|
||||
info.isPoseBonus = false;
|
||||
}
|
||||
info.hitPosition = other.transform.position;
|
||||
info.punchDirection = velocity.normalized; //パンチの進む向き
|
||||
info.isPoseBonus = false;
|
||||
damageble.TakeDamage(info);
|
||||
Debug.Log("パンチ成功 ダメージ: {damage:F1}");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user