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:
parent
5027d2d84f
commit
7d88bc78d0
2 changed files with 52 additions and 5 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,31 @@ namespace RacesOfValheim
|
|||
private static GameObject currentTransformation;
|
||||
private static bool isTransformingSequence;
|
||||
|
||||
/// <summary>
|
||||
/// How high the form's head sits above the player's feet at a form scale of 1, measured
|
||||
/// off the clone the moment it is made. Multiplied by the form's current scale it gives the
|
||||
/// eye height, so the camera rides the grow and shrink tween with the model.
|
||||
/// </summary>
|
||||
private static float headHeightAtScaleOne;
|
||||
|
||||
/// <summary>
|
||||
/// The eye height the Muspell wants for <paramref name="player"/>, for RaceEyeHeight.
|
||||
///
|
||||
/// The form hides the player's own body by shrinking its Visual to 0.001, and RaceEyeHeight
|
||||
/// reads anything that small as "hidden" and leaves the eye alone - so the camera stayed at
|
||||
/// a person's eye level inside something the size of a house. The form is local only, so
|
||||
/// this only ever answers for the local player.
|
||||
/// </summary>
|
||||
public static bool TryGetEyeHeight(Player player, out float height)
|
||||
{
|
||||
height = 0f;
|
||||
if (!IsTransformed || currentTransformation == null || headHeightAtScaleOne <= 0f) return false;
|
||||
if (player == null || player != Player.m_localPlayer) return false;
|
||||
|
||||
height = headHeightAtScaleOne * currentTransformation.transform.localScale.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Toggle(Player player)
|
||||
{
|
||||
if (isTransformingSequence) return;
|
||||
|
|
@ -167,6 +192,14 @@ namespace RacesOfValheim
|
|||
currentTransformation.transform.localPosition = Vector3.zero;
|
||||
currentTransformation.transform.localRotation = Quaternion.identity;
|
||||
|
||||
// Measured here, straight off the clone, before the grow tween touches its scale. The
|
||||
// head is the same bone the spike volley fires from.
|
||||
Transform head = currentTransformation.transform.Find(MuspellFormBehavior.HeadPath);
|
||||
float cloneScale = currentTransformation.transform.localScale.y;
|
||||
headHeightAtScaleOne = head != null && cloneScale > 0f
|
||||
? (head.position.y - player.transform.position.y) / cloneScale
|
||||
: 0f;
|
||||
|
||||
// Same reasoning as FenrirRace.ExecuteTransformation: the clone must never carry
|
||||
// whatever AI/gameplay component made the source a functioning boss.
|
||||
Component animEvent = currentTransformation.GetComponent("AnimEvent");
|
||||
|
|
@ -219,6 +252,8 @@ namespace RacesOfValheim
|
|||
/// </summary>
|
||||
public class MuspellFormBehavior : MonoBehaviour
|
||||
{
|
||||
public const string HeadPath = "Armature/root/spine1/spine2/spine3/head";
|
||||
|
||||
private Animator playerAnim;
|
||||
private Animator formAnim;
|
||||
private Transform muzzle;
|
||||
|
|
@ -232,7 +267,7 @@ namespace RacesOfValheim
|
|||
|
||||
// The spike volley should leave from the Elder's own mouth, not the (now hidden)
|
||||
// player's eye point underneath it.
|
||||
muzzle = transform.Find("Armature/root/spine1/spine2/spine3/head");
|
||||
muzzle = transform.Find(HeadPath);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue