I have a Unity network application that tracks my hands with the Vive Focus. I get the hands position of the rig with the following code:
if (hand.GetJoint(XRHandJointID.BeginMarker).TryGetPose(out Pose poseOut))
{
handPosition = poseOut.position;
handRotation = poseOut.rotation;
}
if (HandTracking.subsystem.leftHand.Equals(hand))
SendLeftHandPositionToServer(handPosition, handRotation);
else
SendRightHandPositionToServer(handPosition, handRotation);
poseOut is the global position of my hands relative to the center of the scene. I need this position to set my avatar's hand to show it to the other network users. I send "handPosition" to the server and set the avatar's hand like this:
[ServerRpc]
private void SendRightHandPositionToServer(Vector3 rightHandPosition, Quaternion rightHandRotation)
{
_avatarData.RootRightHand.position = rightHandPosition;
_avatarData.RootRightHand.rotation = rightHandRotation;
SendRightHandPositionToClient(rightHandPosition, rightHandRotation);
}
The problem is when my rig enters a moving object, like for example an elevator. I parent the rig to the moving object and my rig starts moving based on its behaviour. Because this movement is not registered by the rig, because I didn't move in real space, my avatar's hands stay in the starting point of the moving object. Is there a way to fix this problem?
If you need more context or code feel free to ask.
I found the solution! XROrigin was always (0, 0, 0) in the build because it "resets" as I move through the real world space. The moment I enter the moving platform, it tracks the movement of the moving object (that is, the movement I have not done in real world). So I only had to do this:
where rigOrigin is XROrigin.transform.position. Thanks for the help :)