51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using UnityEngine;
|
|
|
|
[System.Serializable]
|
|
public class VRMap
|
|
{
|
|
public Transform vrTarget;
|
|
public Transform ikTarget;
|
|
public Vector3 trackingPositionOffset;
|
|
public Vector3 trackingRotationOffset;
|
|
public bool pos = false;
|
|
public void Map()
|
|
{
|
|
if (pos)
|
|
ikTarget.position = vrTarget.TransformPoint(trackingPositionOffset);
|
|
ikTarget.rotation = vrTarget.rotation * Quaternion.Euler(trackingRotationOffset);
|
|
}
|
|
}
|
|
|
|
public class IKTargetFollowVRRig : MonoBehaviour
|
|
{
|
|
[Range(0,1)]
|
|
public float turnSmoothness = 0.1f;
|
|
public VRMap head;
|
|
public VRMap leftHand;
|
|
public VRMap rightHand;
|
|
|
|
public Vector3 headBodyPositionOffset;
|
|
public float headBodyYawOffset;
|
|
|
|
// Update is called once per frame
|
|
void LateUpdate()
|
|
{
|
|
// if(pos)
|
|
// transform.position = head.ikTarget.position + headBodyPositionOffset;
|
|
float yaw = head.vrTarget.eulerAngles.y;
|
|
Quaternion targetRotation = Quaternion.Euler(transform.eulerAngles.x, yaw, transform.eulerAngles.z);
|
|
|
|
// محاسبه اختلاف زاویه
|
|
float angleDifference = Quaternion.Angle(transform.rotation, targetRotation);
|
|
|
|
// اگر اختلاف زاویه بیشتر از 30 درجه بود، تغییر انجام شود
|
|
if (angleDifference > 30f)
|
|
{
|
|
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSmoothness);
|
|
}
|
|
head.Map();
|
|
// leftHand.Map();
|
|
// rightHand.Map();
|
|
}
|
|
}
|