46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
//this scripts provides movement functions for the player avatar
|
|
|
|
[System.Serializable]
|
|
public class MapTransform
|
|
{
|
|
public Transform vrTarget;
|
|
public Transform IKTarget;
|
|
public Vector3 trackingPositionOffset;
|
|
public Vector3 trackingRotationOffset;
|
|
|
|
public void MapVRAvatar()
|
|
{
|
|
//map position and rotation of inverse kinematics target
|
|
IKTarget.position = vrTarget.TransformPoint(trackingPositionOffset);
|
|
IKTarget.rotation = vrTarget.rotation * Quaternion.Euler(trackingRotationOffset);
|
|
}
|
|
}
|
|
|
|
public class AvatarController : NetworkBehaviour
|
|
{
|
|
[SerializeField] private MapTransform head;
|
|
[SerializeField] private MapTransform leftHand;
|
|
[SerializeField] private MapTransform rightHand;
|
|
|
|
[SerializeField] private float turnSmoothness;
|
|
|
|
[SerializeField] private Transform IKHead;
|
|
|
|
[SerializeField] private Vector3 headBodyOffset;
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (IsOwner)
|
|
{
|
|
//map position and rotation of VR-Target to the avatar
|
|
transform.position = IKHead.position + headBodyOffset;
|
|
transform.forward = Vector3.Lerp(transform.forward, Vector3.ProjectOnPlane(IKHead.forward, Vector3.up).normalized, Time.deltaTime * turnSmoothness); ;
|
|
head.MapVRAvatar();
|
|
leftHand.MapVRAvatar();
|
|
rightHand.MapVRAvatar();
|
|
}
|
|
}
|
|
} |