fix(trenta): the camera rises to the Muspell's head

The form hides the player's body by shrinking its Visual to 0.001, and
RaceEyeHeight reads anything that small as hidden and leaves the eye
where it was, at a person's height. The Muspell now measures its head
height when the clone is made and hands RaceEyeHeight that height times
the form's current scale, so the camera follows the grow and shrink.
This commit is contained in:
kanym 2026-09-30 12:55:15 +02:00
commit 7d88bc78d0
2 changed files with 52 additions and 5 deletions

View file

@ -24,7 +24,8 @@ namespace RacesOfValheim
/// their eye with them, and read as a factor of 1 here, so they are left alone by
/// construction. So is a player inside a borrowed form (wolf, drake, bat): those hide the
/// body's renderers and leave its scale at 1, and the form's own camera handling is its
/// business.
/// business. The Trenta's Muspell is the exception: it hands over its own eye height, see
/// TrentaMuspell.TryGetEyeHeight.
///
/// Applied to every player, not just the one at the keyboard. m_eye is also what a mob aims
/// at, so a Dvergar's head being where the Dvergar's head is matters on every client.
@ -66,10 +67,21 @@ namespace RacesOfValheim
rest.LocalPosition = eye.localPosition;
}
float scale = visual.transform.localScale.y;
if (scale < MinScale) return;
Vector3 wanted;
if (TrentaMuspell.TryGetEyeHeight(player, out float formEye))
{
// The one borrowed form that sets its own eye: the Muspell is too tall to look out
// of from a person's height. Asked before the hidden-body check below, because the
// Muspell is exactly what hides the body.
wanted = new Vector3(rest.LocalPosition.x, formEye, rest.LocalPosition.z);
}
else
{
float scale = visual.transform.localScale.y;
if (scale < MinScale) return;
wanted = rest.LocalPosition * scale;
}
Vector3 wanted = rest.LocalPosition * scale;
if ((eye.localPosition - wanted).sqrMagnitude > 0.000001f)
{
eye.localPosition = wanted;