Race body scale moved the model and not the camera: Character.m_eye hangs off the unscaled root, so a Trol or a Dvergar changed height for everyone but themselves. RaceEyeHeight moves the eye by whatever scale the Visual is wearing, for every player, so aim rays follow too. Remote copies of a Fenrir form had no one writing to their Animator and stood in the controller's default state, sliding. RemoteFenrirAnimator mirrors the four local behaviours off the player's own replicated animator, the way RemoteSkadiAnimator already did for Skadi. Player.Food.m_time is time remaining, not time elapsed: the Aswid, Trenta and Draugh repeat-meal branches all set it to 0 and expired the slot they meant to renew, and left the nutrition values stale. RaceFoodRefresh does what vanilla's own branch does, in one place instead of three. The Trenta prefix now reports __result, or a working refresh would have renewed the slot without consuming the seed. Aswid devour was gated by one timestamp shared by every corpse, so a pack killed at once fed the player once; it is now per corpse, floored at a second, and a refused meal says $msg_nomore. MonsterAI.UpdateTarget discards any target IsEnemy refuses, so a truced mob could not retaliate at all - it stood still or fled. RaceGrudge records the hit on the AI owner's client and both truce postfixes stand down for that pair. The Aswid drain and the Skadi frost aura now skip kin, as the Skeleton's fire aura already did, or an always-on aura would hold every truce permanently broken. Faction sets matched exact prefab names with families half-listed: added Skeleton_NoArcher and Draugr_Ranged to the Swamp, Greyling to the Black Forest. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
93 lines
4.2 KiB
C#
93 lines
4.2 KiB
C#
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// Puts the camera at the height of the body the player is actually wearing.
|
|
///
|
|
/// Every race that resizes a player does it on the "Visual" child and never on the root: the
|
|
/// root carries the collider and the camera pivot, and scaling that drops the player through
|
|
/// the ground they are standing on. The cost of that - which is what testers reported - is
|
|
/// that Character.m_eye hangs off the same unscaled root. GameCamera.GetCameraBaseOffset takes
|
|
/// the camera from m_eye.position minus the root's, and aim raycasts start there too, so a
|
|
/// Trol grew a head taller for everyone else while still seeing the world from human eye
|
|
/// level, and a Dvergar shrank without ever having to look up at anything. The height was
|
|
/// real, and only the other players could see it.
|
|
///
|
|
/// The eye is moved by whatever factor the Visual is wearing at that instant, rather than by a
|
|
/// per-race number: that way it follows the Trol's transformation lerp for free, costs nothing
|
|
/// for a race that is not sizing anybody (the factor is 1), and returns to the measured
|
|
/// original the moment a player stops being of that race.
|
|
///
|
|
/// Races that scale the player root instead - the Skeleton is the one - are already carrying
|
|
/// 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.
|
|
///
|
|
/// 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>
|
|
public static class RaceEyeHeight
|
|
{
|
|
// Below this the body is not small, it is being hidden - an old scale-to-zero trick, or a
|
|
// transformation caught mid-lerp. Dividing the player's viewpoint down with it would put
|
|
// the camera inside the ground, so the eye is left where it last was.
|
|
private const float MinScale = 0.05f;
|
|
|
|
/// <summary>
|
|
/// Remembers where the eye sat before any race touched it, on the eye itself, so it dies
|
|
/// with the player object and can never be read back as an already-scaled value.
|
|
/// </summary>
|
|
private class EyeRest : MonoBehaviour
|
|
{
|
|
public Vector3 LocalPosition;
|
|
}
|
|
|
|
public static void Apply(Player player)
|
|
{
|
|
if (player == null) return;
|
|
|
|
Transform eye = Traverse.Create(player).Field("m_eye").GetValue<Transform>();
|
|
if (eye == null) return;
|
|
|
|
GameObject visual = Traverse.Create(player).Field("m_visual").GetValue<GameObject>();
|
|
if (visual == null) return;
|
|
|
|
// If this build ever parents the eye inside the rig, the body scale already carries
|
|
// it and doing the same thing here would apply it twice.
|
|
if (eye.IsChildOf(visual.transform)) return;
|
|
|
|
EyeRest rest = eye.GetComponent<EyeRest>();
|
|
if (rest == null)
|
|
{
|
|
rest = eye.gameObject.AddComponent<EyeRest>();
|
|
rest.LocalPosition = eye.localPosition;
|
|
}
|
|
|
|
float scale = visual.transform.localScale.y;
|
|
if (scale < MinScale) return;
|
|
|
|
Vector3 wanted = rest.LocalPosition * scale;
|
|
if ((eye.localPosition - wanted).sqrMagnitude > 0.000001f)
|
|
{
|
|
eye.localPosition = wanted;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Driven from Player.Update, the same place the scales themselves are applied from. The
|
|
/// order the postfixes run in does not matter: this reads whatever scale is on the Visual
|
|
/// now, so the worst a late scale can cost is one frame.
|
|
/// </summary>
|
|
[HarmonyPatch(typeof(Player), "Update")]
|
|
public static class Player_Update_EyeHeight_Patch
|
|
{
|
|
public static void Postfix(Player __instance)
|
|
{
|
|
Apply(__instance);
|
|
}
|
|
}
|
|
}
|
|
}
|