Skip to content

Commit 1573dde

Browse files
committed
Improve head rotation handling
1 parent 8462d23 commit 1573dde

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Source/CustomAvatar/Tracking/HumanoidCalibrator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ internal void CalibrateAutomatically()
8383
Vector3 leftFootPos = center.InverseTransformPoint(_trackingRig.leftFoot.transform.position);
8484
Vector3 rightFootPos = center.InverseTransformPoint(_trackingRig.rightFoot.transform.position);
8585

86-
ApplyCalibration(center, _trackingRig.head, _trackingRig.headCalibration, new Vector3(0, playerEyeHeight, 0), Quaternion.Inverse(center.rotation) * _trackingRig.head.transform.rotation);
86+
ApplyCalibration(center, _trackingRig.head, _trackingRig.headCalibration, new Vector3(0, playerEyeHeight, 0), Quaternion.identity);
8787
ApplyCalibration(center, _trackingRig.pelvis, _trackingRig.pelvisCalibration, new Vector3(0, playerEyeHeight * kEyeHeightToPelvisHeightRatio, 0), Quaternion.identity);
8888
ApplyCalibration(center, _trackingRig.leftFoot, _trackingRig.leftFootCalibration, new Vector3(leftFootPos.x, 0, 0), Quaternion.Euler(0, -10f, 0));
8989
ApplyCalibration(center, _trackingRig.rightFoot, _trackingRig.rightFootCalibration, new Vector3(rightFootPos.x, 0, 0), Quaternion.Euler(0, 10f, 0));
@@ -179,10 +179,15 @@ private Transform CreateCenter(Transform parent)
179179
Transform center = new GameObject("Center").transform;
180180
Transform head = _trackingRig.head.transform;
181181

182+
// We want the user's head rotation to match the avatar's head directly rather than assuming whatever
183+
// position they're in is forward. I'm not sure how I feel about doing that, but it's what VRChat does.
184+
var rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(head.forward, parent.up), parent.up);
185+
head.rotation = rotation;
186+
182187
center.SetParent(parent, false);
183188
center.SetPositionAndRotation(
184189
head.TransformPoint(new Vector3(0, 0, -kEyeToHeadPivotOffset)),
185-
Quaternion.LookRotation(Vector3.ProjectOnPlane(head.forward, parent.up), parent.up));
190+
rotation);
186191

187192
// put center on the ground
188193
center.localPosition = new Vector3(center.localPosition.x, 0, center.localPosition.z);

0 commit comments

Comments
 (0)