Merge branch 'fix-interact-range-scale'
This commit is contained in:
commit
782d49e0eb
1 changed files with 34 additions and 0 deletions
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue