Merge branch 'fix-eye-position-glitch' into main

This commit is contained in:
kanym 2026-08-12 16:29:01 +02:00
commit 7668a0a996
3 changed files with 156 additions and 29 deletions

View file

@ -192,7 +192,20 @@ namespace RacesOfValheim
return;
}
if (eyes == null) eyes = BuildEyes(headBone);
if (eyes == null)
{
// See AswidVisuals.ApplyEyes / DvergarVisuals.ApplyEyes for the full reasoning -
// BuildEyes takes a one-time reading of the head bone's pose to work out which way
// the skull faces, and caches it for as long as the eyes exist. Sitting, attached,
// mid-attack or asleep, the head can be turned away from the body's own forward at
// that instant, which is how the snap-to-axis has picked the wrong side and left
// eyes behind the skull before.
if (player.IsAttached() || player.IsAttachedToShip() || player.InAttack() || player.IsSleeping())
{
return;
}
eyes = BuildEyes(player, headBone);
}
if (eyes == null) return; // already logged once by the resolver
PlaceEyes(player, headBone, eyes);
@ -256,7 +269,7 @@ namespace RacesOfValheim
}
}
private static Transform BuildEyes(Transform headBone)
private static Transform BuildEyes(Player player, Transform headBone)
{
Shader glow = ResolveGlowShader();
if (glow == null) return null;
@ -270,7 +283,12 @@ namespace RacesOfValheim
// Ask the rig which way it faces, once, and ROUND the answer to the skull's own axes.
// The raw, unrounded measurement puts the eyes on the jaw - DvergarVisuals found that
// out first.
Transform root = headBone.root;
//
// player.transform, NOT headBone.root - walking .root up from a bone in
// VisEquipment.m_bodyModel's own array does not reliably land back on the player, and
// gave a wrong answer on every single build rather than an occasional bad-timing one.
// DvergarVisuals.BuildEyes already reads player.transform directly; this now matches it.
Transform root = player.transform;
EyeFrame frame = holder.AddComponent<EyeFrame>();
frame.LocalForward = SnapToAxis(headBone.InverseTransformDirection(root.forward));
frame.LocalUp = SnapToAxis(headBone.InverseTransformDirection(root.up));