feat(skadi): rework dragon flight - longer stasis, stamina sprint, reverse thrust, water take-off

The hover window that holds a form level after you stop powering goes from 2
seconds to 5, so gliding is a choice rather than something that happens to you
the moment you let go.

Shift while holding W spends 15 stamina a second for 22 m/s instead of 12. It is
the only part of flight that costs anything - base flight stays free, because the
drake arrives at The Elder, long before a player has the pool to pay for simply
staying airborne - and running dry drops you back to the free boost rather than
out of the sky.

S beats backwards along the aim, pitch included: look down and press it and you
rise away from what you are watching. Reverse thrust alone would have spun the
dragon round to fly nose-first away from the camera, putting its tail where its
breath comes out, so the form claims AlwaysRotateCamera for exactly those frames
and keeps facing what it is retreating from.

Water is no longer a trap. Character.UpdateMotion asks IsSwimming before it ever
looks at m_flying, so a dragon that touched the sea was handed to UpdateSwimming
every frame: the flight patch never ran and there was no way back up short of
finding land. The Aswid's bat escapes this only because debug-fly is checked at
the very top of UpdateMotion, before water is considered at all - which is
exactly why it can take off from the water and Moder could not. Those frames now
go back to UpdateFlying, and while in swim depth the form climbs regardless of
where the camera points, so the surface is something you break out of rather than
something you sit in. Nothing that merely asks IsSwimming - the Wet status, the
animator, stamina - is touched.

All five speeds now run through m_flySlowSpeed instead of the m_run/m_flyFastSpeed
pair, which only ever picked between two of them.
This commit is contained in:
kanym 2026-08-05 10:16:52 +02:00
commit 5cfd8cfab8
3 changed files with 170 additions and 27 deletions

View file

@ -257,7 +257,7 @@ namespace RacesOfValheim
if (state >= 3)
{
sb.AppendLine("[The Elder Unlock] Drake Form ('G' Key):");
sb.AppendLine("Take the shape of a frost drake. Right Mouse lifts you into flight: you glide wherever you aim, hold W to climb and gather speed, and release to hold level a moment before settling into a slow descent. In this shape you cannot yet strike.\n");
sb.AppendLine("Take the shape of a frost drake. Right Mouse lifts you into flight: you glide wherever you aim, hold W to climb and gather speed, hold Shift with it to spend stamina on a burst of speed, and press S to beat backwards along your aim while your gaze stays where it was. Release everything and you hold level for five seconds before settling into a slow descent. Water cannot hold you - your wings drag you free of the sea as readily as they lift you from the shore. In this shape you cannot yet strike.\n");
}
if (state >= 4)

View file

@ -1,3 +1,4 @@
using System.Reflection;
using HarmonyLib;
using UnityEngine;
@ -244,32 +245,64 @@ namespace RacesOfValheim
// move direction. Character.UpdateFlying normally reads whatever m_moveDir the vanilla input
// pipeline last wrote (ground-plane WASD relative to camera yaw only); this patch overwrites
// it every frame with the camera's actual look direction (pitch included) so the player always
// glides toward wherever the mouse is aiming, with W adding a speed boost (m_run) on top of the
// base glide speed instead of being required just to move.
// glides toward wherever the mouse is aiming, with W powering forward, Shift spending stamina
// for a burst of speed, and S beating backwards away from whatever you are looking at.
[HarmonyPatch(typeof(Character), "UpdateFlying")]
public static class SkadiDirectedFlightPatch
{
private const float TURN_SPEED = 120f;
private const float GLIDE_SPEED = 5f;
private const float BOOST_SPEED = 12f;
private const float HOVER_SECONDS = 2f;
private const float SPRINT_SPEED = 22f;
private const float REVERSE_SPEED = 7f;
// Climbing out of water is deliberately slower than a powered climb in open air - the
// wings are dragging themselves free, not racing.
private const float LIFTOFF_SPEED = 9f;
private const float HOVER_SECONDS = 5f;
// Per second, drained only while the sprint is actually being granted.
private const float SPRINT_STAMINA_PER_SECOND = 15f;
// Tangent of the unpowered descent angle: 0.4 sinks at roughly 22 degrees below level.
private const float DESCENT_SLOPE = 0.4f;
// How much of the aim heading survives the climb out of water. Mostly up, with enough
// forward in it that the player still chooses which shore they surface towards.
private const float LIFTOFF_HEADING_BLEND = 0.35f;
public static void Prefix(Character __instance)
/// <summary>
/// True while the local player is beating backwards this frame. Read by
/// SkadiReverseFacingPatch, which keeps the body pointed at the camera while it happens.
/// </summary>
public static bool Reversing { get; private set; }
public static void Prefix(Character __instance, float dt)
{
if (__instance != Player.m_localPlayer) return;
DrakeFormBehavior form = DrakeFormBehavior.Active;
if (form == null || !form.IsFlying) return;
if (form == null || !form.IsFlying)
{
Reversing = false;
return;
}
var traverse = Traverse.Create(__instance);
Vector3 lookDir = Player.m_localPlayer.GetLookDir();
bool boost = RaceInput.Allowed && Input.GetKey(KeyCode.W);
bool input = RaceInput.Allowed;
bool forward = input && Input.GetKey(KeyCode.W);
// Forward wins a W+S mash rather than the two cancelling into a dead hover.
bool backward = input && !forward && Input.GetKey(KeyCode.S);
bool sprintKey = input && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));
bool onGround = __instance.IsOnGround();
// IsSwimming is the exact test UpdateMotion uses to hand the frame to UpdateSwimming
// instead of UpdateFlying, so it is also the one condition SkadiWaterFlightPatch has
// to take back. Its half-second tail past leaving the water is welcome here - it
// keeps the climb going just long enough to clear the surface properly.
bool inWater = __instance.IsSwimming();
traverse.Field("m_run").SetValue(boost);
traverse.Field("m_flyFastSpeed").SetValue(BOOST_SPEED);
Reversing = backward;
// m_run only picks between the two fly speeds. Every mode now has its own speed, so
// leave it off and drive all of them through m_flySlowSpeed.
traverse.Field("m_run").SetValue(false);
// UpdateFlying rotates the body toward m_moveDir on its own, but at m_flyTurnSpeed,
// which sits at Character's 12 deg/s default because the Player prefab was never set
@ -277,38 +310,145 @@ namespace RacesOfValheim
// model reads as not turning at all. Give it a speed that suits a flying mount.
traverse.Field("m_flyTurnSpeed").SetValue(TURN_SPEED);
// Powered flight and ground contact both refresh the hover window.
if (boost || onGround) form.LastPoweredTime = Time.time;
// Powered flight, ground contact and clawing out of water all refresh the hover
// window, so none of them can be followed by an immediate sink.
if (forward || backward || onGround || inWater) form.LastPoweredTime = Time.time;
Vector3 moveDir = lookDir;
float coastSpeed;
float speed;
if (onGround || Time.time - form.LastPoweredTime < HOVER_SECONDS)
if (inWater)
{
// Wet wings still beat. Water used to be a trap: UpdateMotion hands a swimming
// character to UpdateSwimming before it ever looks at m_flying, so a dragon that
// touched the sea was stuck paddling with the flight controls doing nothing.
// SkadiWaterFlightPatch gives the frame back to flight, and this branch spends it
// climbing regardless of where the camera points, so the surface is always
// something you break out of rather than something you sit in.
moveDir = (Vector3.up + FlatHeading(__instance, lookDir) * LIFTOFF_HEADING_BLEND).normalized;
speed = LIFTOFF_SPEED;
}
else if (backward)
{
// Straight reverse thrust along the aim, pitch included: look down and beat back
// and you rise away from what you are looking at, which is the whole point of
// having a reverse - you can retreat without taking your eyes (or your breath
// attack, which fires along the same vector) off the target.
moveDir = -lookDir;
speed = REVERSE_SPEED;
}
else if (forward)
{
speed = BOOST_SPEED;
// The sprint is the only part of flight that costs anything. Base flight stays
// free on purpose - the drake arrives at the Elder, long before the player has
// the stamina pool to pay for simply staying airborne.
if (sprintKey && TrySpendSprintStamina(dt)) speed = SPRINT_SPEED;
}
else if (onGround || Time.time - form.LastPoweredTime < HOVER_SECONDS)
{
// Holding station: on the ground this keeps a touchdown from sliding the player
// forward forever, and in the air it gives the beat of level flight before the
// forward forever, and in the air it gives the beats of level flight before the
// form starts to sink. m_moveDir stays full length so the body still turns to
// face the camera, and zeroing the speed (rather than the rigidbody velocity)
// avoids fighting the AddForce UpdateFlying queues, which caused visible jitter.
coastSpeed = 0f;
speed = 0f;
}
else
{
// Unpowered flight is a glide, not a hover with a joystick: drift along the
// heading the camera faces while losing height, so aiming at the sky without
// holding W no longer climbs.
Vector3 heading = new Vector3(lookDir.x, 0f, lookDir.z);
if (heading.sqrMagnitude < 0.0001f)
{
heading = __instance.transform.forward;
heading.y = 0f;
}
moveDir = (heading.normalized + Vector3.down * DESCENT_SLOPE).normalized;
coastSpeed = GLIDE_SPEED;
moveDir = (FlatHeading(__instance, lookDir) + Vector3.down * DESCENT_SLOPE).normalized;
speed = GLIDE_SPEED;
}
traverse.Field("m_moveDir").SetValue(moveDir);
traverse.Field("m_flySlowSpeed").SetValue(coastSpeed);
traverse.Field("m_flySlowSpeed").SetValue(speed);
}
/// <summary>Aim flattened onto the ground plane, falling back to the body's own facing
/// when the player is looking straight up or down.</summary>
private static Vector3 FlatHeading(Character character, Vector3 lookDir)
{
Vector3 heading = new Vector3(lookDir.x, 0f, lookDir.z);
if (heading.sqrMagnitude < 0.0001f)
{
heading = character.transform.forward;
heading.y = 0f;
}
return heading.normalized;
}
/// <summary>
/// Charges this frame of sprint. Returns false when the player cannot pay, which drops
/// them back to the free boost speed rather than out of the sky.
/// </summary>
private static bool TrySpendSprintStamina(float dt)
{
Player player = Player.m_localPlayer;
if (player == null) return false;
float cost = SPRINT_STAMINA_PER_SECOND * dt;
if (!player.HaveStamina(cost)) return false;
player.UseStamina(cost);
return true;
}
}
/// <summary>
/// Character.UpdateMotion asks IsSwimming before it asks m_flying, so a flying dragon that
/// touched water was handed to UpdateSwimming every frame: the flight patch above never ran,
/// the form paddled on the surface, and there was no way back into the air short of finding
/// land. (The Aswid's bat escapes this because debug-fly is checked at the very top of
/// UpdateMotion, before water is considered at all - which is exactly why it can take off
/// from the sea.) Hand those frames back to UpdateFlying, which is the only motion path the
/// two methods contend over: nothing else calls either of them, and everything that merely
/// asks IsSwimming - the Wet status, the animator, stamina - is left alone.
/// </summary>
[HarmonyPatch(typeof(Character), "UpdateSwimming")]
public static class SkadiWaterFlightPatch
{
private static readonly MethodInfo UpdateFlyingMethod = AccessTools.Method(typeof(Character), "UpdateFlying");
public static bool Prefix(Character __instance, float dt)
{
if (__instance != Player.m_localPlayer) return true;
DrakeFormBehavior form = DrakeFormBehavior.Active;
if (form == null || !form.IsFlying) return true;
// Fail open: if a game update ever renames the method, swim normally rather than
// freezing the player in place with no motion update at all.
if (UpdateFlyingMethod == null) return true;
UpdateFlyingMethod.Invoke(__instance, new object[] { dt });
return false;
}
}
/// <summary>
/// UpdateFlying turns the body to face m_moveDir, which is right for every direction of
/// travel except backwards - reverse thrust would spin the dragon around to fly nose-first
/// away from the camera, putting its tail where its breath comes out. Claiming
/// AlwaysRotateCamera for the duration switches UpdateRotation over to the camera's yaw
/// instead, so the form keeps facing whatever it is retreating from. Scoped to the frames
/// the reverse is actually held.
/// </summary>
[HarmonyPatch(typeof(Player), "AlwaysRotateCamera")]
public static class SkadiReverseFacingPatch
{
public static bool Prefix(Player __instance, ref bool __result)
{
if (__instance != Player.m_localPlayer) return true;
if (!SkadiDirectedFlightPatch.Reversing) return true;
DrakeFormBehavior form = DrakeFormBehavior.Active;
if (form == null || !form.IsFlying) return true;
__result = true;
return false;
}
}

View file

@ -125,9 +125,12 @@ This mod currently introduces 8 custom races:
- **Fader**: Skeleton Dragon Form ('J' Key).
While transformed, Right Mouse toggles flight. You glide toward wherever you are aiming; hold W
to power forward and climb. Let go and the form holds level for a couple of seconds before
settling into a gentle descent. Timed forms show their remaining seconds, and their cooldown,
as a Moder trophy icon beside the minimap.
to power forward and climb, and add Shift to spend stamina on a burst of speed. S beats backwards
along your aim - look down and press it to rise away from whatever you are watching, without
turning to face away from it. Let go of everything and the form holds level for five seconds
before settling into a gentle descent. Water is no obstacle: a flying form beats its way back
out of the sea instead of being stuck paddling on the surface. Timed forms show their remaining
seconds, and their cooldown, as a Moder trophy icon beside the minimap.
### Skeleton Progression
- **Base (No Bosses)**: +50 Max Health. Undead Diet (Cannot eat mortal food, no stamina bar).