47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[System.Serializable]
|
|
public class VRMap
|
|
{
|
|
public Transform vrTarget;
|
|
public Transform rigTarget;
|
|
public Vector3 trackingOffsetPosition;
|
|
public Vector3 trackingOffsetRotation;
|
|
|
|
public void Map()
|
|
{
|
|
rigTarget.position = vrTarget.TransformPoint(trackingOffsetPosition);
|
|
rigTarget.rotation = vrTarget.rotation * Quaternion.Euler(trackingOffsetRotation);
|
|
}
|
|
}
|
|
|
|
public class VRRig : MonoBehaviour
|
|
{
|
|
|
|
public VRMap head;
|
|
public VRMap leftHand;
|
|
public VRMap rightHand;
|
|
public int turnSmoothness;
|
|
|
|
public Transform headConstraint;
|
|
public Vector3 headBodyOffset;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
headBodyOffset = transform.position - headConstraint.position;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void FixedUpdate()
|
|
{
|
|
transform.position = headConstraint.position + headBodyOffset;
|
|
transform.forward = Vector3.Lerp(transform.forward, Vector3.ProjectOnPlane(headConstraint.up, Vector3.up).normalized, Time.deltaTime * turnSmoothness);
|
|
|
|
head.Map();
|
|
leftHand.Map();
|
|
rightHand.Map();
|
|
}
|
|
}
|