feat(fenrir): forms sneak at a walk and sleep when the player sits
FormLocomotion zeroed the speed whenever the player crouched, so a sneaking form slid across the ground in its idle pose. Only airborne reads as still now: crouched, the player moves at sneaking speed and the creature's controller picks its walk. Sitting sets the "sleeping" bool the creature's own MonsterAI uses, when its controller has one; the log says once per controller which do. IsSitting reads the replicated animator state, so onlookers' copies sleep too. Covers every Fenrir form, local and remote, and the True Form troll, which share FormLocomotion. Mirror now takes the Player. Requested by a player on Discord.
This commit is contained in:
parent
8843e773b1
commit
580ef6d468
3 changed files with 43 additions and 15 deletions
|
|
@ -422,7 +422,7 @@ namespace RacesOfValheim
|
|||
// The same helper the local behaviours use, so both views of the same wolf agree.
|
||||
// Player.IsCrouching answers off the animator's current state, which is replicated, so
|
||||
// it is true here too.
|
||||
locomotion.Mirror(formAnim, playerAnim, player.IsCrouching());
|
||||
locomotion.Mirror(formAnim, playerAnim, player);
|
||||
}
|
||||
|
||||
// Written every frame while the flag is set, and only when the controller has the bool: a
|
||||
|
|
@ -539,7 +539,7 @@ namespace RacesOfValheim
|
|||
// Meglio continuare a sincronizzare i movimenti base.
|
||||
if (!isAttacking)
|
||||
{
|
||||
bool isGrounded = locomotion.Mirror(fenrirAnim, playerAnim, Player.m_localPlayer.IsCrouching());
|
||||
bool isGrounded = locomotion.Mirror(fenrirAnim, playerAnim, Player.m_localPlayer);
|
||||
|
||||
if (isGrounded && RaceInput.Allowed)
|
||||
{
|
||||
|
|
@ -790,7 +790,7 @@ namespace RacesOfValheim
|
|||
if (!isAttacking)
|
||||
{
|
||||
// Se tiene premuto Ctrl (Crouch), ferma il movimento per preparare l'attacco
|
||||
bool isGrounded = locomotion.Mirror(cultistAnim, playerAnim, Player.m_localPlayer.IsCrouching());
|
||||
bool isGrounded = locomotion.Mirror(cultistAnim, playerAnim, Player.m_localPlayer);
|
||||
|
||||
if (isGrounded)
|
||||
{
|
||||
|
|
@ -1172,7 +1172,7 @@ namespace RacesOfValheim
|
|||
|
||||
if (!isAttacking)
|
||||
{
|
||||
bool isGrounded = locomotion.Mirror(wolfAnim, playerAnim, Player.m_localPlayer.IsCrouching());
|
||||
bool isGrounded = locomotion.Mirror(wolfAnim, playerAnim, Player.m_localPlayer);
|
||||
|
||||
if (isGrounded && RaceInput.Allowed)
|
||||
{
|
||||
|
|
@ -1384,7 +1384,7 @@ namespace RacesOfValheim
|
|||
|
||||
if (!isAttacking)
|
||||
{
|
||||
bool isGrounded = locomotion.Mirror(ulvAnim, playerAnim, Player.m_localPlayer.IsCrouching());
|
||||
bool isGrounded = locomotion.Mirror(ulvAnim, playerAnim, Player.m_localPlayer);
|
||||
|
||||
if (isGrounded && RaceInput.Allowed)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,22 +40,50 @@ namespace RacesOfValheim
|
|||
|
||||
private float airborneFor;
|
||||
|
||||
// Whether this form's controller has a "sleeping" bool, asked once per Animator: MonsterAI
|
||||
// drives the creature's own sleep through it, and not every creature has one.
|
||||
private Animator sleepChecked;
|
||||
private bool hasSleeping;
|
||||
private static readonly System.Collections.Generic.HashSet<string> sleepLogged = new System.Collections.Generic.HashSet<string>();
|
||||
|
||||
/// <summary>Copies the movement parameters, and says whether the form counts as grounded.</summary>
|
||||
public bool Mirror(Animator form, Animator player, bool crouching)
|
||||
public bool Mirror(Animator form, Animator playerAnim, Player player)
|
||||
{
|
||||
bool touching = player.GetBool("onGround");
|
||||
bool touching = playerAnim.GetBool("onGround");
|
||||
airborneFor = touching ? 0f : airborneFor + Time.deltaTime;
|
||||
bool grounded = airborneFor <= AirborneGrace;
|
||||
|
||||
// try/catch as the behaviours always did it: a controller missing one of these must not
|
||||
// throw once per frame.
|
||||
try { form.SetBool("onGround", grounded); } catch {}
|
||||
try { form.SetBool("inWater", player.GetBool("inWater")); } catch {}
|
||||
try { form.SetBool("inWater", playerAnim.GetBool("inWater")); } catch {}
|
||||
|
||||
// Airborne and crouching both read as standing still, as before.
|
||||
bool still = !grounded || crouching;
|
||||
try { form.SetFloat("forward_speed", still ? 0f : player.GetFloat("forward_speed")); } catch {}
|
||||
try { form.SetFloat("sideway_speed", still ? 0f : player.GetFloat("sideway_speed")); } catch {}
|
||||
// Only airborne reads as standing still now. Crouching used to as well, so a player
|
||||
// sneaking in a form slid across the ground in the idle pose. Crouched, the player moves
|
||||
// at sneaking speed, and the creature's controller picks its walk for a speed that low:
|
||||
// the sneak a player asked for, from animations the creature already has.
|
||||
try { form.SetFloat("forward_speed", grounded ? playerAnim.GetFloat("forward_speed") : 0f); } catch {}
|
||||
try { form.SetFloat("sideway_speed", grounded ? playerAnim.GetFloat("sideway_speed") : 0f); } catch {}
|
||||
|
||||
// Sitting puts the creature to sleep, on the "sleeping" bool its own MonsterAI uses - the
|
||||
// Ulv curls up. IsSitting reads the animator's state, which is replicated, so it is right
|
||||
// for an onlooker's copy too.
|
||||
if (sleepChecked != form)
|
||||
{
|
||||
sleepChecked = form;
|
||||
hasSleeping = false;
|
||||
foreach (AnimatorControllerParameter p in form.parameters)
|
||||
{
|
||||
if (p.type == AnimatorControllerParameterType.Bool && p.name == "sleeping") { hasSleeping = true; break; }
|
||||
}
|
||||
string controller = form.runtimeAnimatorController != null ? form.runtimeAnimatorController.name : form.name;
|
||||
if (sleepLogged.Add(controller))
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"[FenrirForm] '{controller}' {(hasSleeping ? "has" : "has no")} sleeping animation; " +
|
||||
(hasSleeping ? "sitting puts it to sleep." : "sitting keeps it idle."));
|
||||
}
|
||||
}
|
||||
if (hasSleeping) form.SetBool("sleeping", player != null && player.IsSitting());
|
||||
|
||||
return grounded;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace RacesOfValheim
|
|||
|
||||
if (isAttacking || player.IsDead()) return;
|
||||
|
||||
bool grounded = locomotion.Mirror(anim, playerAnim, player.IsCrouching());
|
||||
bool grounded = locomotion.Mirror(anim, playerAnim, player);
|
||||
if (!grounded || !RaceInput.Allowed) return;
|
||||
|
||||
bool log = heldLogName != null;
|
||||
|
|
@ -437,7 +437,7 @@ namespace RacesOfValheim
|
|||
TrolTrueFormModel.UpdateHeldLog(gameObject, rightPrefab, ref heldLog, ref heldLogName);
|
||||
|
||||
ReplayAttack();
|
||||
locomotion.Mirror(anim, playerAnim, player.IsCrouching());
|
||||
locomotion.Mirror(anim, playerAnim, player);
|
||||
}
|
||||
|
||||
private void ReplayAttack()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue