fix(fenrir): enter the Ulv's Sleep state by hand when the player sits
A vanilla Ulv is born asleep: its controller only knows the way out of Sleep, so setting the bool from Idle did nothing. The state is now cross-faded into when the player sits; standing drops the bool and the controller's own 'Sleep to Idle' plays. The log names the state found.
This commit is contained in:
parent
9cf3f5386c
commit
fb354c2387
1 changed files with 32 additions and 2 deletions
|
|
@ -48,6 +48,9 @@ namespace RacesOfValheim
|
|||
// drives the creature's own sleep through it, and not every creature has one.
|
||||
private Animator sleepChecked;
|
||||
private bool hasSleeping;
|
||||
private int sleepState;
|
||||
private bool wasSitting;
|
||||
private static readonly string[] SleepStateNames = { "Sleep", "sleep", "Sleeping", "sleeping" };
|
||||
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>
|
||||
|
|
@ -87,14 +90,41 @@ namespace RacesOfValheim
|
|||
{
|
||||
if (p.type == AnimatorControllerParameterType.Bool && p.name == "sleeping") { hasSleeping = true; break; }
|
||||
}
|
||||
|
||||
// The state's name is not readable at runtime, only testable: the clip is 'Sleep', and
|
||||
// the state is most likely named after it.
|
||||
sleepState = 0;
|
||||
string found = "none";
|
||||
if (hasSleeping)
|
||||
{
|
||||
foreach (string candidate in SleepStateNames)
|
||||
{
|
||||
int hash = Animator.StringToHash(candidate);
|
||||
if (!form.HasState(0, hash)) continue;
|
||||
sleepState = hash;
|
||||
found = candidate;
|
||||
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."));
|
||||
(hasSleeping ? $"sitting puts it to sleep (state '{found}')." : "sitting keeps it idle."));
|
||||
}
|
||||
}
|
||||
if (hasSleeping) form.SetBool("sleeping", sitting);
|
||||
if (hasSleeping)
|
||||
{
|
||||
form.SetBool("sleeping", sitting);
|
||||
|
||||
// The bool alone never put the Ulv to sleep. A vanilla Ulv is BORN asleep: its
|
||||
// controller enters Sleep from the start and only knows the way out (Sleep, then
|
||||
// 'Sleep to Idle' once the bool drops). Nothing leads from Idle back into Sleep, so
|
||||
// the state is entered by hand when the player sits; standing up drops the bool and
|
||||
// the controller's own wake-up plays.
|
||||
if (sitting && !wasSitting && sleepState != 0) form.CrossFadeInFixedTime(sleepState, 0.4f, 0);
|
||||
}
|
||||
wasSitting = sitting;
|
||||
|
||||
return grounded;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue