fix(visuals): stop Aswid and Sverm eyes measuring their facing off the wrong transform

Both files built their eye holder's forward/up axes from headBone.root
- the top of whatever hierarchy the head bone (from
VisEquipment.m_bodyModel's own bone array) happens to sit in. That
does not reliably resolve back to the player, so the measurement came
out wrong on every single build rather than on an occasional
bad-timing one - which is why resetting the race or logging out never
fixed it for Aswid, only starting a fresh build at the same wrong
reference every time.

DvergarVisuals.BuildEyes already reads player.transform directly and
does not have this problem - its own eye glitches are the ordinary
bad-pose-timing kind the attach/attack/sleep guard mostly covers,
which is why relogging (a fresh, differently-timed build) usually
fixes it. AswidVisuals and SvermVisuals now do the same.

Also gives SvermVisuals.ApplyEyes the same attach/attack/sleep guard
Aswid and Dvergar already had before building fresh, which it was
missing entirely.
This commit is contained in:
kanym 2026-08-12 13:44:59 +02:00
commit 028c34be3c
2 changed files with 30 additions and 4 deletions

View file

@ -396,7 +396,15 @@ namespace RacesOfValheim
// Ask the rig which way it faces, once, and round the answer to the skull's own axes -
// see DvergarVisuals.BuildEyes for why the raw, unrounded measurement puts the eyes at
// the jaw instead of the eye line.
Transform root = headBone.root;
//
// player.transform, NOT headBone.root. headBone comes off VisEquipment.m_bodyModel's
// own bone array, and walking .root from there does not reliably land back on the
// player - the eyes came out wrong on every single build, not just an unlucky one, which
// is what a bad-timing read (the guard above already handles that) would look like.
// A CONSISTENTLY wrong answer means a consistently wrong reference, not a bad moment to
// ask it in. DvergarVisuals.BuildEyes already reads player.transform directly for
// exactly this reason; 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));

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));