fix(visuals): a taller player reaches as far as they are tall

Vanilla only takes a hover target within m_maxInteractDistance (5 m) of
the eye, and RaceEyeHeight raises the eye with the model. A True Form
Trol's eye stands about 4 m up, so a log at its feet was already out of
reach and Grab Log worked on one small spot under the camera. The range
now grows by the same ratio as the eye (10-12.5 m in True Form, the
Muspell by its own eye), and never drops below vanilla for smaller races.
This commit is contained in:
kanym 2026-09-30 13:57:51 +02:00
commit d502eda748

View file

@ -27,6 +27,8 @@ namespace RacesOfValheim
/// business. The Trenta's Muspell is the exception: it hands over its own eye height, see
/// TrentaMuspell.TryGetEyeHeight.
///
/// The interaction range follows the eye up, never down: see ApplyReach.
///
/// 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.
/// </summary>
@ -44,6 +46,10 @@ namespace RacesOfValheim
private class EyeRest : MonoBehaviour
{
public Vector3 LocalPosition;
/// <summary>Player.m_maxInteractDistance before any race touched it. Kept here for the
/// same reason the eye is: read back later it would already be scaled.</summary>
public float InteractDistance;
}
public static void Apply(Player player)
@ -65,6 +71,7 @@ namespace RacesOfValheim
{
rest = eye.gameObject.AddComponent<EyeRest>();
rest.LocalPosition = eye.localPosition;
rest.InteractDistance = player.m_maxInteractDistance;
}
Vector3 wanted;
@ -86,6 +93,33 @@ namespace RacesOfValheim
{
eye.localPosition = wanted;
}
ApplyReach(player, rest, wanted);
}
/// <summary>
/// Stretches the interaction range by as much as the eye was raised.
///
/// Vanilla takes a hover target only within m_maxInteractDistance (5 m) of the EYE, so
/// raising the eye cost reach: a True Form Trol's eye stands about 4 m up, the log at its
/// feet was already 4 m away, and there was one small spot under the camera where Grab Log
/// worked at all. The ratio is taken off the eye itself rather than the Visual, so the
/// Muspell - whose Visual is shrunk to nothing while its eye is raised - gets the reach of
/// the size it looks out from.
///
/// Never below vanilla: a Furling or a Dvergar is shorter, and losing reach for it would
/// make every chest and door fiddly for no gain.
/// </summary>
private static void ApplyReach(Player player, EyeRest rest, Vector3 wantedEye)
{
if (rest.InteractDistance <= 0f || rest.LocalPosition.y <= 0.0001f) return;
float ratio = Mathf.Max(1f, wantedEye.y / rest.LocalPosition.y);
float reach = rest.InteractDistance * ratio;
if (!Mathf.Approximately(player.m_maxInteractDistance, reach))
{
player.m_maxInteractDistance = reach;
}
}
/// <summary>