from github
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: abc1b0f06c98c604ca6ad6e205da3f7a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user