From 7c9c1ca63046ffb36773c8f5ffc888aac9bae934 Mon Sep 17 00:00:00 2001 From: kanym Date: Wed, 5 Aug 2026 20:59:01 +0200 Subject: [PATCH] fix(dvergar): square the skull's axes so the eyes sit on the eye line The trace showed the offsets arriving tilted: 0.109m of forward and 0.078m of up came out as 0.124 forward and 0.059 up, which is the jaw rather than the eyes. towardFace read 0.99, so the direction was never wrong - only leaning. The axes are measured from whatever pose the head is in on the frame the eyes are built, and a head pitched a few degrees hands back a forward that leans down and an up that leans back. A bone's real axes are square, so the measurement is now rounded to the nearest one. The tilt was the pose at the moment of asking and nothing else. --- JotunnModStub/Dvergar/DvergarVisuals.cs | 29 ++++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) 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++) {