Merge branch 'fix-trenta-muspell-camera'
This commit is contained in:
commit
3a538bb942
2 changed files with 90 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
|
/// 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
|
/// 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
|
/// 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
|
/// 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.
|
/// 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;
|
rest.LocalPosition = eye.localPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
float scale = visual.transform.localScale.y;
|
Vector3 wanted;
|
||||||
if (scale < MinScale) return;
|
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)
|
if ((eye.localPosition - wanted).sqrMagnitude > 0.000001f)
|
||||||
{
|
{
|
||||||
eye.localPosition = wanted;
|
eye.localPosition = wanted;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,31 @@ namespace RacesOfValheim
|
||||||
private static GameObject currentTransformation;
|
private static GameObject currentTransformation;
|
||||||
private static bool isTransformingSequence;
|
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)
|
public static void Toggle(Player player)
|
||||||
{
|
{
|
||||||
if (isTransformingSequence) return;
|
if (isTransformingSequence) return;
|
||||||
|
|
@ -167,6 +192,14 @@ namespace RacesOfValheim
|
||||||
currentTransformation.transform.localPosition = Vector3.zero;
|
currentTransformation.transform.localPosition = Vector3.zero;
|
||||||
currentTransformation.transform.localRotation = Quaternion.identity;
|
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
|
// Same reasoning as FenrirRace.ExecuteTransformation: the clone must never carry
|
||||||
// whatever AI/gameplay component made the source a functioning boss.
|
// whatever AI/gameplay component made the source a functioning boss.
|
||||||
Component animEvent = currentTransformation.GetComponent("AnimEvent");
|
Component animEvent = currentTransformation.GetComponent("AnimEvent");
|
||||||
|
|
@ -219,6 +252,8 @@ namespace RacesOfValheim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MuspellFormBehavior : MonoBehaviour
|
public class MuspellFormBehavior : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public const string HeadPath = "Armature/root/spine1/spine2/spine3/head";
|
||||||
|
|
||||||
private Animator playerAnim;
|
private Animator playerAnim;
|
||||||
private Animator formAnim;
|
private Animator formAnim;
|
||||||
private Transform muzzle;
|
private Transform muzzle;
|
||||||
|
|
@ -232,7 +267,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
// The spike volley should leave from the Elder's own mouth, not the (now hidden)
|
// The spike volley should leave from the Elder's own mouth, not the (now hidden)
|
||||||
// player's eye point underneath it.
|
// player's eye point underneath it.
|
||||||
muzzle = transform.Find("Armature/root/spine1/spine2/spine3/head");
|
muzzle = transform.Find(HeadPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
|
|
@ -255,6 +290,8 @@ namespace RacesOfValheim
|
||||||
TrySet(() => formAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed")));
|
TrySet(() => formAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoopIdle();
|
||||||
|
|
||||||
if (!isGrounded || !RaceInput.Allowed) return;
|
if (!isGrounded || !RaceInput.Allowed) return;
|
||||||
|
|
||||||
if (RaceInput.AttackDown(0)) // Stomp
|
if (RaceInput.AttackDown(0)) // Stomp
|
||||||
|
|
@ -267,6 +304,42 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const string IdleClip = "Unarmed Idle";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Keeps the idle going. The Elder's "Unarmed Idle" clip is not a looping clip (dumpanim:
|
||||||
|
/// loop=False, 1.90s), so after the stand-up or any attack the form played it once and
|
||||||
|
/// froze on its last frame. The boss never showed it, being hardly ever idle; a player in
|
||||||
|
/// the form is idle most of the time. The clip's flag lives in the game's asset, so the
|
||||||
|
/// state is restarted from here instead, once it has run to its end.
|
||||||
|
///
|
||||||
|
/// The idle shares a locomotion blend tree with the four Swagger Walk clips, so the clip
|
||||||
|
/// list for the state holds all of them and the idle is not necessarily first: it is found
|
||||||
|
/// by name and must be carrying most of the weight, which is what "standing still" means.
|
||||||
|
/// Play and not CrossFade: Unity can ignore a cross-fade from a state into itself, and
|
||||||
|
/// the first version of this did exactly nothing for that reason.
|
||||||
|
/// </summary>
|
||||||
|
private void LoopIdle()
|
||||||
|
{
|
||||||
|
if (formAnim.IsInTransition(0)) return;
|
||||||
|
|
||||||
|
bool idle = false;
|
||||||
|
foreach (AnimatorClipInfo info in formAnim.GetCurrentAnimatorClipInfo(0))
|
||||||
|
{
|
||||||
|
if (info.clip != null && info.clip.name == IdleClip && info.weight >= 0.5f)
|
||||||
|
{
|
||||||
|
idle = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!idle) return;
|
||||||
|
|
||||||
|
AnimatorStateInfo state = formAnim.GetCurrentAnimatorStateInfo(0);
|
||||||
|
if (state.normalizedTime < 1f) return;
|
||||||
|
|
||||||
|
formAnim.Play(state.fullPathHash, 0, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
private static void TrySet(System.Action set)
|
private static void TrySet(System.Action set)
|
||||||
{
|
{
|
||||||
try { set(); } catch { }
|
try { set(); } catch { }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue