chore(dvergar): trace where the eyes actually are, not where they should be

The arithmetic puts them 7cm from the head bone and the screen puts them metres away, so the offsets are not the thing to keep adjusting. Traces position, parent, local and world transforms and the distance from the head, six times over the first few seconds - enough to tell a bad offset from an object that is not parented, or one that is parented and then moved.
This commit is contained in:
kanym 2026-08-05 20:43:24 +02:00
commit 7651a07279

View file

@ -251,27 +251,40 @@ namespace RacesOfValheim
eye.localScale = Vector3.one * eyeLocalSize;
}
LogEyePlacementOnce(player, headBone, localEye, localForward, lossy, raceScale);
LogEyeTrace(player, headBone, holder, lossy, raceScale);
}
private static bool loggedEyePlacement;
// Traced repeatedly rather than once. The arithmetic says these eyes land 7cm from the
// head bone, and the screen says they are metres away - so the useful question is no
// longer what the offsets are, but whether the objects are where they were put and whether
// they stay there. Position, parent and distance, several times over the first few
// seconds, answers both.
private static int eyeTraceCount;
private static float nextEyeTrace;
private static void LogEyePlacementOnce(Player player, Transform headBone, Vector3 localEye, Vector3 localForward, float lossy, float raceScale)
private static void LogEyeTrace(Player player, Transform headBone, Transform holder, float lossy, float raceScale)
{
if (loggedEyePlacement) return;
loggedEyePlacement = true;
if (eyeTraceCount >= 6 || Time.time < nextEyeTrace) return;
eyeTraceCount++;
nextEyeTrace = Time.time + 2f;
Transform eye = holder.childCount > 0 ? holder.GetChild(0) : null;
Jotunn.Logger.LogInfo(
$"[Dvergar] Eyes on bone '{headBone.name}' at {headBone.position}: lossyScale={lossy:F2} " +
$"raceScale={raceScale:F2} localEyePoint={localEye} localForward={localForward}");
// The two candidates side by side. If these are different transforms, that difference
// is the whole story of why the eyes ignored the head animation.
Animator animator = player.GetComponentInChildren<Animator>();
Transform avatarHead = animator != null ? animator.GetBoneTransform(HumanBodyBones.Head) : null;
$"[Dvergar] trace {eyeTraceCount}: player={player.transform.position} head={headBone.position} " +
$"lossy={lossy:F2} race={raceScale:F2}");
Jotunn.Logger.LogInfo(
$"[Dvergar] avatar head: {(avatarHead != null ? $"'{avatarHead.name}' at {avatarHead.position}" : "none")}" +
$" | same transform = {avatarHead == headBone}");
$"[Dvergar] holder parent='{(holder.parent != null ? holder.parent.name : "none")}' " +
$"localPos={holder.localPosition} localScale={holder.localScale} world={holder.position}");
if (eye != null)
{
Jotunn.Logger.LogInfo(
$"[Dvergar] eye parent='{(eye.parent != null ? eye.parent.name : "none")}' " +
$"localPos={eye.localPosition} localScale={eye.localScale} world={eye.position} " +
$"distFromHead={Vector3.Distance(eye.position, headBone.position):F3}m " +
$"worldSize={eye.lossyScale.x:F3}m");
}
}
private static Transform BuildEyes(Player player, Transform headBone)