diff --git a/JotunnModStub/Dvergar/DvergarVisuals.cs b/JotunnModStub/Dvergar/DvergarVisuals.cs
index 5357b6a..393a23d 100644
--- a/JotunnModStub/Dvergar/DvergarVisuals.cs
+++ b/JotunnModStub/Dvergar/DvergarVisuals.cs
@@ -318,6 +318,21 @@ namespace RacesOfValheim
}
}
+ ///
+ /// Rounds a direction to the nearest of the six axis directions. Whichever component is
+ /// largest wins, sign included.
+ ///
+ private static Vector3 SnapToAxis(Vector3 direction)
+ {
+ float x = Mathf.Abs(direction.x);
+ float y = Mathf.Abs(direction.y);
+ float z = Mathf.Abs(direction.z);
+
+ if (x >= y && x >= z) return new Vector3(Mathf.Sign(direction.x), 0f, 0f);
+ if (y >= z) return new Vector3(0f, Mathf.Sign(direction.y), 0f);
+ return new Vector3(0f, 0f, Mathf.Sign(direction.z));
+ }
+
private static Transform BuildEyes(Player player, Transform headBone)
{
Shader glow = ResolveGlowShader();
@@ -332,14 +347,16 @@ namespace RacesOfValheim
holder.transform.localRotation = Quaternion.identity;
holder.transform.localScale = Vector3.one;
- // The one moment worth asking the rig which way it faces: now, before an animation has
- // had a chance to turn the head away from the body. From here on the answer is kept
- // and the skull carries it around.
+ // Ask the rig which way it faces, once - and then round the answer to the skull's own
+ // axes. The raw measurement is taken at whatever pose the head happens to be in on
+ // this frame, so it arrives tilted: a "forward" leaning 20 degrees down put the eyes
+ // at the jaw instead of the eye line. A bone's real axes are square, and the tilt is
+ // nothing but the pose at the moment of asking, so it is rounded away.
Transform root = player.transform;
EyeFrame frame = holder.AddComponent();
- frame.LocalForward = headBone.InverseTransformDirection(root.forward).normalized;
- frame.LocalUp = headBone.InverseTransformDirection(root.up).normalized;
- frame.LocalRight = headBone.InverseTransformDirection(root.right).normalized;
+ frame.LocalForward = SnapToAxis(headBone.InverseTransformDirection(root.forward));
+ frame.LocalUp = SnapToAxis(headBone.InverseTransformDirection(root.up));
+ frame.LocalRight = SnapToAxis(headBone.InverseTransformDirection(root.right));
for (int i = 0; i < 2; i++)
{