From 4303fd82f09e2ad8d4a0b6a46a2da7a3b6313a72 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 03:31:12 +0000 Subject: [PATCH 01/41] feat: the hero takes Gothic's fall damage at the landing - measured from the top of the jump or fall, none within FALLDOWN_HEIGHT, also without the combat system HeroFallService (Core) tracks the hero's airborne phases from per-frame measurements (HeroAirborneDomain), sets BS_JUMP/BS_FALL, computes the damage once at the landing with NpcFallDomain.GetFallDamage and raises HeroLanded and FallDamage. Gated by DeveloperConfig.EnableHeroFallDamage. FightService takes the hero's fall damage without the combat system (NPCs unchanged), honours god mode for a hero without prefab properties and never sets negative hit points. A deep landing locks walking (PlayerLocks.FallLanding). Co-Authored-By: Claude Opus 5.5 --- .../Domain/Movement/HeroAirborneDomain.cs | 170 +++++++++++ .../Scripts/GlobalEventDispatcher.cs | 8 + .../Scripts/Models/Config/DeveloperConfig.cs | 5 + .../Scripts/Models/Context/PlayerLocks.cs | 4 +- .../Scripts/Models/Movement/HeroAirEvent.cs | 27 ++ .../Scripts/Models/Movement/HeroAirPhase.cs | 30 ++ .../Scripts/Models/Movement/HeroFallSample.cs | 59 ++++ .../Scripts/Models/Movement/HeroLanding.cs | 33 +++ .../Scripts/ReflexProjectInstaller.cs | 1 + .../Services/Movement/HeroFallService.cs | 265 ++++++++++++++++++ .../Scripts/Services/Npc/FightService.cs | 24 +- .../Movement/HeroAirborneDomainTest.cs | 205 ++++++++++++++ 12 files changed, 825 insertions(+), 6 deletions(-) create mode 100644 Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroAirEvent.cs create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs create mode 100644 Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs create mode 100644 Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs new file mode 100644 index 000000000..c9ab1796b --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs @@ -0,0 +1,170 @@ +using Gothic.Core.Models.Movement; +using UnityEngine; + +namespace Gothic.Core.Domain.Movement +{ + /// + /// The hero's airborne phases from per-frame measurements (HeroFallSample): jump, fall, deep fall, landing, and + /// the drop of each landing - from the highest point of the phase down to the landing point (like OpenGothic, which + /// derives it from the impact speed: a jump on flat ground adds only its own small height). Pure rules, no Unity + /// objects - worker of HeroFallService, which decides what is ignored (water, climbing, teleports) and what a + /// landing costs. Platform-neutral: VR feeds it from the rig port, Flat can feed it from its controller. + /// - The phase is visual/body state only. Damage is never tied to it: a fall that plays S_FALLDN or even S_FALL + /// but lands within FALLDOWN_HEIGHT costs nothing; HeroFallService computes the damage once, at the landing. + /// - No fall without real falling: off the ground (beyond the platform's grounded grace) the hero falls only when + /// moving down faster than FallSpeed and below MinFallDrop - stairs, slopes and lifts stay walking. + /// + public class HeroAirborneDomain + { + /// + /// m/s downwards: an airborne hero this fast falls (S_FALLDN). Slower is a lift or a slope. + /// + public const float FallSpeed = 1f; + + /// + /// m below the highest point before a fall counts - the rig's ground snap (0.3 m) covers smaller steps. + /// + public const float MinFallDrop = 0.3f; + + // A jump that drops this far below its take-off (off a ledge) becomes a fall: S_FALLDN, the fall's landing. + private const float _jumpFallBelowTakeOff = 0.5f; + + // One frame's step beyond what falling (terminal speed) or jumping can do: a teleport nobody announced. + private const float _teleportTolerance = 1f; + private const float _teleportRise = 2f; + + private float _previousFeetY; + private bool _hasPrevious; + private float _lastGroundedFeetY; + private bool _hasLastGrounded; + + public HeroAirPhase Phase { get; private set; } + + /// + /// Highest feet height of the current airborne phase. + /// + public float PeakY { get; private set; } + + /// + /// Feet height where the current airborne phase left the ground. + /// + public float TakeOffY { get; private set; } + + /// + /// Falling deeper than FALLDOWN_HEIGHT so far: S_FALL instead of S_FALLDN. Visual only. + /// + public bool IsDeepFall { get; private set; } + + /// + /// One frame. safeHeight: the guild's FALLDOWN_HEIGHT in m (0 = none: no deep falls). Returns what changed; + /// landing is set for HeroAirEvent.Landed only. + /// + public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLanding landing) + { + landing = default; + var feetY = sample.FeetY; + var deltaTime = sample.DeltaTime; + + var verticalSpeed = 0f; + if (_hasPrevious && deltaTime > 0f) + { + var step = feetY - _previousFeetY; + var maxDrop = Mathf.Max(sample.MaxFallSpeed, 0f) * deltaTime + _teleportTolerance; + if (step > _teleportRise || step < -maxDrop) + { + var wasAirborne = Phase != HeroAirPhase.Grounded; + Hold(feetY); + return wasAirborne ? HeroAirEvent.TeleportDetected : HeroAirEvent.None; + } + verticalSpeed = step / deltaTime; + } + _previousFeetY = feetY; + _hasPrevious = true; + + if (sample.IsGrounded && !sample.IsJumping) + return TickGrounded(feetY, safeHeight, out landing); + + if (Phase == HeroAirPhase.Grounded) + { + // The grounded grace hides the first moments of a fall: the take-off is the last ground contact. + PeakY = _hasLastGrounded ? Mathf.Max(_lastGroundedFeetY, feetY) : feetY; + TakeOffY = PeakY; + IsDeepFall = false; + Phase = HeroAirPhase.Airborne; + } + PeakY = Mathf.Max(PeakY, feetY); + + if (Phase == HeroAirPhase.Airborne && sample.IsJumping) + { + Phase = HeroAirPhase.Jumping; + return HeroAirEvent.JumpStarted; + } + + if (Phase is HeroAirPhase.Airborne or HeroAirPhase.Jumping && IsFalling(feetY, verticalSpeed)) + { + Phase = HeroAirPhase.Falling; + return HeroAirEvent.FallStarted; + } + + if (Phase == HeroAirPhase.Falling && !IsDeepFall && safeHeight > 0f && PeakY - feetY > safeHeight) + { + IsDeepFall = true; + return HeroAirEvent.DeepFallStarted; + } + + return HeroAirEvent.None; + } + + /// + /// Not tracked right now (climbing, swimming, teleported, lying...): no phase, a later fall starts from here. + /// + public void Hold(float feetY) + { + Phase = HeroAirPhase.Grounded; + IsDeepFall = false; + _previousFeetY = feetY; + _hasPrevious = true; + _lastGroundedFeetY = feetY; + _hasLastGrounded = true; + } + + /// + /// Forget everything (a new world or a loaded game). + /// + public void Reset() + { + Phase = HeroAirPhase.Grounded; + IsDeepFall = false; + _hasPrevious = false; + _hasLastGrounded = false; + } + + private HeroAirEvent TickGrounded(float feetY, float safeHeight, out HeroLanding landing) + { + landing = default; + _lastGroundedFeetY = feetY; + _hasLastGrounded = true; + + var phase = Phase; + Phase = HeroAirPhase.Grounded; + IsDeepFall = false; + + // A step down or a flicker: no jump, no fall - no landing. + if (phase is HeroAirPhase.Grounded or HeroAirPhase.Airborne) + return HeroAirEvent.None; + + var height = Mathf.Max(0f, PeakY - feetY); + landing = new HeroLanding(height, phase == HeroAirPhase.Jumping, safeHeight > 0f && height > safeHeight); + return HeroAirEvent.Landed; + } + + private bool IsFalling(float feetY, float verticalSpeed) + { + if (verticalSpeed >= 0f) + return false; + if (Phase == HeroAirPhase.Jumping) + return feetY < TakeOffY - _jumpFallBelowTakeOff; + return verticalSpeed <= -FallSpeed && PeakY - feetY >= MinFallDrop; + } + } +} diff --git a/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs b/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs index e5ef283d2..8582af0c6 100644 --- a/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs +++ b/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs @@ -177,6 +177,14 @@ public enum HandSide public static readonly UnityEvent NpcIgnited = new(); // NPC landed after a fall higher than FALLDOWN_HEIGHT (damage already minus PROT_FALL). public static readonly UnityEvent FallDamage = new(); + + /// + /// The hero landed after a jump or fall (HeroFallService), raised before his FallDamage. The VR hero body + /// plays the deep landing (lying, getting up), the controllers vibrate. + /// float - drop in m from the highest point of the jump/fall + /// bool - deeper than FALLDOWN_HEIGHT: he lands lying and gets up, movement locked meanwhile + /// + public static readonly UnityEvent HeroLanded = new(); // Marvin's "kill": the NPC dies at once, no killer (no experience). public static readonly UnityEvent CheatKill = new(); diff --git a/Assets/Gothic-Core/Scripts/Models/Config/DeveloperConfig.cs b/Assets/Gothic-Core/Scripts/Models/Config/DeveloperConfig.cs index c47400a2d..33b16dc9a 100644 --- a/Assets/Gothic-Core/Scripts/Models/Config/DeveloperConfig.cs +++ b/Assets/Gothic-Core/Scripts/Models/Config/DeveloperConfig.cs @@ -186,6 +186,11 @@ public class DebugChannelTypesCollection : CollectionWrapper + /// What one measurement changed (HeroAirborneDomain.Tick). At most one per frame. + /// + public enum HeroAirEvent + { + None, + JumpStarted, + FallStarted, + + /// + /// The drop got deeper than FALLDOWN_HEIGHT: S_FALL instead of S_FALLDN (visual only). + /// + DeepFallStarted, + + /// + /// A jump or fall ended on the ground - see HeroLanding. Stepping off a small edge ends without one. + /// + Landed, + + /// + /// The feet moved further in one frame than falling or jumping can: a teleport nobody announced. Reset. + /// + TeleportDetected + } +} diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs new file mode 100644 index 000000000..f407ffdf1 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs @@ -0,0 +1,30 @@ +namespace Gothic.Core.Models.Movement +{ + /// + /// Where the hero is between the ground and the air (HeroFallService). Drives his body state (BS_JUMP, BS_FALL) + /// and the jump and fall animations of the VR hero body. Visual and body state only - fall damage is decided once, + /// at the landing, from the measured drop (HeroLanding), never from the phase. + /// + public enum HeroAirPhase + { + /// + /// On the ground - or not tracked (swimming, climbing, lying, teleported). + /// + Grounded, + + /// + /// Off the ground without a jump and not falling yet (a step down, a slope, a lift): nothing changes yet. + /// + Airborne, + + /// + /// His own jump, from the take-off until the landing - unless he drops clearly below the take-off. + /// + Jumping, + + /// + /// Falling: S_FALLDN, S_FALL once the drop is deeper than FALLDOWN_HEIGHT (HeroAirborneDomain.IsDeepFall). + /// + Falling + } +} diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs new file mode 100644 index 000000000..9b129aa57 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs @@ -0,0 +1,59 @@ +namespace Gothic.Core.Models.Movement +{ + /// + /// One frame's measurement of the player's body for HeroFallService.Tick, given by the platform (VR: the rig port + /// IVrRig, with its grounded grace time). Platform-neutral: the rules don't know where it comes from. + /// + public readonly struct HeroFallSample + { + /// + /// Height of the feet (world y in m). + /// + public readonly float FeetY; + + /// + /// On the ground - with the platform's grace time against one-frame flickers on slopes and stairs. + /// + public readonly bool IsGrounded; + + /// + /// The player's own jump runs (take-off until landing). + /// + public readonly bool IsJumping; + + /// + /// A hand holds a ladder or a ledge: no fall, the fall measured so far is dropped. + /// + public readonly bool IsClimbing; + + /// + /// The hero is transformed into a monster (spell): the transformation plays its own fall, no hero fall. + /// + public readonly bool IsTransformed; + + /// + /// m/s^2. 0 = no gravity (swimming, diving): nothing falls. + /// + public readonly float Gravity; + + /// + /// Terminal fall speed in m/s - a larger step per frame is a teleport. + /// + public readonly float MaxFallSpeed; + + public readonly float DeltaTime; + + public HeroFallSample(float feetY, bool isGrounded, bool isJumping, bool isClimbing, bool isTransformed, + float gravity, float maxFallSpeed, float deltaTime) + { + FeetY = feetY; + IsGrounded = isGrounded; + IsJumping = isJumping; + IsClimbing = isClimbing; + IsTransformed = isTransformed; + Gravity = gravity; + MaxFallSpeed = maxFallSpeed; + DeltaTime = deltaTime; + } + } +} diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs new file mode 100644 index 000000000..c4db498fb --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs @@ -0,0 +1,33 @@ +namespace Gothic.Core.Models.Movement +{ + /// + /// The end of a jump or fall of the hero (HeroAirborneDomain): how deep he dropped and how he lands. + /// + public readonly struct HeroLanding + { + /// + /// Drop in m from the highest point of the airborne phase down to the landing point. A jump on flat ground is + /// only its own small height. Measured from positions, not from the speed: the rig's terminal velocity would + /// cap a speed based height at ~20 m. + /// + public readonly float Height; + + /// + /// The phase was the hero's own jump and he never dropped clearly below the take-off (T_JUMP_2_STAND). + /// + public readonly bool IsJump; + + /// + /// Deeper than the guild's FALLDOWN_HEIGHT: he lands lying (T_FALL_2_FALLEN) and gets up. Only the landing + /// animation - the damage is NpcFallDomain.GetFallDamage of Height (0 within FALLDOWN_HEIGHT, PROT_FALL off). + /// + public readonly bool IsDeep; + + public HeroLanding(float height, bool isJump, bool isDeep) + { + Height = height; + IsJump = isJump; + IsDeep = isDeep; + } + } +} diff --git a/Assets/Gothic-Core/Scripts/ReflexProjectInstaller.cs b/Assets/Gothic-Core/Scripts/ReflexProjectInstaller.cs index 519b69f0f..28af77ce4 100644 --- a/Assets/Gothic-Core/Scripts/ReflexProjectInstaller.cs +++ b/Assets/Gothic-Core/Scripts/ReflexProjectInstaller.cs @@ -146,6 +146,7 @@ public void InstallBindings(ContainerBuilder containerBuilder) containerBuilder.AddSingleton(typeof(PhysicsService)); containerBuilder.AddSingleton(typeof(RoomService)); containerBuilder.AddSingleton(typeof(LedgeService)); + containerBuilder.AddSingleton(typeof(HeroFallService)); // Misc containerBuilder.AddSingleton(typeof(AudioService)); diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs new file mode 100644 index 000000000..62aa01348 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -0,0 +1,265 @@ +using Gothic.Core.Const; +using Gothic.Core.Domain.Movement; +using Gothic.Core.Domain.Npc; +using Gothic.Core.Logging; +using Gothic.Core.Models.Container; +using Gothic.Core.Models.Context; +using Gothic.Core.Models.Movement; +using Gothic.Core.Models.Vm; +using Gothic.Core.Services.Config; +using Gothic.Core.Services.Context; +using Gothic.Core.Services.Npc; +using Reflex.Attributes; +using UnityEngine; +using Logger = Gothic.Core.Logging.Logger; + +namespace Gothic.Core.Services.Movement +{ + /// + /// The hero's jumps and falls like the engine's: BS_JUMP / BS_FALL while in the air, fall damage at the landing + /// (DeveloperConfig.EnableHeroFallDamage), lying and getting up after a deep fall. The platform measures (VR: the + /// rig port, VrHeroJumpFall) and calls Tick every frame; the phases come from HeroAirborneDomain. + /// Damage rule - one place, once per landing, never per frame and never from the fall animation: the drop from the + /// highest point of the jump/fall to the landing point, NpcFallDomain.GetFallDamage = (drop - FALLDOWN_HEIGHT) * + /// FALLDOWN_DAMAGE - PROT_FALL, at least 0. S_FALLDN starts early and S_FALL past FALLDOWN_HEIGHT is only visual: a + /// fall landing within FALLDOWN_HEIGHT (5 m for humans) costs nothing. FightService applies it (a deep fall kills, + /// god mode ignores it). + /// Not tracked (no damage): in water (water level not normal, swimming, diving, no gravity), climbing, teleported + /// (OnTeleported, or a step no fall can make), transformed, down (dead, unconscious) or busy (sitting, mobs). + /// Not saved: a loaded game starts on the ground (LoadGameStart / WorldSceneLoaded reset it). + /// + public class HeroFallService + { + [Inject] private readonly GameStateService _gameStateService; + [Inject] private readonly NpcService _npcService; + [Inject] private readonly ConfigService _configService; + [Inject] private readonly ContextInteractionService _contextInteractionService; + [Inject] private readonly AnimationService _animationService; + + /// + /// The hero lies this long in S_FALLEN after a deep fall (T_FALL_2_FALLEN) before he gets up (T_FALLEN_2_STAND). + /// + public const float FallenHoldSeconds = 0.3f; + + public const string DeepLandingAnimation = "T_FALL_2_FALLEN"; + public const string FallenAnimation = "S_FALLEN"; + public const string StandUpAnimation = "T_FALLEN_2_STAND"; + + // Lock after a deep landing without the hero's animations: T_FALL_2_FALLEN + S_FALLEN + T_FALLEN_2_STAND (G1). + private const float _defaultDeepLandingSeconds = 1.7f; + + private readonly HeroAirborneDomain _airborne = new(); + + private bool _isLandingLocked; + private float _landingUnlockTime; + // Why the hero isn't tracked right now (logged when it changes mid-air), null = tracked. + private string _holdReason; + + /// + /// The hero's phase this frame (VR hero body: which jump/fall animation). + /// + public HeroAirPhase Phase => _airborne.Phase; + + /// + /// Falling deeper than FALLDOWN_HEIGHT: S_FALL instead of S_FALLDN. Visual only - no damage until the landing. + /// + public bool IsDeepFall => _airborne.IsDeepFall; + + /// + /// Counts the landings - a new value: LastLanding just happened (the VR hero body picks the landing animation). + /// + public int LandingCount { get; private set; } + + public HeroLanding LastLanding { get; private set; } + + public HeroFallService() + { + GlobalEventDispatcher.LoadGameStart.AddListener(ResetAll); + GlobalEventDispatcher.WorldSceneLoaded.AddListener(ResetAll); + } + + /// + /// One frame's measurement of the player's body. Called every frame by the platform, also on the ground. + /// + public void Tick(in HeroFallSample sample) + { + UpdateLandingLock(); + + var hero = _npcService.GetHeroContainer(); + if (hero?.Props == null) + return; + + var holdReason = GetHoldReason(hero, sample); + if (holdReason != null) + { + Hold(hero, sample.FeetY, holdReason); + return; + } + _holdReason = null; + + var safeHeight = NpcFallDomain.GetSafeFallHeight(_gameStateService.GuildValues, hero); + switch (_airborne.Tick(sample, safeHeight, out var landing)) + { + case HeroAirEvent.JumpStarted: + SetAirBodyState(hero, VmGothicEnums.BodyState.BsJump); + Logger.Log($"[HeroFall] Jump from {_airborne.TakeOffY:F2}", LogCat.Npc); + break; + case HeroAirEvent.FallStarted: + SetAirBodyState(hero, VmGothicEnums.BodyState.BsFall); + Logger.Log($"[HeroFall] Falls from {_airborne.PeakY:F2} (FALLDOWN_HEIGHT {safeHeight:F1} m - " + + "no damage within it)", LogCat.Npc); + break; + case HeroAirEvent.DeepFallStarted: + Logger.Log($"[HeroFall] Deeper than FALLDOWN_HEIGHT {safeHeight:F1} m - S_FALL, the damage " + + "follows at the landing", LogCat.Npc); + break; + case HeroAirEvent.Landed: + EndAirBodyState(hero); + Land(hero, landing, safeHeight, sample.FeetY); + break; + case HeroAirEvent.TeleportDetected: + EndAirBodyState(hero); + Logger.Log($"[HeroFall] Moved too far in one frame (to {sample.FeetY:F2}) - a teleport, the " + + "fall is ignored", LogCat.Npc); + break; + } + } + + /// + /// The player was teleported (thumbstick, Marvin, AI_Teleport, spawn, loading, ledge/ladder exits): whatever + /// fall ran is dropped, a new one starts at the target. + /// + public void OnTeleported(float feetY) + { + var hero = _npcService.GetHeroContainer(); + if (hero?.Props != null) + Hold(hero, feetY, "teleported"); + else + _airborne.Hold(feetY); + } + + /// + /// Why the hero isn't tracked now, null if he is. + /// + private static string GetHoldReason(NpcContainer hero, in HeroFallSample sample) + { + if (sample.IsClimbing) + return "climbing"; + if (sample.IsTransformed) + return "transformed (the transformation falls itself)"; + if (sample.Gravity <= 0f) + return "no gravity (swimming, diving)"; + + var ai = hero.Vob?.AiHuman; + if (ai != null && ai.WaterLevel != (int)ZenGineConst.WaterLevel.Normal) + return "in water"; + + return hero.Props.BodyState is VmGothicEnums.BodyState.BsStand or VmGothicEnums.BodyState.BsWalk + or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSneak or VmGothicEnums.BodyState.BsJump + or VmGothicEnums.BodyState.BsFall + ? null + : $"body state {hero.Props.BodyState}"; + } + + private void Hold(NpcContainer hero, float feetY, string reason) + { + if (_airborne.Phase != HeroAirPhase.Grounded) + Logger.Log($"[HeroFall] {_airborne.Phase} ended without a landing ({reason}) at {feetY:F2}, " + + $"{_airborne.PeakY - feetY:F2} m below the top - no fall damage", LogCat.Npc); + else if (reason != _holdReason) + Logger.LogEditor($"[HeroFall] Not tracked: {reason}", LogCat.Npc); + _holdReason = reason; + + _airborne.Hold(feetY); + EndAirBodyState(hero); + } + + /// + /// The landing, once: damage from the measured drop, the deep landing's lock, the event for the VR body. + /// + private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, float feetY) + { + LandingCount++; + LastLanding = landing; + + var isDamageOn = _configService.Dev.EnableHeroFallDamage; + var damage = NpcFallDomain.GetFallDamage(_gameStateService.GuildValues, hero, landing.Height); + var kind = landing.IsJump ? "jump" : landing.IsDeep ? "deep fall" : "fall"; + Logger.Log($"[HeroFall] Landed ({kind}) at {feetY:F2} after {landing.Height:F2} m, FALLDOWN_HEIGHT " + + $"{safeHeight:F1} m, damage {damage}" + + (isDamageOn ? "" : " - not applied (DeveloperConfig.EnableHeroFallDamage off)"), LogCat.Npc); + + // Before the damage: a deadly fall's HeroDied comes after it, the VR body knows it lands lying. + GlobalEventDispatcher.HeroLanded.Invoke(landing.Height, landing.IsDeep); + if (landing.IsDeep) + LockForDeepLanding(hero); + + if (isDamageOn && damage > 0) + GlobalEventDispatcher.FallDamage.Invoke(hero, damage); + } + + /// + /// He lies and gets up: no walking or teleporting until then (turning and the hands stay free). + /// + private void LockForDeepLanding(NpcContainer hero) + { + var seconds = GetAnimationSeconds(hero, DeepLandingAnimation) + FallenHoldSeconds + + GetAnimationSeconds(hero, StandUpAnimation); + if (seconds <= FallenHoldSeconds) + seconds = _defaultDeepLandingSeconds; + + _contextInteractionService.LockPlayer(PlayerLocks.FallLanding, PlayerControls.Walking); + _isLandingLocked = true; + _landingUnlockTime = Time.time + seconds; + Logger.Log($"[HeroFall] Deep landing - movement locked for {seconds:F2} s", LogCat.Npc); + } + + private float GetAnimationSeconds(NpcContainer hero, string animationName) + { + return _animationService.GetTrack(animationName, hero.Props.MdsNameBase, hero.Props.MdsNameOverlay) + ?.Duration ?? 0f; + } + + private void UpdateLandingLock() + { + if (!_isLandingLocked || Time.time < _landingUnlockTime) + return; + Unlock(); + } + + private void Unlock() + { + if (!_isLandingLocked) + return; + _isLandingLocked = false; + _contextInteractionService.UnlockPlayer(PlayerLocks.FallLanding); + } + + /// + /// BS_JUMP / BS_FALL only over the hero's own moving states - swimming, lying, sitting stay. + /// + private static void SetAirBodyState(NpcContainer hero, VmGothicEnums.BodyState bodyState) + { + if (hero.Props.BodyState is VmGothicEnums.BodyState.BsStand or VmGothicEnums.BodyState.BsWalk + or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSneak or VmGothicEnums.BodyState.BsJump + or VmGothicEnums.BodyState.BsFall) + hero.Props.BodyState = bodyState; + } + + /// + /// Back on his feet: BS_STAND, the platform's movement (VR: VRHeroMovement) makes it walk/run again. + /// + private static void EndAirBodyState(NpcContainer hero) + { + if (hero.Props.BodyState is VmGothicEnums.BodyState.BsJump or VmGothicEnums.BodyState.BsFall) + hero.Props.BodyState = VmGothicEnums.BodyState.BsStand; + } + + private void ResetAll() + { + _airborne.Reset(); + _holdReason = null; + Unlock(); + } + } +} diff --git a/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs b/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs index 2d7cf11d7..4dcacb1fd 100644 --- a/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs @@ -81,6 +81,8 @@ public void Init() // Scripts (B_KillNpc), drowning and damage zones kill with or without the combat system. GlobalEventDispatcher.HitPointsDepleted.AddListener(OnHitPointsDepleted); GlobalEventDispatcher.LoadGameStart.AddListener(OnLoadGameStart); + // The hero's falls (HeroFallService, EnableHeroFallDamage) hurt without the combat system, NPCs' with it. + GlobalEventDispatcher.FallDamage.AddListener(OnFallDamage); if (!_configService.Dev.EnableCombatSystem) return; @@ -89,7 +91,6 @@ public void Init() GlobalEventDispatcher.SpellHit.AddListener(_spellHitDomain.OnSpellHit); GlobalEventDispatcher.SpellSpreadHit.AddListener((caster, pos, damage) => _spellHitDomain.ApplySpreadHit(caster, pos, damage, null)); - GlobalEventDispatcher.FallDamage.AddListener(OnFallDamage); GlobalEventDispatcher.CheatKill.AddListener(OnCheatKill); GlobalEventDispatcher.RangedHit.AddListener(_rangedHitDomain.OnRangedHit); GlobalEventDispatcher.FightFinishingMove.AddListener(OnFinishingMove); @@ -170,14 +171,24 @@ public void ReportBlockContact(NpcContainer attacker) } /// - /// Fall damage (NpcJumpFall). Like the engine a fall can kill. + /// Fall damage (NpcJumpFall, the hero's HeroFallService). Like the engine a fall can kill. NPCs only with the + /// combat system (as before), the hero whenever HeroFallService raised it (EnableHeroFallDamage) - except in + /// Marvin's god mode. /// private void OnFallDamage(NpcContainer npc, int damage) { - if (npc?.Vob == null || npc.Props.BodyState == VmGothicEnums.BodyState.BsDead || IsHeroInGodMode(npc)) + if (npc?.Vob == null || npc.Props.BodyState == VmGothicEnums.BodyState.BsDead) + return; + if (IsHeroInGodMode(npc)) + { + Logger.Log($"[FightService] God mode: the hero's fall damage {damage} is ignored", LogCat.Fight); + return; + } + if (!_configService.Dev.EnableCombatSystem && !npc.Instance.IsHero(_gameStateService.GothicVm)) return; - var hitPoints = npc.Vob.GetAttribute((int)NpcAttribute.HitPoints) - damage; + // Never below 0, like the engine - the hero's health bar showed negative hit points. + var hitPoints = Mathf.Max(npc.Vob.GetAttribute((int)NpcAttribute.HitPoints) - damage, 0); _npcService.SetAttribute(npc, NpcAttribute.HitPoints, hitPoints); Logger.Log($"[FightService] {npc.Instance.GetName(NpcNameSlot.Slot0)} fall damage {damage} -> HP {hitPoints}", LogCat.Fight); @@ -239,7 +250,10 @@ private void OnHitPointsDepleted(NpcContainer victim) private bool IsHeroInGodMode(NpcContainer npc) { - return _playerService.IsGodMode && npc?.PrefabProps != null && npc.PrefabProps.IsHero(); + // The instance too: the fall damage of a hero without prefab properties (VR rig) skipped god mode. + return _playerService.IsGodMode && npc != null && + ((npc.PrefabProps != null && npc.PrefabProps.IsHero()) || + npc.Instance.IsHero(_gameStateService.GothicVm)); } /// diff --git a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs new file mode 100644 index 000000000..c84d1c3a5 --- /dev/null +++ b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs @@ -0,0 +1,205 @@ +using Gothic.Core.Domain.Movement; +using Gothic.Core.Models.Movement; +using NUnit.Framework; +using UnityEngine; + +namespace Gothic.Tests.EditMode.Movement +{ + /// + /// The hero's airborne phases and the drop of a landing (HeroAirborneDomain): measured from the highest point, + /// no landing for steps and slow lifts, teleports dropped, deep falls past FALLDOWN_HEIGHT. + /// + public class HeroAirborneDomainTest + { + private const float _dt = 1f / 72f; + private const float _gravity = 9.81f; + private const float _maxFallSpeed = 20f; + private const float _safeHeight = 5f; + + private HeroAirborneDomain _domain; + private HeroLanding _landing; + private int _landings; + private int _falls; + private int _deepFalls; + private int _teleports; + + [SetUp] + public void SetUp() + { + _domain = new HeroAirborneDomain(); + _landing = default; + _landings = 0; + _falls = 0; + _deepFalls = 0; + _teleports = 0; + } + + private void Tick(float feetY, bool isGrounded, bool isJumping = false, float dt = _dt) + { + var sample = new HeroFallSample(feetY, isGrounded, isJumping, false, false, _gravity, _maxFallSpeed, dt); + switch (_domain.Tick(sample, _safeHeight, out var landing)) + { + case HeroAirEvent.Landed: + _landings++; + _landing = landing; + break; + case HeroAirEvent.FallStarted: + _falls++; + break; + case HeroAirEvent.DeepFallStarted: + _deepFalls++; + break; + case HeroAirEvent.TeleportDetected: + _teleports++; + break; + } + } + + private void Stand(float feetY, int frames = 5) + { + for (var i = 0; i < frames; i++) + Tick(feetY, true); + } + + /// + /// Free fall (terminal speed capped) from y with a start speed up, until the ground. + /// + private void FallTo(float y, float groundY, float velocityY = 0f, bool isJumping = false, float dt = _dt) + { + for (var i = 0; i < 100000 && y > groundY; i++) + { + velocityY = Mathf.Max(velocityY - _gravity * dt, -_maxFallSpeed); + y = Mathf.Max(y + velocityY * dt, groundY); + Tick(y, y <= groundY, isJumping && y > groundY, dt); + } + Stand(groundY, 2); + } + + [Test] + public void JumpOnFlatGroundLandsAsJumpWithItsOwnHeight() + { + Stand(0f); + Tick(0f, true, true); + Assert.AreEqual(HeroAirPhase.Jumping, _domain.Phase); + FallTo(0f, 0f - 0.0001f, 3f, true); + + Assert.AreEqual(1, _landings); + Assert.IsTrue(_landing.IsJump); + Assert.IsFalse(_landing.IsDeep); + Assert.AreEqual(0, _falls); + Assert.AreEqual(0.46f, _landing.Height, 0.05f); + } + + [Test] + public void SmallFallWithinFallDownHeightIsNotDeep() + { + Stand(4f); + FallTo(4f, 0f); + + Assert.AreEqual(1, _falls); + Assert.AreEqual(0, _deepFalls); + Assert.AreEqual(1, _landings); + Assert.IsFalse(_landing.IsJump); + Assert.IsFalse(_landing.IsDeep); + Assert.AreEqual(4f, _landing.Height, 0.01f); + } + + [Test] + public void FallDeeperThanFallDownHeightIsDeep() + { + Stand(6f); + FallTo(6f, 0f); + + Assert.AreEqual(1, _deepFalls); + Assert.IsTrue(_landing.IsDeep); + Assert.AreEqual(6f, _landing.Height, 0.01f); + } + + [Test] + public void FiftyMetersAtTerminalSpeedAreMeasuredNotCapped() + { + Stand(50f); + FallTo(50f, 0f); + + Assert.AreEqual(0, _teleports); + Assert.AreEqual(50f, _landing.Height, 0.01f); + } + + [Test] + public void HitchesDontLookLikeTeleports() + { + Stand(30f); + FallTo(30f, 0f, dt: 0.25f); + + Assert.AreEqual(0, _teleports); + Assert.AreEqual(30f, _landing.Height, 0.01f); + } + + [Test] + public void JumpOffALedgeBecomesAFallFromTheJumpsTop() + { + Stand(10f); + Tick(10f, true, true); + FallTo(10f, 0f, 3f, true); + + Assert.AreEqual(1, _falls); + Assert.IsFalse(_landing.IsJump); + Assert.IsTrue(_landing.IsDeep); + Assert.AreEqual(10.46f, _landing.Height, 0.05f); + } + + [Test] + public void SteppingOffASmallEdgeIsNoLanding() + { + Stand(0.2f); + FallTo(0.2f, 0f); + + Assert.AreEqual(0, _falls); + Assert.AreEqual(0, _landings); + } + + [Test] + public void SlowLiftIsNoFall() + { + Stand(10f); + var y = 10f; + for (var i = 0; i < 72 * 5; i++) + { + y -= 0.8f * _dt; + Tick(y, false); + } + Stand(y); + + Assert.AreEqual(0, _falls); + Assert.AreEqual(0, _landings); + } + + [Test] + public void TeleportMidAirDropsTheFall() + { + Stand(20f); + for (var i = 0; i < 30; i++) + Tick(20f - 0.5f * _gravity * Mathf.Pow(i * _dt, 2f), false); + Assert.AreEqual(HeroAirPhase.Falling, _domain.Phase); + Tick(-200f, false); + Assert.AreEqual(1, _teleports); + Assert.AreEqual(HeroAirPhase.Grounded, _domain.Phase); + } + + [Test] + public void HoldDropsTheFallAndStartsTheNextOneThere() + { + Stand(20f); + for (var i = 0; i < 30; i++) + Tick(20f - 0.5f * _gravity * Mathf.Pow(i * _dt, 2f), false); + Assert.AreEqual(HeroAirPhase.Falling, _domain.Phase); + + // A ladder grabbed at 18 m, let go there. + _domain.Hold(18f); + FallTo(18f, 16f); + + Assert.AreEqual(1, _landings); + Assert.AreEqual(2f, _landing.Height, 0.01f); + } + } +} From d2b05e4499f4313a0acaae0521c7d227cc2ee26f Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 03:31:56 +0000 Subject: [PATCH 02/41] feat: the VR hero jumps and falls for the scripts (BS_JUMP, BS_FALL) and gets hurt by deep falls - the rig port feeds HeroFallService VrHeroJumpFall measures feet height, grounded (with the rig's grace), jumping (new IVrRig.IsJumping, XRI's jump provider), climbing, gravity and teleports. A hero jumping or falling into water swims (VRSwimDive takes BS_JUMP/BS_FALL over). Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Player/VRHeroMovement.cs | 3 +- .../Scripts/Adapters/Player/VRSwimDive.cs | 4 +- .../Scripts/Adapters/Player/VrHeroJumpFall.cs | 57 +++++++++++++++++++ .../Interaction/Backends/Xri/XriRig.cs | 5 ++ .../Scripts/Interaction/Ports/IVrRig.cs | 6 ++ .../Context/VRContextInteractionService.cs | 3 + 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs index c6ccaffd7..4bf5941bd 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs @@ -182,7 +182,8 @@ private void UpdateSpeedBoost() /// /// The engine sets BS_WALK/BS_RUN from the hero's movement. Scripts /// read it, e.g. G1 ZS_Attack_Loop gives up a chase ("$RUNCOWARD") after HAI_TIME_FOLLOW loops of a running - /// target. Only stand/walk/run are touched - swim/dive (VRSwimDive), unconscious, sitting, ... stay. + /// target. Only stand/walk/run are touched - jump/fall (HeroFallService), swim/dive (VRSwimDive), unconscious, + /// sitting, ... stay. /// private void UpdateHeroBodyState() { diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs index 564b37df0..96a1fa056 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs @@ -373,8 +373,10 @@ private void UpdateHeroBodyState() return; var bodyState = _heroContainer.Props.BodyState; + // Jumping or falling into the water too (HeroFallService): he swims, not falls. var isWaterOrMoving = bodyState is VmGothicEnums.BodyState.BsStand or VmGothicEnums.BodyState.BsWalk - or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSwim or VmGothicEnums.BodyState.BsDive; + or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSwim or VmGothicEnums.BodyState.BsDive + or VmGothicEnums.BodyState.BsJump or VmGothicEnums.BodyState.BsFall; if (!isWaterOrMoving) return; diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs new file mode 100644 index 000000000..507a0acd4 --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs @@ -0,0 +1,57 @@ +using Gothic.Core.Extensions; +using Gothic.Core.Logging; +using Gothic.Core.Models.Movement; +using Gothic.Core.Services.Movement; +using Gothic.VR.Interaction.Ports; +using Gothic.VR.Services; +using Reflex.Attributes; +using UnityEngine; +using Logger = Gothic.Core.Logging.Logger; + +namespace Gothic.VR.Adapters.Player +{ + /// + /// Feeds the hero's jumps and falls (HeroFallService: body state, fall damage, deep landing) from the VR rig port: + /// feet height, grounded (with the rig's grace time), jumping, climbing, gravity, teleports. Measures only - the + /// rules are in Core. Sits next to VRPlayer (added by VRContextInteractionService). + /// + public class VrHeroJumpFall : MonoBehaviour + { + [Inject] private readonly HeroFallService _heroFallService; + [Inject] private readonly VRSpellTransformService _vrSpellTransformService; + + private IVrRig _rig; + + private void Awake() + { + this.Inject(); + _rig = GetComponentInParent(); + if (_rig == null) + { + Logger.LogWarning("[VrHeroJumpFall] No VR rig above - the hero never jumps or falls.", LogCat.VR); + enabled = false; + return; + } + _rig.Teleported += OnTeleported; + } + + private void OnDestroy() + { + if (_rig is Object rigObject && rigObject != null) + _rig.Teleported -= OnTeleported; + } + + private void Update() + { + var sample = new HeroFallSample(_rig.Root.position.y, _rig.IsGrounded, _rig.IsJumping, _rig.IsClimbing, + _vrSpellTransformService != null && _vrSpellTransformService.IsTransformed, _rig.Gravity, + _rig.MaxFallSpeed, Time.deltaTime); + _heroFallService.Tick(sample); + } + + private void OnTeleported(Vector3 feetPosition) + { + _heroFallService.OnTeleported(feetPosition.y); + } + } +} diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs index af2616168..4554c84e6 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs @@ -192,6 +192,11 @@ public bool IsGrounded /// public bool IsClimbing => _climbProvider != null && _climbProvider.climbAnchorInteractable != null; + /// + /// XRI's jump from the take-off until grounded again (or cancelled by a grab mid-air). + /// + public bool IsJumping => _jumpProvider != null && _jumpProvider.isJumping; + /// /// Height the origin adds below the HMD (Device mode's CameraYOffset, 0 on the floor) and the tracking space's /// scale (Standing) - XriHvrStyleSimulator keeps the simulated eyes at a fixed height with them. diff --git a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs index 962b2b776..2c7f6ec1c 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs @@ -40,6 +40,12 @@ public interface IVrRig bool IsGrounded { get; } bool IsClimbing { get; } + /// + /// The player's own jump runs, from the take-off until the landing (the hero's jump: BS_JUMP, T_STAND_2_JUMP). + /// Default: false, for backends without jumping. + /// + bool IsJumping => false; + /// /// The player crouches (crouch button or the head held low). Crouched = sneaking for the scripts. /// diff --git a/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs b/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs index 3a0928f84..1e8cfb162 100644 --- a/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs +++ b/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs @@ -225,6 +225,9 @@ public void SetupPlayerController(DeveloperConfig developerConfig) // The hero's walk/run/sneak state, his footsteps and the speed potion's faster movement (any backend). _player.gameObject.AddComponent(); + // His jumps and falls: BS_JUMP/BS_FALL, fall damage, the deep landing (HeroFallService). + _player.gameObject.AddComponent(); + // Both hands on a melee weapon + both triggers = parry (option heroBlock, VRHeroBlockService). var heroBlock = new GameObject("_HeroBlock").AddComponent(); heroBlock.transform.SetParent(_player.transform, false); From 340291e485b6061071e1d022d7fb2d3d9d16305a Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 03:33:28 +0000 Subject: [PATCH 03/41] feat: the VR hero body jumps and falls like Gothic's hero - take-off, S_JUMP, S_FALLDN/S_FALL and the small landings VrHeroLocomotion follows HeroFallService's phase: T_STAND_2_JUMP or T_RUNL_2_JUMP (played in 0.3 s, the physics jump is already airborne) -> S_JUMP -> T_JUMP_2_STAND / T_JUMP_2_RUNL (or straight on running), S_FALLDN -> S_FALL past FALLDOWN_HEIGHT -> T_FALLDN_2_STAND. Walking on cuts a landing short. Stairs and slopes no longer show S_FALLDN (the old grounded/speed check). Co-Authored-By: Claude Opus 5.5 --- .../Adapters/Player/VrHeroLocomotion.cs | 128 ++++++++++++++++-- 1 file changed, 120 insertions(+), 8 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs index f864e1bbd..48da773f3 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using Gothic.Core.Logging; using Gothic.Core.Models.Container; +using Gothic.Core.Models.Movement; +using Gothic.Core.Services.Movement; using Gothic.Core.Services.Npc; using Gothic.VR.Interaction.Ports; using Gothic.VR.Models; @@ -15,7 +17,8 @@ namespace Gothic.VR.Adapters.Player /// Legs and torso of the VR hero body like the hero in Gothic: picks the animation and its playback speed from the /// player's velocity, the body state, the body's turn speed, crouching and swimming (VrHeroSwimPose) - idle, /// walk/run (played at the real speed - no sliding feet), walking backwards, strafing, turning on the spot, - /// falling, sneaking, swimming and diving. Worker of VRHeroBody (new().Inject(), Bind per built body). + /// jumping and falling (HeroFallService's phase), sneaking, swimming and diving. Worker of VRHeroBody + /// (new().Inject(), Bind per built body). A deep landing (lying, getting up) is VrHeroDownPose's. /// Publishes the body's walk/run/sneak speeds (its animations at its scale, VRPlayerService.HeroBodySpeeds) - the /// rig moves at them (VRHeroMovement), so the feet match the ground. /// @@ -23,6 +26,7 @@ public class VrHeroLocomotion { [Inject] private readonly AnimationService _animationService; [Inject] private readonly VRPlayerService _vrPlayerService; + [Inject] private readonly HeroFallService _heroFallService; private const float _idleSpeed = 0.15f; private const float _turnAnimationSpeed = 60f; // degrees per second @@ -34,6 +38,24 @@ public class VrHeroLocomotion private const string _walkBackAnimation = "S_WALKBL"; private const string _fallAnimation = "S_FALLDN"; + // Jumps and falls: take-off -> S_JUMP -> landing, S_FALLDN -> S_FALL (deeper than FALLDOWN_HEIGHT) -> landing. + private const string _standToJump = "T_STAND_2_JUMP"; + private const string _runToJump = "T_RUNL_2_JUMP"; + private const string _jumpAnimation = "S_JUMP"; + private const string _jumpToStand = "T_JUMP_2_STAND"; + // Not in G1's HUMANS.MDS: landing from a run goes straight on running then. + private const string _jumpToRun = "T_JUMP_2_RUNL"; + private const string _deepFallAnimation = "S_FALL"; + private const string _fallToStand = "T_FALLDN_2_STAND"; + // The take-off (G1: 0.96 s, the body rising 0.6 m) is over this fast - the physics jump (~0.46 m) is already in + // the air, the body should be in S_JUMP for it. + private const float _takeOffSeconds = 0.3f; + private HeroAirPhase _airPhase; + private int _landingCount; + // The take-off or landing one-shot running now (null = none) and its playback speed. + private string _airOneShot; + private float _airOneShotSpeed = 1f; + private VRHeroBodyAnimator _animator; private float _lastBodyYaw; private float _bodyYawSpeed; @@ -100,9 +122,15 @@ public void Update(NpcContainer hero, Transform body, IVrRig rig, float scale, b var isBackwards = local.z < -_backwardsShare * speed; var isTurning = Mathf.Abs(_bodyYawSpeed) >= _turnAnimationSpeed; + if (TryPlayAirAnimation(speed, isMoving)) + { + _animator.Update(Time.deltaTime); + return; + } + var animation = _swimPose.GetAnimation(_animator, bodyState, speed, isMoving, isBackwards, isTurning, _bodyYawSpeed < 0f) - ?? GetWalkAnimation(rig, velocity, speed, local, isMoving, isBackwards, isTurning, isCrouching, + ?? GetWalkAnimation(speed, local, isMoving, isBackwards, isTurning, isCrouching, _vrPlayerService.HeroSpeeds.RunThreshold); if (!_animator.HasAnimation(animation)) @@ -188,15 +216,99 @@ private string GetMissingAnimationFallback(string animation) } /// - /// On land: falling, sneaking, idle/turning on the spot, walking backwards, strafing, walking/running (from the + /// The jump/fall animations of HeroFallService's phase, and the landing's one-shot - false: none, the normal + /// animations play. Not in water (the swim pose's). One-shots are played to their end (polled - the animator + /// has no NextAni), a landing is cut short when the player walks on. + /// + private bool TryPlayAirAnimation(float speed, bool isMoving) + { + var previousPhase = _airPhase; + _airPhase = _heroFallService.Phase; + var isNewLanding = _heroFallService.LandingCount != _landingCount; + _landingCount = _heroFallService.LandingCount; + if (_swimPose.IsInWater) + { + _airOneShot = null; + return false; + } + + switch (_airPhase) + { + case HeroAirPhase.Jumping: + if (previousPhase != HeroAirPhase.Jumping) + StartAirOneShot(speed >= _vrPlayerService.HeroSpeeds.RunThreshold && + _animator.HasAnimation(_runToJump) + ? _runToJump + : _standToJump, _takeOffSeconds); + return PlayAirOneShot(false) || _animator.Play(_jumpAnimation); + case HeroAirPhase.Falling: + _airOneShot = null; + return _animator.Play(_heroFallService.IsDeepFall && _animator.HasAnimation(_deepFallAnimation) + ? _deepFallAnimation + : _fallAnimation); + } + + if (isNewLanding) + StartLanding(speed, isMoving); + return PlayAirOneShot(isMoving && _airOneShot != _jumpToRun); + } + + /// + /// Small landings only - a deep one lies down and gets up (VrHeroDownPose). Moving on: straight into the walk. + /// + private void StartLanding(float speed, bool isMoving) + { + _airOneShot = null; + var landing = _heroFallService.LastLanding; + if (landing.IsDeep) + return; + + var isRunning = speed >= _vrPlayerService.HeroSpeeds.RunThreshold; + if (landing.IsJump && isRunning && _animator.HasAnimation(_jumpToRun)) + StartAirOneShot(_jumpToRun, 0f); + else if (!isMoving) + StartAirOneShot(landing.IsJump ? _jumpToStand : _fallToStand, 0f); + } + + /// + /// seconds: squeeze the one-shot into this time (never slower than its own), 0 = its own speed. + /// + private void StartAirOneShot(string animation, float seconds) + { + var track = _animationService.GetTrack(animation, _animator.MdsBase, _animator.MdsOverlay); + if (track == null) + { + _airOneShot = null; + return; + } + + _airOneShot = animation; + _airOneShotSpeed = seconds > 0f && track.Duration > seconds ? track.Duration / seconds : 1f; + } + + /// + /// The running one-shot until its end. isCut: ends it now. + /// + private bool PlayAirOneShot(bool isCut) + { + if (_airOneShot == null) + return false; + if (isCut || _animator.IsDone(_airOneShot)) + { + _airOneShot = null; + return false; + } + + return _animator.Play(_airOneShot, _airOneShotSpeed); + } + + /// + /// On land: sneaking, idle/turning on the spot, walking backwards, strafing, walking/running (from the /// same speed on as BS_RUN, VrHeroSpeeds.RunThreshold). /// - private string GetWalkAnimation(IVrRig rig, Vector3 velocity, float speed, Vector3 local, bool isMoving, - bool isBackwards, bool isTurning, bool isCrouching, float runThreshold) + private string GetWalkAnimation(float speed, Vector3 local, bool isMoving, bool isBackwards, bool isTurning, + bool isCrouching, float runThreshold) { - if (rig != null && !rig.IsGrounded && velocity.y < -1f && !_swimPose.IsInWater && - _animator.HasAnimation(_fallAnimation)) - return _fallAnimation; if (isCrouching) return !isMoving ? "S_SNEAK" : isBackwards ? "S_SNEAKBL" : "S_SNEAKL"; if (!isMoving) From a1e143abb0ff6a351f5838bf0a9cacd19b5a0317 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 03:35:59 +0000 Subject: [PATCH 04/41] feat: after a deep fall the VR hero lands lying and gets up - the view stays at the head or goes with the body (Immersion option heroLandingView) VrHeroDownPose plays T_FALL_2_FALLEN -> S_FALLEN -> T_FALLEN_2_STAND on a deep HeroLanded in either heroFallMode, reusing its camera-down mechanism for heroLandingView 1; killed by the fall he stays lying (S_DEAD). Both controllers give a short strong pulse on a deep landing. Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Player/VrHeroDownPose.cs | 105 ++++++++++++++++-- .../Scripts/Models/VrHeroLandingView.cs | 20 ++++ .../Services/Context/VRContextMenuService.cs | 5 + .../Scripts/Services/VRPlayerService.cs | 22 ++++ .../Scripts/Services/VrHapticsService.cs | 12 ++ Assets/Gothic-VR/Scripts/VRConstants.cs | 5 + 6 files changed, 161 insertions(+), 8 deletions(-) create mode 100644 Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs index fd42ea3b2..06aef5f77 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs @@ -4,6 +4,7 @@ using Gothic.Core.Logging; using Gothic.Core.Models.Container; using Gothic.Core.Models.Vm; +using Gothic.Core.Services.Movement; using Gothic.Core.Services.Npc; using Gothic.VR.Interaction.Components; using Gothic.VR.Interaction.Ports; @@ -26,6 +27,10 @@ namespace Gothic.VR.Adapters.Player /// stays yours. It only follows the hero's events: FightService decides death and the locks, VRPlayer opens the /// death menu. Tells VRPlayerService whether a body that can fall exists (SetHeroFallBody); "blink" leaves the /// view to VrKnockoutView. + /// A fall deeper than FALLDOWN_HEIGHT (HeroLanded, deep) lands him lying - T_FALL_2_FALLEN, S_FALLEN for + /// HeroFallService.FallenHoldSeconds, T_FALLEN_2_STAND - whatever heroFallMode is; the Immersion option + /// heroLandingView decides whether the camera goes with the head (VRPlayerService.HeroLandingView, default: it stays + /// at the player's head). HeroFallService locks walking meanwhile. Killed by the fall, he stays lying dead (S_DEAD). /// Worker of VRHeroBody (new().Inject(), Initialize, Bind, Dispose). /// public class VrHeroDownPose @@ -39,6 +44,8 @@ private enum DownPhase Knockout, Asleep, Dead, + // After a deep fall, until he starts getting up (Rising). + Landing, Rising } @@ -52,6 +59,10 @@ private enum DownPhase private const string _standToSleep = "T_STAND_2_VICTIM_SLE"; private const string _sleep = "S_VICTIM_SLE"; private const string _sleepToStand = "T_VICTIM_SLE_2_STAND"; + // Killed by a fall: lying on his front like S_FALLEN. + private const string _deadFront = "S_DEAD"; + // A landing not started within this time (no body update meanwhile) is forgotten. + private const float _landingStartTimeout = 0.5f; private const float _downFloorMargin = 0.03f; private const float _minDownEyeHeight = 0.2f; @@ -65,6 +76,14 @@ private enum DownPhase private bool _isKnockedOut; private bool _isDead; private bool _isAsleep; + // A deep landing (HeroLanded) to lie down for, when it was raised. + private bool _isLanding; + private float _landedTime; + // This down started as a landing: its camera follows the head only with heroLandingView "move with body". + private bool _isLandingDown; + private bool _isLandingViewOnBody; + // When S_FALLEN started (-1 = T_FALL_2_FALLEN still plays). + private float _fallenStartTime = -1f; // The hands' physics before the hero went down. private readonly Dictionary _physicalBeforeDown = new(); private readonly Queue _downAnimations = new(); @@ -103,6 +122,7 @@ public void Initialize() GlobalEventDispatcher.HeroDied.AddListener(OnHeroDied); GlobalEventDispatcher.HeroFellAsleep.AddListener(OnHeroFellAsleep); GlobalEventDispatcher.HeroWokeUp.AddListener(OnHeroWokeUp); + GlobalEventDispatcher.HeroLanded.AddListener(OnHeroLanded); GlobalEventDispatcher.LoadGameStart.AddListener(OnLoadGameStart); GlobalEventDispatcher.MenuOpened.AddListener(OnMenuOpened); GlobalEventDispatcher.MenuClosed.AddListener(OnMenuClosed); @@ -116,6 +136,7 @@ public void Dispose() GlobalEventDispatcher.HeroDied.RemoveListener(OnHeroDied); GlobalEventDispatcher.HeroFellAsleep.RemoveListener(OnHeroFellAsleep); GlobalEventDispatcher.HeroWokeUp.RemoveListener(OnHeroWokeUp); + GlobalEventDispatcher.HeroLanded.RemoveListener(OnHeroLanded); GlobalEventDispatcher.LoadGameStart.RemoveListener(OnLoadGameStart); GlobalEventDispatcher.MenuOpened.RemoveListener(OnMenuOpened); GlobalEventDispatcher.MenuClosed.RemoveListener(OnMenuClosed); @@ -181,12 +202,24 @@ private void OnHeroWokeUp() _isAsleep = false; } + /// + /// Raised before the fall's damage: a deadly fall's HeroDied comes in the same frame, before UpdateDown. + /// + private void OnHeroLanded(float height, bool isDeep) + { + if (!isDeep) + return; + _isLanding = true; + _landedTime = Time.time; + } + private void OnLoadGameStart() { // A loaded game: up at once, the loading screen covers it. _isKnockedOut = false; _isDead = false; _isAsleep = false; + _isLanding = false; EndDown(); } @@ -212,8 +245,12 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig EndDown(); return false; } - if (_vrPlayerService.HeroFallMode != VrHeroFallMode.MoveWithBody || _body == null || _animator == null || - !_animator.IsValid || _headBone == null || standingScale <= 0f) + if (_isLanding && _downPhase == DownPhase.None && Time.time - _landedTime > _landingStartTimeout) + _isLanding = false; + // A deep landing lies down in either heroFallMode - "blink" is for knocked out, dead, asleep. + var isLandingOnly = !isDown && (_isLanding || _downPhase == DownPhase.Landing || _isLandingDown); + if ((_vrPlayerService.HeroFallMode != VrHeroFallMode.MoveWithBody && !isLandingOnly) || _body == null || + _animator == null || !_animator.IsValid || _headBone == null || standingScale <= 0f) { EndDown(); return false; @@ -221,7 +258,7 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig if (_downPhase == DownPhase.None) { - if (!isDown) + if (!isDown && !_isLanding) return false; StartDown(head, standingScale, feetY); } @@ -230,16 +267,24 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig { if (_downPhase == DownPhase.Knockout) SetDownAnimations(_woundedToDead, _dead); + else if (_downPhase == DownPhase.Landing) + SetDownAnimations(_deadFront); else SetDownAnimations(_standToDead, _dead); _downPhase = DownPhase.Dead; + _isLandingDown = false; } - // Knocked out while asleep (the hit woke him) or while getting up. - else if (!_isDead && _isKnockedOut && _downPhase is DownPhase.Rising or DownPhase.Asleep) + // Knocked out while asleep (the hit woke him), while getting up or lying after a fall. + else if (!_isDead && _isKnockedOut && _downPhase is DownPhase.Rising or DownPhase.Asleep + or DownPhase.Landing) { SetDownAnimations(_standToWounded, _wounded); _downPhase = DownPhase.Knockout; + _isLandingDown = false; + _isLanding = false; } + else if (!isDown && _downPhase == DownPhase.Landing) + UpdateLanding(); else if (!_isDead && !_isKnockedOut && _isAsleep && _downPhase == DownPhase.Rising) { SetDownAnimations(_standToSleep, _sleep); @@ -289,7 +334,7 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig var eyeHeight = _headBone.position.y + _neckBelowEyes * scale - feetY; if (_downStartEyeHeight < 0f) _downStartEyeHeight = eyeHeight; - if (IsRigAlive()) + if (IsRigAlive() && (!_isLandingDown || _isLandingViewOnBody)) _rig.CameraYOffset = _downBaseCameraOffset + Mathf.Max(eyeHeight, _minDownEyeHeight) - _downStartEyeHeight; @@ -301,6 +346,30 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig return true; } + /// + /// Lying after a deep fall: T_FALL_2_FALLEN to its end, S_FALLEN for HeroFallService.FallenHoldSeconds, then + /// T_FALLEN_2_STAND (Rising, which ends the down when done). S_FALLEN loops - timed, not IsDone. + /// + private void UpdateLanding() + { + if (_fallenStartTime >= 0f) + { + if (Time.time - _fallenStartTime < HeroFallService.FallenHoldSeconds) + return; + SetDownAnimations(HeroFallService.StandUpAnimation); + _downPhase = DownPhase.Rising; + _isLanding = false; + Logger.Log("[VRHeroBody] Deep landing - getting up", LogCat.VR); + return; + } + + if (_downAnimation == null || _animator.IsDone(_downAnimation)) + { + _fallenStartTime = Time.time; + SetDownAnimations(HeroFallService.FallenAnimation); + } + } + /// /// Lying on the floor (knocked out, dead, asleep), the hands follow /// the controllers without physics - the physical hands bounced on the floor and shook the lying body. @@ -366,21 +435,38 @@ private void StartDown(Transform head, float standingScale, float feetY) _bodyBones = null; SetHandsThroughFloor(true); _vrPlayerService.IsHeroBodyDown = true; + _fallenStartTime = -1f; + _isLandingDown = false; if (_isDead) { _downPhase = DownPhase.Dead; - SetDownAnimations(_standToDead, _dead); + // Killed by the fall: he lands on his front and stays there. + if (_isLanding) + SetDownAnimations(HeroFallService.DeepLandingAnimation, _deadFront); + else + SetDownAnimations(_standToDead, _dead); } else if (_isKnockedOut) { _downPhase = DownPhase.Knockout; SetDownAnimations(_standToWounded, _wounded); } - else + else if (_isAsleep) { _downPhase = DownPhase.Asleep; SetDownAnimations(_standToSleep, _sleep); } + else + { + _downPhase = DownPhase.Landing; + _isLandingDown = true; + _isLandingViewOnBody = _vrPlayerService.HeroLandingView == VrHeroLandingView.MoveWithBody; + SetDownAnimations(HeroFallService.DeepLandingAnimation); + Logger.Log("[VRHeroBody] Deep landing - body lies down, camera " + + (_isLandingViewOnBody ? "follows its head" : "stays at the player's head"), LogCat.VR); + return; + } + _isLanding = false; Logger.Log("[VRHeroBody] Hero down - body falls, camera follows its head", LogCat.VR); } @@ -401,10 +487,13 @@ private void SetDownAnimations(string first, string second = null) /// private void EndDown() { + _isLanding = false; if (_downPhase == DownPhase.None) return; _downPhase = DownPhase.None; + _isLandingDown = false; + _fallenStartTime = -1f; SetBodyShown(true); SetHandsThroughFloor(false); _vrPlayerService.IsHeroBodyDown = false; diff --git a/Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs b/Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs new file mode 100644 index 000000000..90b7661b2 --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs @@ -0,0 +1,20 @@ +namespace Gothic.VR.Models +{ + /// + /// Where the view is while the hero lies after a fall deeper than FALLDOWN_HEIGHT and gets up again + /// (VrHeroDownPose, HeroFallService's deep landing). + /// HINT: Stored as int in Gothic.ini (VRConstants.IniNames.HeroLandingView). Never change the values. + /// + public enum VrHeroLandingView + { + /// + /// The body falls, the camera stays at the player's head (less motion). + /// + StayAtHead = 0, + + /// + /// The view goes down with the body and comes back up while he stands up. + /// + MoveWithBody = 1 + } +} diff --git a/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs b/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs index 519fa7535..6c07040d9 100644 --- a/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs +++ b/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs @@ -116,6 +116,11 @@ public void UpdateMainMenu(AbstractMenuInstance mainMenu) CreateOptionChoice(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_MOVE_VIGNETTE", "moveVignette", VRConstants.IniNames.MoveVignette, VRConstants.IniSectionImmersion, VRConstants.MoveVignetteDefaultValue)), + // After a deep fall: the camera stays at the head or goes down and up with the body (VrHeroLandingView). + (CreateOptionLabel(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_HERO_LANDING_VIEW", "heroLandingView"), + CreateOptionChoice(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_HERO_LANDING_VIEW", + "heroLandingView", VRConstants.IniNames.HeroLandingView, VRConstants.IniSectionImmersion, + VRConstants.HeroLandingViewDefaultValue)), (CreateToggleLabel(gameMenu, "ITEM_DETAILS_POPUP", "itemDetailsPopup"), CreateToggleChoice(gameMenu, "ITEM_DETAILS_POPUP", VRConstants.IniNames.ItemDetailsPopup, VRConstants.ItemDetailsPopupDefaultValue)), diff --git a/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs b/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs index 0a3e308ea..16fbebecc 100644 --- a/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs +++ b/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs @@ -42,6 +42,8 @@ public class VRPlayerService // Gothic.ini heroFallMode, read on first use and again when the menu changes it. private VrHeroFallMode? _heroFallMode; + // Gothic.ini heroLandingView, the same way. + private VrHeroLandingView? _heroLandingView; private bool _hasHeroFallBody; public VRPlayerService() @@ -334,6 +336,24 @@ public VrHeroFallMode HeroFallMode } } + /// + /// The player's choice for the view while the hero lies after a deep fall and gets up (Gothic.ini + /// [GOTHIC_VR_IMMERSION] heroLandingView). Its only reader; VrHeroDownPose asks here. + /// + public VrHeroLandingView HeroLandingView + { + get + { + if (_heroLandingView.HasValue) + return _heroLandingView.Value; + if (_configService.Gothic == null) + return (VrHeroLandingView)VRConstants.HeroLandingViewDefaultValue; + _heroLandingView = (VrHeroLandingView)_configService.Gothic.GetInt(VRConstants.IniNames.HeroLandingView, + VRConstants.HeroLandingViewDefaultValue); + return _heroLandingView.Value; + } + } + /// /// The one owner of the camera height while the hero is down (knocked out, dead, asleep): true while a VR hero /// body that can fall with its camera exists and the player chose to move with it (HeroFallMode) - @@ -353,6 +373,8 @@ private void OnPlayerPrefUpdated(string key, object value) { if (key == VRConstants.IniNames.HeroFallMode) _heroFallMode = null; + if (key == VRConstants.IniNames.HeroLandingView) + _heroLandingView = null; } /// diff --git a/Assets/Gothic-VR/Scripts/Services/VrHapticsService.cs b/Assets/Gothic-VR/Scripts/Services/VrHapticsService.cs index 22730f21e..9fa0112b6 100644 --- a/Assets/Gothic-VR/Scripts/Services/VrHapticsService.cs +++ b/Assets/Gothic-VR/Scripts/Services/VrHapticsService.cs @@ -77,6 +77,8 @@ public VrHapticsService() // Gothic's camera shake GlobalEventDispatcher.VisualFxEarthquake.AddListener(OnVisualFxEarthquake); + + GlobalEventDispatcher.HeroLanded.AddListener(OnHeroLanded); } public void Dispose() @@ -108,6 +110,7 @@ public void Dispose() GlobalEventDispatcher.LedgeClimbRefused.RemoveListener(OnLedgeClimbRefused); GlobalEventDispatcher.VisualFxEarthquake.RemoveListener(OnVisualFxEarthquake); + GlobalEventDispatcher.HeroLanded.RemoveListener(OnHeroLanded); if (_earthquakeRumble != null) _unityMonoService.StopCoroutine(_earthquakeRumble); } @@ -159,6 +162,15 @@ private void OnLedgeTouched(int handSide) => private void OnLedgeClimbRefused(int handSide) => Vibrate((VrHandSide)handSide, VrHapticPreset.Error); + /// + /// A fall deeper than FALLDOWN_HEIGHT: a short strong pulse in both hands. Small landings stay quiet. + /// + private void OnHeroLanded(float height, bool isDeep) + { + if (isDeep) + BothHandsVibration(VrHapticPreset.FistHit); + } + /// /// A hand reached a body slot it can use: the slots are behind the back or out of sight. /// diff --git a/Assets/Gothic-VR/Scripts/VRConstants.cs b/Assets/Gothic-VR/Scripts/VRConstants.cs index 1c62bfd3c..85470bf8d 100644 --- a/Assets/Gothic-VR/Scripts/VRConstants.cs +++ b/Assets/Gothic-VR/Scripts/VRConstants.cs @@ -31,6 +31,10 @@ public static class IniNames // 1 = hands stop at walls and push objects (VrPhysicsHand), 0 = hands follow the controllers directly. public const string PhysicalHands = "physicalHands"; + // VrHeroLandingView: after a deep fall the body lies and gets up - 0 = the camera stays at the head, + // 1 = the view goes down and up with the body. + public const string HeroLandingView = "heroLandingView"; + // 1 = the hero's own fists are the VR hands (with the VR hero body, default), 0 = the VR hand models. public const string HeroHands = "heroHands"; // 1 = both hands on a melee weapon and both triggers held parry like Gothic (VRContextHeroBlockService), @@ -123,6 +127,7 @@ public static class IniNames public const int LedgeClimbModeDefaultValue = 0; public const int HeroFallModeDefaultValue = 0; + public const int HeroLandingViewDefaultValue = 0; public const int LedgeHintsDefaultValue = 1; public const int ItemDetailsPopupDefaultValue = 1; From 5b379c3b9158513299ef85ae52cdc9b32294cafa Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 03:37:21 +0000 Subject: [PATCH 05/41] fix: dropping through a bridge that is still loading after a world load or a loaded game is no fall - the first 2 s aren't tracked Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Services/Movement/HeroFallService.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 62aa01348..69fe971d7 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -26,7 +26,8 @@ namespace Gothic.Core.Services.Movement /// god mode ignores it). /// Not tracked (no damage): in water (water level not normal, swimming, diving, no gravity), climbing, teleported /// (OnTeleported, or a step no fall can make), transformed, down (dead, unconscious) or busy (sitting, mobs). - /// Not saved: a loaded game starts on the ground (LoadGameStart / WorldSceneLoaded reset it). + /// Not saved: a loaded game starts on the ground (LoadGameStart / WorldSceneLoaded reset it, the first seconds + /// after it aren't tracked - VOBs under the spawn point may still be loading). /// public class HeroFallService { @@ -55,6 +56,11 @@ public class HeroFallService // Why the hero isn't tracked right now (logged when it changes mid-air), null = tracked. private string _holdReason; + // Just after a world load or a loaded game, objects under the spawn point may still be loading (bridges, + // platforms): a drop through them meanwhile is no fall. + private const float _settleSeconds = 2f; + private float _settleEndTime; + /// /// The hero's phase this frame (VR hero body: which jump/fall animation). /// @@ -89,7 +95,7 @@ public void Tick(in HeroFallSample sample) if (hero?.Props == null) return; - var holdReason = GetHoldReason(hero, sample); + var holdReason = Time.time < _settleEndTime ? "world just loaded" : GetHoldReason(hero, sample); if (holdReason != null) { Hold(hero, sample.FeetY, holdReason); @@ -259,6 +265,7 @@ private void ResetAll() { _airborne.Reset(); _holdReason = null; + _settleEndTime = Time.time + _settleSeconds; Unlock(); } } From c0a3383a957d3c2e71b7b4d9e71c20d775626211 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 03:37:25 +0000 Subject: [PATCH 06/41] docs: decision record for the hero's jumps, falls and fall damage Co-Authored-By: Claude Opus 5.5 --- Docs/adr/2026-11-29-hero-jump-fall.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Docs/adr/2026-11-29-hero-jump-fall.md diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md new file mode 100644 index 000000000..ff60f3fd5 --- /dev/null +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -0,0 +1,26 @@ +# ADR: The hero's jumps, falls and fall damage + +- Date: 2026-11-29 +- Technical details: the class docs of HeroFallService and HeroAirborneDomain (Core), VrHeroJumpFall, VrHeroLocomotion and VrHeroDownPose (VR) + +## Context + +In Gothic gravity hurts the hero like everybody else: a drop deeper than his guild's safe height (5 m for humans) costs 20 hit points per meter above it, minus the armor's fall protection, and a very deep fall kills. Until now only NPCs took fall damage; the VR player could jump off any cliff unhurt. The VR hero body also showed no jump at all and its falling animation only from the falling speed, which flickered on stairs. + +In the original game the falling animation starts early and the hero then falls for a while without any harm: the falling animation, even the "deep" one, says nothing about the damage. Only the landing does. + +## Decisions + +1. **The hero takes fall damage like in Gothic, with a developer switch that is on in the released game.** The switch works with or without the combat system, NPCs keep their old behaviour (fall damage only with the combat system). Not chosen: tying it to the combat system, which is still a work-in-progress switch, so a cliff would stay harmless for many players. +2. **The damage is computed once, at the landing, from the measured drop: from the highest point of the jump or fall down to where he lands.** Below the safe height it is zero, above it the engine's rule (meters above the safe height times the damage per meter, minus fall protection, never below zero). Nothing ticks while he is in the air, and the falling animations never decide anything: a fall that plays the falling animation, even the deep one, and lands within 5 m costs nothing. A jump on flat ground only counts its own small height. Not chosen: deriving the height from the impact speed like OpenGothic, because the VR rig's top falling speed would cap it at about 20 m, so a 50 m drop would not kill. +3. **No fall damage in water, on teleports, while climbing, while transformed into a monster, while lying, and in god mode.** Water means any water level (wading, swimming, diving); a teleport is any move by the game or the player (teleport, Marvin, scripts, loading, ledge and ladder exits) and also a step no fall can make in one frame; grabbing a ladder or ledge mid-air ends the fall, and letting go starts a new one from there. A transformed hero falls as the monster's puppet: no damage, his monster's own rules are not applied. Not chosen: monster fall rules for the transformed hero, left for later. +4. **Falling plays Gothic's animations on the VR hero body:** the take-off (from standing or running, sped up so the body is already in the jump pose while the physical jump is in the air), the jump pose, the short landing; the falling pose, the deep falling pose past the safe height, the small landing. Stairs, slopes, small steps and slow lifts are no fall. +5. **After a fall deeper than the safe height the hero lands lying, stays down a moment and gets up; walking is locked meanwhile (about one and a half seconds).** Turning and the hands stay free. Both controllers give a short strong pulse. If the fall kills him, he stays lying and the usual death takes over. +6. **A new Immersion option decides the view while he lies after a deep fall: the camera stays at the player's head (default), or it goes down with the body and comes back up while he stands up.** The default spares the player a sudden drop of the view after a long fall. Not chosen: reusing the knockout view option, which is about the game taking the hero down, not about a landing the player caused. + +## Consequences + +- Nothing new is saved: a loaded game starts on the ground. +- Flat mode can feed the same rules from its own controller once it runs again. +- A knocked-out hero who falls takes no fall damage, and a dialog or video starting mid-fall does not stop the landing's damage. +- The new option needs its texts (label, description, choices) in the localization tables. From 03b5dc34fa93db50a5adcf9891d1764cf2cc7ddf Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 03:48:00 +0000 Subject: [PATCH 07/41] fix: a normal VR jump lifts the hero 1 m - the prefab's XRI jump height (0.46, a force unit) lifted him only about 0.3 m Co-Authored-By: Claude Opus 5.5 --- .../Interaction/Backends/Xri/GothicJumpProvider.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/GothicJumpProvider.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/GothicJumpProvider.cs index 34ae1b7aa..ecd8dce29 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/GothicJumpProvider.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/GothicJumpProvider.cs @@ -22,6 +22,9 @@ public class GothicJumpProvider : JumpProvider private const float _jumpHeightClamp = 4f; // Ours: upper bound of the search in GetJumpHeightForRise. private const float _maxJumpHeight = 8f; + // Ours: how high (m) a normal jump lifts the player. The prefab's jumpHeight 0.46 is XRI's force unit, not + // metres - it lifted him only ~0.3 m. It stays the lower bound. + private const float _normalJumpRise = 1f; private IVrLedgeHandler _handler; private float _gravity = 9.81f; @@ -83,10 +86,8 @@ public void CancelJump() private float GetTakeOffJumpHeight() { - var rise = _handler?.GetJumpRise() ?? 0f; - if (rise <= 0f) - return _normalJumpHeight; - + // A ledge may want a higher jump (IVrLedgeHandler), never a lower one than the normal jump. + var rise = Mathf.Max(_handler?.GetJumpRise() ?? 0f, _normalJumpRise); return Mathf.Max(_normalJumpHeight, GetJumpHeightForRise(rise, _gravity, maxJumpHoldTime, disableGravityDuringJump)); } From 4696bcf4e7e128ab7221d5cded3a38bf945bbfcf Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 03:55:09 +0000 Subject: [PATCH 08/41] feat: deeper than 2 m the hero falls flat and lands lying - on his face, or on his back when he went over the edge backwards; the damage still starts at FALLDOWN_HEIGHT The pose is decoupled from the damage: NpcFallDomain.LyingFallHeight (2 m, shared with NpcJumpFall) switches to S_FALL / S_FALLB and a lying landing (HeroFallPose: T_FALL_2_FALLEN, S_FALLEN, T_FALLEN_2_STAND or the FALLB/FALLENB set, S_DEAD/S_DEADB when it kills), the lock lasts the chosen set's animations. Backwards = horizontal movement against the facing when the fall turns flat; the face set if the model lacks the back one. A 3 m fall lands lying with damage 0. HeroLanded carries the HeroLanding. Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Npc/NpcJumpFall.cs | 5 +- .../Domain/Movement/HeroAirborneDomain.cs | 104 +++++++++++++----- .../Scripts/Domain/Npc/NpcFallDomain.cs | 6 + .../Scripts/GlobalEventDispatcher.cs | 10 +- .../Scripts/Models/Movement/HeroAirEvent.cs | 5 +- .../Scripts/Models/Movement/HeroAirPhase.cs | 2 +- .../Scripts/Models/Movement/HeroFallPose.cs | 48 ++++++++ .../Scripts/Models/Movement/HeroFallSample.cs | 20 +++- .../Scripts/Models/Movement/HeroLanding.cs | 22 +++- .../Services/Movement/HeroFallService.cs | 98 +++++++++++------ .../Movement/HeroAirborneDomainTest.cs | 92 +++++++++++----- .../Scripts/Adapters/Player/VrHeroDownPose.cs | 44 ++++---- .../Scripts/Adapters/Player/VrHeroJumpFall.cs | 18 ++- .../Adapters/Player/VrHeroLocomotion.cs | 30 +++-- .../Scripts/Services/VrHapticsService.cs | 8 +- 15 files changed, 363 insertions(+), 149 deletions(-) create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs diff --git a/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs b/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs index e733dc66c..622ecf05a 100644 --- a/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs +++ b/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs @@ -39,7 +39,6 @@ public class NpcJumpFall : MonoBehaviour, INpcJumpFall private const float _gravity = 9.81f; private const float _maxFallSpeedH = 6f; - private const float _deepFallHeight = 2f; private const float _outOfWorldFallHeight = 100f; private const float _groundProbeExtra = 0.1f; private const float _climbMinSeconds = 0.6f; @@ -271,7 +270,7 @@ private void TickFall() transform.position = position + moveH + Vector3.up * moveY; var fallen = _fallStartFeetY - (transform.position.y - RestHeight); - if (fallen > _deepFallHeight && _fallAnimName != "S_FALL") + if (fallen > NpcFallDomain.LyingFallHeight && _fallAnimName != "S_FALL") { _npc.PrefabProps.AnimationSystem.StopAnimation(_fallAnimName); _fallAnimName = "S_FALL"; @@ -293,7 +292,7 @@ private void TickFall() private void Land(float height) { _npc.PrefabProps.AnimationSystem.StopAnimation(_fallAnimName); - var isDeep = height > _deepFallHeight || _isThrown; + var isDeep = height > NpcFallDomain.LyingFallHeight || _isThrown; _isThrown = false; StartSequence(State.Landing, isDeep ? new[] { "T_FALL_2_FALLEN", "T_FALLEN_2_STAND" } diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs index c9ab1796b..0a033eab3 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs @@ -1,16 +1,19 @@ +using Gothic.Core.Domain.Npc; using Gothic.Core.Models.Movement; using UnityEngine; namespace Gothic.Core.Domain.Movement { /// - /// The hero's airborne phases from per-frame measurements (HeroFallSample): jump, fall, deep fall, landing, and + /// The hero's airborne phases from per-frame measurements (HeroFallSample): jump, fall, fall flat, landing, and /// the drop of each landing - from the highest point of the phase down to the landing point (like OpenGothic, which /// derives it from the impact speed: a jump on flat ground adds only its own small height). Pure rules, no Unity /// objects - worker of HeroFallService, which decides what is ignored (water, climbing, teleports) and what a /// landing costs. Platform-neutral: VR feeds it from the rig port, Flat can feed it from its controller. - /// - The phase is visual/body state only. Damage is never tied to it: a fall that plays S_FALLDN or even S_FALL - /// but lands within FALLDOWN_HEIGHT costs nothing; HeroFallService computes the damage once, at the landing. + /// - The phase and the pose are visual/body state only. Damage is never tied to them: a fall flat (S_FALL) from + /// 3 m lands lying and costs nothing; HeroFallService computes the damage once, at the landing, from the height. + /// - Deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs) he falls flat - on his back if he went over the edge + /// moving backwards (against his facing), else on his face - and lands lying. /// - No fall without real falling: off the ground (beyond the platform's grounded grace) the hero falls only when /// moving down faster than FallSpeed and below MinFallDrop - stairs, slopes and lifts stay walking. /// @@ -33,10 +36,17 @@ public class HeroAirborneDomain private const float _teleportTolerance = 1f; private const float _teleportRise = 2f; - private float _previousFeetY; + // Horizontal movement (m/s) that counts for the direction he goes over the edge, and how much against his + // facing is backwards (cosine). + private const float _minMoveSpeed = 0.3f; + private const float _backwardsDot = -0.3f; + + private Vector3 _previousFeet; private bool _hasPrevious; private float _lastGroundedFeetY; private bool _hasLastGrounded; + // The last real horizontal movement: kept in the air when the stick lets go, zero once standing still. + private Vector3 _moveVelocity; public HeroAirPhase Phase { get; private set; } @@ -51,48 +61,55 @@ public class HeroAirborneDomain public float TakeOffY { get; private set; } /// - /// Falling deeper than FALLDOWN_HEIGHT so far: S_FALL instead of S_FALLDN. Visual only. + /// Falling deeper than NpcFallDomain.LyingFallHeight so far: he falls flat (HeroFallPose.Flight) and will land + /// lying. Pose only. + /// + public bool IsLyingFall { get; private set; } + + /// + /// The fall flat is on his back (HeroFallPose.Back): he moved against his facing when it began. /// - public bool IsDeepFall { get; private set; } + public bool IsBackwards { get; private set; } /// - /// One frame. safeHeight: the guild's FALLDOWN_HEIGHT in m (0 = none: no deep falls). Returns what changed; - /// landing is set for HeroAirEvent.Landed only. + /// One frame. Returns what changed; landing is set for HeroAirEvent.Landed only. /// - public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLanding landing) + public HeroAirEvent Tick(in HeroFallSample sample, out HeroLanding landing) { landing = default; - var feetY = sample.FeetY; + var feet = sample.FeetPosition; var deltaTime = sample.DeltaTime; var verticalSpeed = 0f; if (_hasPrevious && deltaTime > 0f) { - var step = feetY - _previousFeetY; + var step = feet.y - _previousFeet.y; var maxDrop = Mathf.Max(sample.MaxFallSpeed, 0f) * deltaTime + _teleportTolerance; if (step > _teleportRise || step < -maxDrop) { var wasAirborne = Phase != HeroAirPhase.Grounded; - Hold(feetY); + Hold(feet); return wasAirborne ? HeroAirEvent.TeleportDetected : HeroAirEvent.None; } verticalSpeed = step / deltaTime; + UpdateMoveVelocity(feet, deltaTime, sample.IsGrounded && !sample.IsJumping); } - _previousFeetY = feetY; + _previousFeet = feet; _hasPrevious = true; if (sample.IsGrounded && !sample.IsJumping) - return TickGrounded(feetY, safeHeight, out landing); + return TickGrounded(feet.y, out landing); if (Phase == HeroAirPhase.Grounded) { // The grounded grace hides the first moments of a fall: the take-off is the last ground contact. - PeakY = _hasLastGrounded ? Mathf.Max(_lastGroundedFeetY, feetY) : feetY; + PeakY = _hasLastGrounded ? Mathf.Max(_lastGroundedFeetY, feet.y) : feet.y; TakeOffY = PeakY; - IsDeepFall = false; + IsLyingFall = false; + IsBackwards = false; Phase = HeroAirPhase.Airborne; } - PeakY = Mathf.Max(PeakY, feetY); + PeakY = Mathf.Max(PeakY, feet.y); if (Phase == HeroAirPhase.Airborne && sample.IsJumping) { @@ -100,16 +117,17 @@ public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLan return HeroAirEvent.JumpStarted; } - if (Phase is HeroAirPhase.Airborne or HeroAirPhase.Jumping && IsFalling(feetY, verticalSpeed)) + if (Phase is HeroAirPhase.Airborne or HeroAirPhase.Jumping && IsFalling(feet.y, verticalSpeed)) { Phase = HeroAirPhase.Falling; return HeroAirEvent.FallStarted; } - if (Phase == HeroAirPhase.Falling && !IsDeepFall && safeHeight > 0f && PeakY - feetY > safeHeight) + if (Phase == HeroAirPhase.Falling && !IsLyingFall && PeakY - feet.y > NpcFallDomain.LyingFallHeight) { - IsDeepFall = true; - return HeroAirEvent.DeepFallStarted; + IsLyingFall = true; + IsBackwards = IsMovingBackwards(sample.Forward); + return HeroAirEvent.LyingFallStarted; } return HeroAirEvent.None; @@ -118,13 +136,15 @@ public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLan /// /// Not tracked right now (climbing, swimming, teleported, lying...): no phase, a later fall starts from here. /// - public void Hold(float feetY) + public void Hold(Vector3 feet) { Phase = HeroAirPhase.Grounded; - IsDeepFall = false; - _previousFeetY = feetY; + IsLyingFall = false; + IsBackwards = false; + _moveVelocity = Vector3.zero; + _previousFeet = feet; _hasPrevious = true; - _lastGroundedFeetY = feetY; + _lastGroundedFeetY = feet.y; _hasLastGrounded = true; } @@ -134,27 +154,32 @@ public void Hold(float feetY) public void Reset() { Phase = HeroAirPhase.Grounded; - IsDeepFall = false; + IsLyingFall = false; + IsBackwards = false; + _moveVelocity = Vector3.zero; _hasPrevious = false; _hasLastGrounded = false; } - private HeroAirEvent TickGrounded(float feetY, float safeHeight, out HeroLanding landing) + private HeroAirEvent TickGrounded(float feetY, out HeroLanding landing) { landing = default; _lastGroundedFeetY = feetY; _hasLastGrounded = true; var phase = Phase; + var isLying = IsLyingFall; + var isBackwards = IsBackwards; Phase = HeroAirPhase.Grounded; - IsDeepFall = false; + IsLyingFall = false; + IsBackwards = false; // A step down or a flicker: no jump, no fall - no landing. if (phase is HeroAirPhase.Grounded or HeroAirPhase.Airborne) return HeroAirEvent.None; var height = Mathf.Max(0f, PeakY - feetY); - landing = new HeroLanding(height, phase == HeroAirPhase.Jumping, safeHeight > 0f && height > safeHeight); + landing = new HeroLanding(height, phase == HeroAirPhase.Jumping, isLying, isLying && isBackwards); return HeroAirEvent.Landed; } @@ -166,5 +191,26 @@ private bool IsFalling(float feetY, float verticalSpeed) return feetY < TakeOffY - _jumpFallBelowTakeOff; return verticalSpeed <= -FallSpeed && PeakY - feetY >= MinFallDrop; } + + /// + /// On the ground the current movement (zero when standing still), in the air the last real one - letting go of + /// the stick mid-air doesn't change how he went over the edge. + /// + private void UpdateMoveVelocity(Vector3 feet, float deltaTime, bool isGrounded) + { + var velocity = new Vector3(feet.x - _previousFeet.x, 0f, feet.z - _previousFeet.z) / deltaTime; + if (velocity.sqrMagnitude >= _minMoveSpeed * _minMoveSpeed) + _moveVelocity = velocity; + else if (isGrounded) + _moveVelocity = Vector3.zero; + } + + private bool IsMovingBackwards(Vector3 forward) + { + forward.y = 0f; + if (forward.sqrMagnitude < 0.0001f || _moveVelocity.sqrMagnitude < _minMoveSpeed * _minMoveSpeed) + return false; + return Vector3.Dot(_moveVelocity.normalized, forward.normalized) < _backwardsDot; + } } } diff --git a/Assets/Gothic-Core/Scripts/Domain/Npc/NpcFallDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Npc/NpcFallDomain.cs index 7b725b51b..7e46b5c5b 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Npc/NpcFallDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Npc/NpcFallDomain.cs @@ -23,6 +23,12 @@ public static class NpcFallDomain /// private const float _dropProbeDistance = 1f; + /// + /// A drop deeper than this (m) is fallen flat (S_FALL) and landed lying (T_FALL_2_FALLEN, then up again) - NPCs + /// and the hero. Only the pose: the damage starts at the guild's FALLDOWN_HEIGHT (GetFallDamage). + /// + public const float LyingFallHeight = 2f; + /// /// Both water depths (cm) of a guild mark it as flying. /// diff --git a/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs b/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs index 8582af0c6..7d546cac2 100644 --- a/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs +++ b/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs @@ -3,6 +3,7 @@ using Gothic.Core.Models.Container; using Gothic.Core.Models.Context; using Gothic.Core.Models.Doc; +using Gothic.Core.Models.Movement; using Gothic.Core.Models.Npc; using Gothic.Core.Models.Trade; using Gothic.Core.Models.UI; @@ -179,12 +180,11 @@ public enum HandSide public static readonly UnityEvent FallDamage = new(); /// - /// The hero landed after a jump or fall (HeroFallService), raised before his FallDamage. The VR hero body - /// plays the deep landing (lying, getting up), the controllers vibrate. - /// float - drop in m from the highest point of the jump/fall - /// bool - deeper than FALLDOWN_HEIGHT: he lands lying and gets up, movement locked meanwhile + /// The hero landed after a jump or fall (HeroFallService), raised before his FallDamage. A lying landing + /// (IsLying, on his face or back): the VR hero body lies down and gets up, the controllers vibrate, movement is + /// locked meanwhile. Height is the drop from the highest point; the damage depends on it alone. /// - public static readonly UnityEvent HeroLanded = new(); + public static readonly UnityEvent HeroLanded = new(); // Marvin's "kill": the NPC dies at once, no killer (no experience). public static readonly UnityEvent CheatKill = new(); diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirEvent.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirEvent.cs index 9bcc07a6f..e2d418ce1 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirEvent.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirEvent.cs @@ -10,9 +10,10 @@ public enum HeroAirEvent FallStarted, /// - /// The drop got deeper than FALLDOWN_HEIGHT: S_FALL instead of S_FALLDN (visual only). + /// The drop got deeper than NpcFallDomain.LyingFallHeight: he falls flat (S_FALL, S_FALLB backwards) and will + /// land lying. Only the pose - no damage, that's decided at the landing. /// - DeepFallStarted, + LyingFallStarted, /// /// A jump or fall ended on the ground - see HeroLanding. Stepping off a small edge ends without one. diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs index f407ffdf1..ed8b342ff 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs @@ -23,7 +23,7 @@ public enum HeroAirPhase Jumping, /// - /// Falling: S_FALLDN, S_FALL once the drop is deeper than FALLDOWN_HEIGHT (HeroAirborneDomain.IsDeepFall). + /// Falling: S_FALLDN, flat (S_FALL / S_FALLB) once deeper than 2 m (HeroAirborneDomain.IsLyingFall). /// Falling } diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs new file mode 100644 index 000000000..71e35d5a3 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs @@ -0,0 +1,48 @@ +namespace Gothic.Core.Models.Movement +{ + /// + /// The animations of a fall flat (deeper than NpcFallDomain.LyingFallHeight): on his face, or on his back when he + /// went over the edge backwards. HUMANS.MDS of G1 and G2 have both sets. + /// + public readonly struct HeroFallPose + { + public static readonly HeroFallPose Front = new("S_FALL", "T_FALL_2_FALLEN", "S_FALLEN", "T_FALLEN_2_STAND", + "S_DEAD"); + + public static readonly HeroFallPose Back = new("S_FALLB", "T_FALLB_2_FALLENB", "S_FALLENB", + "T_FALLENB_2_STAND", "S_DEADB"); + + /// + /// In the air once the drop is deeper than LyingFallHeight. + /// + public readonly string Flight; + + /// + /// Hitting the ground. + /// + public readonly string Landing; + + /// + /// Lying (a loop) for HeroFallService.FallenHoldSeconds. + /// + public readonly string Lying; + + public readonly string StandUp; + + /// + /// Killed by the fall: after Landing he stays in this pose. + /// + public readonly string Dead; + + private HeroFallPose(string flight, string landing, string lying, string standUp, string dead) + { + Flight = flight; + Landing = landing; + Lying = lying; + StandUp = standUp; + Dead = dead; + } + + public static HeroFallPose Get(bool isBackwards) => isBackwards ? Back : Front; + } +} diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs index 9b129aa57..006b8e8ce 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs @@ -1,3 +1,5 @@ +using UnityEngine; + namespace Gothic.Core.Models.Movement { /// @@ -7,9 +9,14 @@ namespace Gothic.Core.Models.Movement public readonly struct HeroFallSample { /// - /// Height of the feet (world y in m). + /// Position of the feet (world, m). /// - public readonly float FeetY; + public readonly Vector3 FeetPosition; + + /// + /// Where the hero's body faces (horizontal). Moving against it over an edge falls on his back. + /// + public readonly Vector3 Forward; /// /// On the ground - with the platform's grace time against one-frame flickers on slopes and stairs. @@ -43,10 +50,13 @@ public readonly struct HeroFallSample public readonly float DeltaTime; - public HeroFallSample(float feetY, bool isGrounded, bool isJumping, bool isClimbing, bool isTransformed, - float gravity, float maxFallSpeed, float deltaTime) + public float FeetY => FeetPosition.y; + + public HeroFallSample(Vector3 feetPosition, Vector3 forward, bool isGrounded, bool isJumping, bool isClimbing, + bool isTransformed, float gravity, float maxFallSpeed, float deltaTime) { - FeetY = feetY; + FeetPosition = feetPosition; + Forward = forward; IsGrounded = isGrounded; IsJumping = isJumping; IsClimbing = isClimbing; diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs index c4db498fb..0c4fad367 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs @@ -1,7 +1,9 @@ namespace Gothic.Core.Models.Movement { /// - /// The end of a jump or fall of the hero (HeroAirborneDomain): how deep he dropped and how he lands. + /// The end of a jump or fall of the hero (HeroAirborneDomain): how deep he dropped and how he lands. The pose + /// (IsLying, IsBackwards) and the damage are separate: the damage comes from Height alone, at the landing + /// (NpcFallDomain.GetFallDamage: 0 within FALLDOWN_HEIGHT) - a lying landing from 3 m costs nothing. /// public readonly struct HeroLanding { @@ -18,16 +20,24 @@ public readonly struct HeroLanding public readonly bool IsJump; /// - /// Deeper than the guild's FALLDOWN_HEIGHT: he lands lying (T_FALL_2_FALLEN) and gets up. Only the landing - /// animation - the damage is NpcFallDomain.GetFallDamage of Height (0 within FALLDOWN_HEIGHT, PROT_FALL off). + /// He fell flat (deeper than NpcFallDomain.LyingFallHeight): lands lying (HeroFallPose.Landing), lies a moment + /// and gets up, walking locked meanwhile. Only the pose, not the damage. /// - public readonly bool IsDeep; + public readonly bool IsLying; - public HeroLanding(float height, bool isJump, bool isDeep) + /// + /// Lying on his back (HeroFallPose.Back): he went over the edge backwards. Otherwise on his face. + /// + public readonly bool IsBackwards; + + public HeroLanding(float height, bool isJump, bool isLying, bool isBackwards) { Height = height; IsJump = isJump; - IsDeep = isDeep; + IsLying = isLying; + IsBackwards = isBackwards; } + + public HeroFallPose Pose => HeroFallPose.Get(IsBackwards); } } diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 69fe971d7..76bcf6edc 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -17,13 +17,16 @@ namespace Gothic.Core.Services.Movement { /// /// The hero's jumps and falls like the engine's: BS_JUMP / BS_FALL while in the air, fall damage at the landing - /// (DeveloperConfig.EnableHeroFallDamage), lying and getting up after a deep fall. The platform measures (VR: the + /// (DeveloperConfig.EnableHeroFallDamage), lying and getting up after a fall flat. The platform measures (VR: the /// rig port, VrHeroJumpFall) and calls Tick every frame; the phases come from HeroAirborneDomain. - /// Damage rule - one place, once per landing, never per frame and never from the fall animation: the drop from the - /// highest point of the jump/fall to the landing point, NpcFallDomain.GetFallDamage = (drop - FALLDOWN_HEIGHT) * - /// FALLDOWN_DAMAGE - PROT_FALL, at least 0. S_FALLDN starts early and S_FALL past FALLDOWN_HEIGHT is only visual: a - /// fall landing within FALLDOWN_HEIGHT (5 m for humans) costs nothing. FightService applies it (a deep fall kills, - /// god mode ignores it). + /// Pose and damage are separate rules: + /// - Pose: S_FALLDN as soon as he falls; deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs) he falls flat + /// (HeroFallPose: on his face, on his back when he went over the edge backwards) and lands lying - he lies a + /// moment and gets up, walking locked meanwhile. + /// - Damage - one place, once per landing, never per frame and never from the pose: the drop from the highest point + /// of the jump/fall to the landing point, NpcFallDomain.GetFallDamage = (drop - FALLDOWN_HEIGHT) * + /// FALLDOWN_DAMAGE - PROT_FALL, at least 0. A lying landing from 3 m costs nothing, damage starts above + /// FALLDOWN_HEIGHT (5 m for humans). FightService applies it (a deep fall kills, god mode ignores it). /// Not tracked (no damage): in water (water level not normal, swimming, diving, no gravity), climbing, teleported /// (OnTeleported, or a step no fall can make), transformed, down (dead, unconscious) or busy (sitting, mobs). /// Not saved: a loaded game starts on the ground (LoadGameStart / WorldSceneLoaded reset it, the first seconds @@ -38,16 +41,12 @@ public class HeroFallService [Inject] private readonly AnimationService _animationService; /// - /// The hero lies this long in S_FALLEN after a deep fall (T_FALL_2_FALLEN) before he gets up (T_FALLEN_2_STAND). + /// The hero lies this long (HeroFallPose.Lying) after a fall flat before he gets up (HeroFallPose.StandUp). /// public const float FallenHoldSeconds = 0.3f; - public const string DeepLandingAnimation = "T_FALL_2_FALLEN"; - public const string FallenAnimation = "S_FALLEN"; - public const string StandUpAnimation = "T_FALLEN_2_STAND"; - - // Lock after a deep landing without the hero's animations: T_FALL_2_FALLEN + S_FALLEN + T_FALLEN_2_STAND (G1). - private const float _defaultDeepLandingSeconds = 1.7f; + // Lock after a lying landing without the hero's animations: T_FALL_2_FALLEN + S_FALLEN + T_FALLEN_2_STAND (G1). + private const float _defaultLyingLandingSeconds = 1.7f; private readonly HeroAirborneDomain _airborne = new(); @@ -67,9 +66,16 @@ public class HeroFallService public HeroAirPhase Phase => _airborne.Phase; /// - /// Falling deeper than FALLDOWN_HEIGHT: S_FALL instead of S_FALLDN. Visual only - no damage until the landing. + /// Falling deeper than NpcFallDomain.LyingFallHeight: he falls flat (HeroFallPose.Flight) instead of S_FALLDN + /// and lands lying. Pose only - no damage until the landing, and only above FALLDOWN_HEIGHT. + /// + public bool IsLyingFall => _airborne.IsLyingFall; + + /// + /// The fall flat is on his back (HeroFallPose.Back) - the landing falls back to the front set when the model + /// lacks the back animations (LastLanding). /// - public bool IsDeepFall => _airborne.IsDeepFall; + public bool IsFallingBackwards => _airborne.IsBackwards; /// /// Counts the landings - a new value: LastLanding just happened (the VR hero body picks the landing animation). @@ -98,13 +104,13 @@ public void Tick(in HeroFallSample sample) var holdReason = Time.time < _settleEndTime ? "world just loaded" : GetHoldReason(hero, sample); if (holdReason != null) { - Hold(hero, sample.FeetY, holdReason); + Hold(hero, sample.FeetPosition, holdReason); return; } _holdReason = null; var safeHeight = NpcFallDomain.GetSafeFallHeight(_gameStateService.GuildValues, hero); - switch (_airborne.Tick(sample, safeHeight, out var landing)) + switch (_airborne.Tick(sample, out var landing)) { case HeroAirEvent.JumpStarted: SetAirBodyState(hero, VmGothicEnums.BodyState.BsJump); @@ -115,9 +121,10 @@ public void Tick(in HeroFallSample sample) Logger.Log($"[HeroFall] Falls from {_airborne.PeakY:F2} (FALLDOWN_HEIGHT {safeHeight:F1} m - " + "no damage within it)", LogCat.Npc); break; - case HeroAirEvent.DeepFallStarted: - Logger.Log($"[HeroFall] Deeper than FALLDOWN_HEIGHT {safeHeight:F1} m - S_FALL, the damage " + - "follows at the landing", LogCat.Npc); + case HeroAirEvent.LyingFallStarted: + Logger.Log($"[HeroFall] Deeper than {NpcFallDomain.LyingFallHeight:F1} m - falls flat " + + $"({(_airborne.IsBackwards ? "on his back" : "on his face")}), lands lying; damage " + + $"only above FALLDOWN_HEIGHT {safeHeight:F1} m, at the landing", LogCat.Npc); break; case HeroAirEvent.Landed: EndAirBodyState(hero); @@ -135,13 +142,13 @@ public void Tick(in HeroFallSample sample) /// The player was teleported (thumbstick, Marvin, AI_Teleport, spawn, loading, ledge/ladder exits): whatever /// fall ran is dropped, a new one starts at the target. /// - public void OnTeleported(float feetY) + public void OnTeleported(Vector3 feetPosition) { var hero = _npcService.GetHeroContainer(); if (hero?.Props != null) - Hold(hero, feetY, "teleported"); + Hold(hero, feetPosition, "teleported"); else - _airborne.Hold(feetY); + _airborne.Hold(feetPosition); } /// @@ -167,8 +174,9 @@ or VmGothicEnums.BodyState.BsFall : $"body state {hero.Props.BodyState}"; } - private void Hold(NpcContainer hero, float feetY, string reason) + private void Hold(NpcContainer hero, Vector3 feet, string reason) { + var feetY = feet.y; if (_airborne.Phase != HeroAirPhase.Grounded) Logger.Log($"[HeroFall] {_airborne.Phase} ended without a landing ({reason}) at {feetY:F2}, " + $"{_airborne.PeakY - feetY:F2} m below the top - no fall damage", LogCat.Npc); @@ -176,48 +184,66 @@ private void Hold(NpcContainer hero, float feetY, string reason) Logger.LogEditor($"[HeroFall] Not tracked: {reason}", LogCat.Npc); _holdReason = reason; - _airborne.Hold(feetY); + _airborne.Hold(feet); EndAirBodyState(hero); } /// - /// The landing, once: damage from the measured drop, the deep landing's lock, the event for the VR body. + /// The landing, once: damage from the measured drop alone (not the pose), the lying landing's lock, the event + /// for the VR body. /// private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, float feetY) { + // On his back only with the model's back set - else on his face. + if (landing.IsBackwards && !HasPose(hero, HeroFallPose.Back)) + { + Logger.Log("[HeroFall] No back fall animations - lands on his face", LogCat.Npc); + landing = new HeroLanding(landing.Height, landing.IsJump, landing.IsLying, false); + } LandingCount++; LastLanding = landing; var isDamageOn = _configService.Dev.EnableHeroFallDamage; var damage = NpcFallDomain.GetFallDamage(_gameStateService.GuildValues, hero, landing.Height); - var kind = landing.IsJump ? "jump" : landing.IsDeep ? "deep fall" : "fall"; + var kind = landing.IsJump ? "jump" : !landing.IsLying ? "fall" : + landing.IsBackwards ? "lying landing on his back" : "lying landing on his face"; Logger.Log($"[HeroFall] Landed ({kind}) at {feetY:F2} after {landing.Height:F2} m, FALLDOWN_HEIGHT " + $"{safeHeight:F1} m, damage {damage}" + (isDamageOn ? "" : " - not applied (DeveloperConfig.EnableHeroFallDamage off)"), LogCat.Npc); // Before the damage: a deadly fall's HeroDied comes after it, the VR body knows it lands lying. - GlobalEventDispatcher.HeroLanded.Invoke(landing.Height, landing.IsDeep); - if (landing.IsDeep) - LockForDeepLanding(hero); + GlobalEventDispatcher.HeroLanded.Invoke(landing); + if (landing.IsLying) + LockForLyingLanding(hero, landing.Pose); if (isDamageOn && damage > 0) GlobalEventDispatcher.FallDamage.Invoke(hero, damage); } /// - /// He lies and gets up: no walking or teleporting until then (turning and the hands stay free). + /// He lies and gets up: no walking or teleporting until then (turning and the hands stay free). As long as the + /// pose's landing, lying and standing up take. /// - private void LockForDeepLanding(NpcContainer hero) + private void LockForLyingLanding(NpcContainer hero, HeroFallPose pose) { - var seconds = GetAnimationSeconds(hero, DeepLandingAnimation) + FallenHoldSeconds + - GetAnimationSeconds(hero, StandUpAnimation); + var seconds = GetAnimationSeconds(hero, pose.Landing) + FallenHoldSeconds + + GetAnimationSeconds(hero, pose.StandUp); if (seconds <= FallenHoldSeconds) - seconds = _defaultDeepLandingSeconds; + seconds = _defaultLyingLandingSeconds; _contextInteractionService.LockPlayer(PlayerLocks.FallLanding, PlayerControls.Walking); _isLandingLocked = true; _landingUnlockTime = Time.time + seconds; - Logger.Log($"[HeroFall] Deep landing - movement locked for {seconds:F2} s", LogCat.Npc); + Logger.Log($"[HeroFall] Lying landing ({pose.Landing}) - movement locked for {seconds:F2} s", LogCat.Npc); + } + + /// + /// The hero's model can land in this pose and get up from it (lying itself may be missing - then he holds the + /// landing's last frame). + /// + private bool HasPose(NpcContainer hero, HeroFallPose pose) + { + return GetAnimationSeconds(hero, pose.Landing) > 0f && GetAnimationSeconds(hero, pose.StandUp) > 0f; } private float GetAnimationSeconds(NpcContainer hero, string animationName) diff --git a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs index c84d1c3a5..64cfccdd3 100644 --- a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs +++ b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs @@ -7,21 +7,25 @@ namespace Gothic.Tests.EditMode.Movement { /// /// The hero's airborne phases and the drop of a landing (HeroAirborneDomain): measured from the highest point, - /// no landing for steps and slow lifts, teleports dropped, deep falls past FALLDOWN_HEIGHT. + /// no landing for steps and slow lifts, teleports dropped, falls flat (lying landing) deeper than 2 m - on his back + /// when he went over the edge backwards. The damage isn't the domain's: only Height counts for it. /// public class HeroAirborneDomainTest { private const float _dt = 1f / 72f; private const float _gravity = 9.81f; private const float _maxFallSpeed = 20f; - private const float _safeHeight = 5f; private HeroAirborneDomain _domain; private HeroLanding _landing; private int _landings; private int _falls; - private int _deepFalls; + private int _lyingFalls; private int _teleports; + // Horizontal movement per second while falling (walking off an edge), and where the hero faces. + private Vector3 _moveVelocity; + private Vector3 _forward; + private Vector3 _feet; [SetUp] public void SetUp() @@ -30,14 +34,19 @@ public void SetUp() _landing = default; _landings = 0; _falls = 0; - _deepFalls = 0; + _lyingFalls = 0; _teleports = 0; + _moveVelocity = Vector3.zero; + _forward = Vector3.forward; + _feet = Vector3.zero; } private void Tick(float feetY, bool isGrounded, bool isJumping = false, float dt = _dt) { - var sample = new HeroFallSample(feetY, isGrounded, isJumping, false, false, _gravity, _maxFallSpeed, dt); - switch (_domain.Tick(sample, _safeHeight, out var landing)) + _feet = new Vector3(_feet.x, feetY, _feet.z) + _moveVelocity * dt; + var sample = new HeroFallSample(_feet, _forward, isGrounded, isJumping, false, false, _gravity, + _maxFallSpeed, dt); + switch (_domain.Tick(sample, out var landing)) { case HeroAirEvent.Landed: _landings++; @@ -46,8 +55,8 @@ private void Tick(float feetY, bool isGrounded, bool isJumping = false, float dt case HeroAirEvent.FallStarted: _falls++; break; - case HeroAirEvent.DeepFallStarted: - _deepFalls++; + case HeroAirEvent.LyingFallStarted: + _lyingFalls++; break; case HeroAirEvent.TeleportDetected: _teleports++; @@ -72,6 +81,7 @@ private void FallTo(float y, float groundY, float velocityY = 0f, bool isJumping y = Mathf.Max(y + velocityY * dt, groundY); Tick(y, y <= groundY, isJumping && y > groundY, dt); } + _moveVelocity = Vector3.zero; Stand(groundY, 2); } @@ -85,34 +95,63 @@ public void JumpOnFlatGroundLandsAsJumpWithItsOwnHeight() Assert.AreEqual(1, _landings); Assert.IsTrue(_landing.IsJump); - Assert.IsFalse(_landing.IsDeep); + Assert.IsFalse(_landing.IsLying); Assert.AreEqual(0, _falls); Assert.AreEqual(0.46f, _landing.Height, 0.05f); } [Test] - public void SmallFallWithinFallDownHeightIsNotDeep() + public void SmallFallLandsStanding() { - Stand(4f); - FallTo(4f, 0f); + Stand(1.5f); + FallTo(1.5f, 0f); Assert.AreEqual(1, _falls); - Assert.AreEqual(0, _deepFalls); + Assert.AreEqual(0, _lyingFalls); Assert.AreEqual(1, _landings); Assert.IsFalse(_landing.IsJump); - Assert.IsFalse(_landing.IsDeep); - Assert.AreEqual(4f, _landing.Height, 0.01f); + Assert.IsFalse(_landing.IsLying); + Assert.AreEqual(1.5f, _landing.Height, 0.01f); + } + + /// + /// Within FALLDOWN_HEIGHT (5 m) but deeper than 2 m: flat on his face and a lying landing - the damage, 0 here, + /// is HeroFallService's from Height alone. + /// + [Test] + public void ThreeMetersFallFlatAndLandLying() + { + Stand(3f); + FallTo(3f, 0f); + + Assert.AreEqual(1, _lyingFalls); + Assert.IsTrue(_landing.IsLying); + Assert.IsFalse(_landing.IsBackwards); + Assert.AreEqual(3f, _landing.Height, 0.01f); + } + + [Test] + public void WalkingBackwardsOffAnEdgeLandsOnTheBack() + { + Stand(3f); + _moveVelocity = Vector3.back * 1.2f; + Stand(3f); + FallTo(3f, 0f); + + Assert.IsTrue(_landing.IsLying); + Assert.IsTrue(_landing.IsBackwards); } [Test] - public void FallDeeperThanFallDownHeightIsDeep() + public void WalkingForwardsOffAnEdgeLandsOnTheFace() { - Stand(6f); - FallTo(6f, 0f); + Stand(3f); + _moveVelocity = Vector3.forward * 1.2f; + Stand(3f); + FallTo(3f, 0f); - Assert.AreEqual(1, _deepFalls); - Assert.IsTrue(_landing.IsDeep); - Assert.AreEqual(6f, _landing.Height, 0.01f); + Assert.IsTrue(_landing.IsLying); + Assert.IsFalse(_landing.IsBackwards); } [Test] @@ -122,6 +161,7 @@ public void FiftyMetersAtTerminalSpeedAreMeasuredNotCapped() FallTo(50f, 0f); Assert.AreEqual(0, _teleports); + Assert.IsTrue(_landing.IsLying); Assert.AreEqual(50f, _landing.Height, 0.01f); } @@ -144,7 +184,7 @@ public void JumpOffALedgeBecomesAFallFromTheJumpsTop() Assert.AreEqual(1, _falls); Assert.IsFalse(_landing.IsJump); - Assert.IsTrue(_landing.IsDeep); + Assert.IsTrue(_landing.IsLying); Assert.AreEqual(10.46f, _landing.Height, 0.05f); } @@ -195,11 +235,13 @@ public void HoldDropsTheFallAndStartsTheNextOneThere() Assert.AreEqual(HeroAirPhase.Falling, _domain.Phase); // A ladder grabbed at 18 m, let go there. - _domain.Hold(18f); - FallTo(18f, 16f); + _feet = new Vector3(_feet.x, 18f, _feet.z); + _domain.Hold(_feet); + FallTo(18f, 16.5f); Assert.AreEqual(1, _landings); - Assert.AreEqual(2f, _landing.Height, 0.01f); + Assert.IsFalse(_landing.IsLying); + Assert.AreEqual(1.5f, _landing.Height, 0.01f); } } } diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs index 06aef5f77..7f3afcb41 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs @@ -3,6 +3,7 @@ using Gothic.Core; using Gothic.Core.Logging; using Gothic.Core.Models.Container; +using Gothic.Core.Models.Movement; using Gothic.Core.Models.Vm; using Gothic.Core.Services.Movement; using Gothic.Core.Services.Npc; @@ -27,10 +28,11 @@ namespace Gothic.VR.Adapters.Player /// stays yours. It only follows the hero's events: FightService decides death and the locks, VRPlayer opens the /// death menu. Tells VRPlayerService whether a body that can fall exists (SetHeroFallBody); "blink" leaves the /// view to VrKnockoutView. - /// A fall deeper than FALLDOWN_HEIGHT (HeroLanded, deep) lands him lying - T_FALL_2_FALLEN, S_FALLEN for - /// HeroFallService.FallenHoldSeconds, T_FALLEN_2_STAND - whatever heroFallMode is; the Immersion option - /// heroLandingView decides whether the camera goes with the head (VRPlayerService.HeroLandingView, default: it stays - /// at the player's head). HeroFallService locks walking meanwhile. Killed by the fall, he stays lying dead (S_DEAD). + /// A fall flat (HeroLanded, IsLying: deeper than 2 m - not tied to the damage) lands him lying in the landing's + /// HeroFallPose - on his face T_FALL_2_FALLEN, S_FALLEN for HeroFallService.FallenHoldSeconds, T_FALLEN_2_STAND, on + /// his back the same with FALLB/FALLENB - whatever heroFallMode is; the Immersion option heroLandingView decides + /// whether the camera goes with the head (VRPlayerService.HeroLandingView, default: it stays at the player's head). + /// HeroFallService locks walking meanwhile. Killed by the fall, he stays lying dead (S_DEAD, on his back S_DEADB). /// Worker of VRHeroBody (new().Inject(), Initialize, Bind, Dispose). /// public class VrHeroDownPose @@ -44,7 +46,7 @@ private enum DownPhase Knockout, Asleep, Dead, - // After a deep fall, until he starts getting up (Rising). + // After a fall flat, until he starts getting up (Rising). Landing, Rising } @@ -59,8 +61,6 @@ private enum DownPhase private const string _standToSleep = "T_STAND_2_VICTIM_SLE"; private const string _sleep = "S_VICTIM_SLE"; private const string _sleepToStand = "T_VICTIM_SLE_2_STAND"; - // Killed by a fall: lying on his front like S_FALLEN. - private const string _deadFront = "S_DEAD"; // A landing not started within this time (no body update meanwhile) is forgotten. private const float _landingStartTimeout = 0.5f; @@ -76,8 +76,9 @@ private enum DownPhase private bool _isKnockedOut; private bool _isDead; private bool _isAsleep; - // A deep landing (HeroLanded) to lie down for, when it was raised. + // A lying landing (HeroLanded) to lie down for, when it was raised, and its pose (face or back). private bool _isLanding; + private HeroFallPose _landingPose = HeroFallPose.Front; private float _landedTime; // This down started as a landing: its camera follows the head only with heroLandingView "move with body". private bool _isLandingDown; @@ -205,10 +206,11 @@ private void OnHeroWokeUp() /// /// Raised before the fall's damage: a deadly fall's HeroDied comes in the same frame, before UpdateDown. /// - private void OnHeroLanded(float height, bool isDeep) + private void OnHeroLanded(HeroLanding landing) { - if (!isDeep) + if (!landing.IsLying) return; + _landingPose = landing.Pose; _isLanding = true; _landedTime = Time.time; } @@ -247,7 +249,7 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig } if (_isLanding && _downPhase == DownPhase.None && Time.time - _landedTime > _landingStartTimeout) _isLanding = false; - // A deep landing lies down in either heroFallMode - "blink" is for knocked out, dead, asleep. + // A lying landing lies down in either heroFallMode - "blink" is for knocked out, dead, asleep. var isLandingOnly = !isDown && (_isLanding || _downPhase == DownPhase.Landing || _isLandingDown); if ((_vrPlayerService.HeroFallMode != VrHeroFallMode.MoveWithBody && !isLandingOnly) || _body == null || _animator == null || !_animator.IsValid || _headBone == null || standingScale <= 0f) @@ -268,7 +270,7 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig if (_downPhase == DownPhase.Knockout) SetDownAnimations(_woundedToDead, _dead); else if (_downPhase == DownPhase.Landing) - SetDownAnimations(_deadFront); + SetDownAnimations(_landingPose.Dead); else SetDownAnimations(_standToDead, _dead); _downPhase = DownPhase.Dead; @@ -347,8 +349,8 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig } /// - /// Lying after a deep fall: T_FALL_2_FALLEN to its end, S_FALLEN for HeroFallService.FallenHoldSeconds, then - /// T_FALLEN_2_STAND (Rising, which ends the down when done). S_FALLEN loops - timed, not IsDone. + /// Lying after a fall flat: the pose's landing to its end, lying for HeroFallService.FallenHoldSeconds, then + /// standing up (Rising, which ends the down when done). Lying loops - timed, not IsDone. /// private void UpdateLanding() { @@ -356,17 +358,17 @@ private void UpdateLanding() { if (Time.time - _fallenStartTime < HeroFallService.FallenHoldSeconds) return; - SetDownAnimations(HeroFallService.StandUpAnimation); + SetDownAnimations(_landingPose.StandUp); _downPhase = DownPhase.Rising; _isLanding = false; - Logger.Log("[VRHeroBody] Deep landing - getting up", LogCat.VR); + Logger.Log($"[VRHeroBody] Lying landing - getting up ({_landingPose.StandUp})", LogCat.VR); return; } if (_downAnimation == null || _animator.IsDone(_downAnimation)) { _fallenStartTime = Time.time; - SetDownAnimations(HeroFallService.FallenAnimation); + SetDownAnimations(_landingPose.Lying); } } @@ -440,9 +442,9 @@ private void StartDown(Transform head, float standingScale, float feetY) if (_isDead) { _downPhase = DownPhase.Dead; - // Killed by the fall: he lands on his front and stays there. + // Killed by the fall: he lands on his face or back and stays there. if (_isLanding) - SetDownAnimations(HeroFallService.DeepLandingAnimation, _deadFront); + SetDownAnimations(_landingPose.Landing, _landingPose.Dead); else SetDownAnimations(_standToDead, _dead); } @@ -461,8 +463,8 @@ private void StartDown(Transform head, float standingScale, float feetY) _downPhase = DownPhase.Landing; _isLandingDown = true; _isLandingViewOnBody = _vrPlayerService.HeroLandingView == VrHeroLandingView.MoveWithBody; - SetDownAnimations(HeroFallService.DeepLandingAnimation); - Logger.Log("[VRHeroBody] Deep landing - body lies down, camera " + + SetDownAnimations(_landingPose.Landing); + Logger.Log($"[VRHeroBody] Lying landing ({_landingPose.Landing}) - body lies down, camera " + (_isLandingViewOnBody ? "follows its head" : "stays at the player's head"), LogCat.VR); return; } diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs index 507a0acd4..5d5dcdff7 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs @@ -43,15 +43,25 @@ private void OnDestroy() private void Update() { - var sample = new HeroFallSample(_rig.Root.position.y, _rig.IsGrounded, _rig.IsJumping, _rig.IsClimbing, - _vrSpellTransformService != null && _vrSpellTransformService.IsTransformed, _rig.Gravity, - _rig.MaxFallSpeed, Time.deltaTime); + var sample = new HeroFallSample(_rig.Root.position, GetFacing(), _rig.IsGrounded, _rig.IsJumping, + _rig.IsClimbing, _vrSpellTransformService != null && _vrSpellTransformService.IsTransformed, + _rig.Gravity, _rig.MaxFallSpeed, Time.deltaTime); _heroFallService.Tick(sample); } + /// + /// Where the hero faces: the head's direction (the VR hero body turns after it), the rig's when looking + /// straight down or up. + /// + private Vector3 GetFacing() + { + var forward = Vector3.ProjectOnPlane(_rig.Head.forward, Vector3.up); + return forward.sqrMagnitude > 0.01f ? forward : Vector3.ProjectOnPlane(_rig.Root.forward, Vector3.up); + } + private void OnTeleported(Vector3 feetPosition) { - _heroFallService.OnTeleported(feetPosition.y); + _heroFallService.OnTeleported(feetPosition); } } } diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs index 48da773f3..298f89733 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs @@ -38,17 +38,16 @@ public class VrHeroLocomotion private const string _walkBackAnimation = "S_WALKBL"; private const string _fallAnimation = "S_FALLDN"; - // Jumps and falls: take-off -> S_JUMP -> landing, S_FALLDN -> S_FALL (deeper than FALLDOWN_HEIGHT) -> landing. + // Jumps and falls: take-off -> S_JUMP -> landing, S_FALLDN -> S_FALL / S_FALLB (deeper than 2 m) -> landing. private const string _standToJump = "T_STAND_2_JUMP"; private const string _runToJump = "T_RUNL_2_JUMP"; private const string _jumpAnimation = "S_JUMP"; private const string _jumpToStand = "T_JUMP_2_STAND"; // Not in G1's HUMANS.MDS: landing from a run goes straight on running then. private const string _jumpToRun = "T_JUMP_2_RUNL"; - private const string _deepFallAnimation = "S_FALL"; private const string _fallToStand = "T_FALLDN_2_STAND"; - // The take-off (G1: 0.96 s, the body rising 0.6 m) is over this fast - the physics jump (~0.46 m) is already in - // the air, the body should be in S_JUMP for it. + // The take-off (G1: 0.96 s, the body rising 0.6 m) is over this fast - the physics jump (~1 m rise) is + // already in the air, the body should be in S_JUMP for it. private const float _takeOffSeconds = 0.3f; private HeroAirPhase _airPhase; private int _landingCount; @@ -243,9 +242,7 @@ private bool TryPlayAirAnimation(float speed, bool isMoving) return PlayAirOneShot(false) || _animator.Play(_jumpAnimation); case HeroAirPhase.Falling: _airOneShot = null; - return _animator.Play(_heroFallService.IsDeepFall && _animator.HasAnimation(_deepFallAnimation) - ? _deepFallAnimation - : _fallAnimation); + return _animator.Play(GetFallAnimation()); } if (isNewLanding) @@ -254,13 +251,28 @@ private bool TryPlayAirAnimation(float speed, bool isMoving) } /// - /// Small landings only - a deep one lies down and gets up (VrHeroDownPose). Moving on: straight into the walk. + /// S_FALLDN, deeper than NpcFallDomain.LyingFallHeight flat: S_FALL on his face, S_FALLB on his back (the face + /// set if the model has no S_FALLB). + /// + private string GetFallAnimation() + { + if (!_heroFallService.IsLyingFall) + return _fallAnimation; + var flight = HeroFallPose.Get(_heroFallService.IsFallingBackwards).Flight; + if (_animator.HasAnimation(flight)) + return flight; + return _animator.HasAnimation(HeroFallPose.Front.Flight) ? HeroFallPose.Front.Flight : _fallAnimation; + } + + /// + /// Standing landings only - a lying one lies down and gets up (VrHeroDownPose). Moving on: straight into the + /// walk. /// private void StartLanding(float speed, bool isMoving) { _airOneShot = null; var landing = _heroFallService.LastLanding; - if (landing.IsDeep) + if (landing.IsLying) return; var isRunning = speed >= _vrPlayerService.HeroSpeeds.RunThreshold; diff --git a/Assets/Gothic-VR/Scripts/Services/VrHapticsService.cs b/Assets/Gothic-VR/Scripts/Services/VrHapticsService.cs index 9fa0112b6..2cf248339 100644 --- a/Assets/Gothic-VR/Scripts/Services/VrHapticsService.cs +++ b/Assets/Gothic-VR/Scripts/Services/VrHapticsService.cs @@ -4,6 +4,7 @@ using Gothic.Core.Logging; using Gothic.Core.Manager; using Gothic.Core.Models.Container; +using Gothic.Core.Models.Movement; using Gothic.VR.Interaction.Models; using Gothic.VR.Interaction.Ports; using Reflex.Attributes; @@ -163,11 +164,12 @@ private void OnLedgeTouched(int handSide) => private void OnLedgeClimbRefused(int handSide) => Vibrate((VrHandSide)handSide, VrHapticPreset.Error); /// - /// A fall deeper than FALLDOWN_HEIGHT: a short strong pulse in both hands. Small landings stay quiet. + /// A lying landing (a fall flat, deeper than 2 m): a short strong pulse in both hands. Standing landings stay + /// quiet. /// - private void OnHeroLanded(float height, bool isDeep) + private void OnHeroLanded(HeroLanding landing) { - if (isDeep) + if (landing.IsLying) BothHandsVibration(VrHapticPreset.FistHit); } From 505f6805a7647e14cea7de658506040d61c7344b Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 03:55:13 +0000 Subject: [PATCH 09/41] docs: the jump/fall decision record - falling flat from 2 m, on the face or the back, separate from the damage Co-Authored-By: Claude Opus 5.5 --- Docs/adr/2026-11-29-hero-jump-fall.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md index ff60f3fd5..d17e37052 100644 --- a/Docs/adr/2026-11-29-hero-jump-fall.md +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -12,11 +12,13 @@ In the original game the falling animation starts early and the hero then falls ## Decisions 1. **The hero takes fall damage like in Gothic, with a developer switch that is on in the released game.** The switch works with or without the combat system, NPCs keep their old behaviour (fall damage only with the combat system). Not chosen: tying it to the combat system, which is still a work-in-progress switch, so a cliff would stay harmless for many players. -2. **The damage is computed once, at the landing, from the measured drop: from the highest point of the jump or fall down to where he lands.** Below the safe height it is zero, above it the engine's rule (meters above the safe height times the damage per meter, minus fall protection, never below zero). Nothing ticks while he is in the air, and the falling animations never decide anything: a fall that plays the falling animation, even the deep one, and lands within 5 m costs nothing. A jump on flat ground only counts its own small height. Not chosen: deriving the height from the impact speed like OpenGothic, because the VR rig's top falling speed would cap it at about 20 m, so a 50 m drop would not kill. +2. **The damage is computed once, at the landing, from the measured drop: from the highest point of the jump or fall down to where he lands.** Below the safe height it is zero, above it the engine's rule (meters above the safe height times the damage per meter, minus fall protection, never below zero). Nothing ticks while he is in the air, and the falling animations never decide anything: a fall that plays the falling animation, even falling flat and landing lying, and lands within 5 m costs nothing. A jump on flat ground only counts its own small height. Not chosen: deriving the height from the impact speed like OpenGothic, because the VR rig's top falling speed would cap it at about 20 m, so a 50 m drop would not kill. 3. **No fall damage in water, on teleports, while climbing, while transformed into a monster, while lying, and in god mode.** Water means any water level (wading, swimming, diving); a teleport is any move by the game or the player (teleport, Marvin, scripts, loading, ledge and ladder exits) and also a step no fall can make in one frame; grabbing a ladder or ledge mid-air ends the fall, and letting go starts a new one from there. A transformed hero falls as the monster's puppet: no damage, his monster's own rules are not applied. Not chosen: monster fall rules for the transformed hero, left for later. -4. **Falling plays Gothic's animations on the VR hero body:** the take-off (from standing or running, sped up so the body is already in the jump pose while the physical jump is in the air), the jump pose, the short landing; the falling pose, the deep falling pose past the safe height, the small landing. Stairs, slopes, small steps and slow lifts are no fall. -5. **After a fall deeper than the safe height the hero lands lying, stays down a moment and gets up; walking is locked meanwhile (about one and a half seconds).** Turning and the hands stay free. Both controllers give a short strong pulse. If the fall kills him, he stays lying and the usual death takes over. -6. **A new Immersion option decides the view while he lies after a deep fall: the camera stays at the player's head (default), or it goes down with the body and comes back up while he stands up.** The default spares the player a sudden drop of the view after a long fall. Not chosen: reusing the knockout view option, which is about the game taking the hero down, not about a landing the player caused. +4. **Falling plays Gothic's animations on the VR hero body:** the take-off (from standing or running, sped up so the body is already in the jump pose while the physical jump is in the air), the jump pose, the short landing; the falling pose, then falling flat, the small landing. Stairs, slopes, small steps and slow lifts are no fall. +5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. +6. **He falls on his back when he went over the edge moving backwards (against where he faces), otherwise on his face.** Each side has its own landing, lying and getting up; if the hero's model lacks the back set, he falls on his face. +7. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** Turning and the hands stay free. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. +8. **A new Immersion option decides the view while he lies after a fall flat: the camera stays at the player's head (default), or it goes down with the body and comes back up while he stands up.** The default spares the player a sudden drop of the view after a long fall. Not chosen: reusing the knockout view option, which is about the game taking the hero down, not about a landing the player caused. ## Consequences From ef3fdcce7c38351980c1eb810fe5728f6e8a6b75 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 04:07:57 +0000 Subject: [PATCH 10/41] chore: meta files of the jump/fall scripts (generated by Unity on import) and EnableHeroFallDamage on in Production Co-Authored-By: Claude Opus 5.5 --- .../Resources/DeveloperConfigs/Production.asset | 1 + .../Scripts/Domain/Movement/HeroAirborneDomain.cs.meta | 2 ++ .../Scripts/Models/Movement/HeroAirEvent.cs.meta | 2 ++ .../Scripts/Models/Movement/HeroAirPhase.cs.meta | 2 ++ .../Scripts/Models/Movement/HeroFallPose.cs.meta | 2 ++ .../Scripts/Models/Movement/HeroFallSample.cs.meta | 2 ++ .../Scripts/Models/Movement/HeroLanding.cs.meta | 2 ++ .../Scripts/Services/Movement/HeroFallService.cs.meta | 2 ++ Assets/Gothic-Tests/EditMode/Movement.meta | 8 ++++++++ .../EditMode/Movement/HeroAirborneDomainTest.cs.meta | 2 ++ .../Scripts/Adapters/Player/VrHeroJumpFall.cs.meta | 2 ++ Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs.meta | 2 ++ 12 files changed, 29 insertions(+) create mode 100644 Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs.meta create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroAirEvent.cs.meta create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs.meta create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs.meta create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs.meta create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs.meta create mode 100644 Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs.meta create mode 100644 Assets/Gothic-Tests/EditMode/Movement.meta create mode 100644 Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs.meta create mode 100644 Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs.meta create mode 100644 Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs.meta diff --git a/Assets/Gothic-Core/Resources/DeveloperConfigs/Production.asset b/Assets/Gothic-Core/Resources/DeveloperConfigs/Production.asset index dfc440af2..f6ab967a1 100644 --- a/Assets/Gothic-Core/Resources/DeveloperConfigs/Production.asset +++ b/Assets/Gothic-Core/Resources/DeveloperConfigs/Production.asset @@ -55,6 +55,7 @@ MonoBehaviour: ShowCapsuleOverlapGizmos: 0 EnableNpcs: 1 EnableCombatSystem: 1 + EnableHeroFallDamage: 1 EnableNpcMeshCulling: 1 NpcCullingDistance: 50 SpawnNpcInstances: diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs.meta b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs.meta new file mode 100644 index 000000000..8411c5edb --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 7e2f6abb449e3fe4281a8da21523ed4f \ No newline at end of file diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirEvent.cs.meta b/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirEvent.cs.meta new file mode 100644 index 000000000..d9ff47e7a --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirEvent.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: fdd32d7a7e54ab64ba4d1e012173cff0 \ No newline at end of file diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs.meta b/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs.meta new file mode 100644 index 000000000..b2cecadcf --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroAirPhase.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 41d43ec34f83834469e7b0f1859bc0aa \ No newline at end of file diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs.meta b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs.meta new file mode 100644 index 000000000..4d4456a36 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 51ed26a7ac881924c8e01160e9a8d3a1 \ No newline at end of file diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs.meta b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs.meta new file mode 100644 index 000000000..121c14f12 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 80fdb44021da5fa4087f7ad92d945142 \ No newline at end of file diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs.meta b/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs.meta new file mode 100644 index 000000000..b43c7f032 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: a92760995c8c38549a854717c64c2d19 \ No newline at end of file diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs.meta b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs.meta new file mode 100644 index 000000000..da388a767 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ce784740e830f8a4985edd436611f052 \ No newline at end of file diff --git a/Assets/Gothic-Tests/EditMode/Movement.meta b/Assets/Gothic-Tests/EditMode/Movement.meta new file mode 100644 index 000000000..cd5a82838 --- /dev/null +++ b/Assets/Gothic-Tests/EditMode/Movement.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b094c23e744d8e6479a7c412d53eddb9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs.meta b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs.meta new file mode 100644 index 000000000..09e708049 --- /dev/null +++ b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: a7be32d4688ff9844a2c25066e77d25c \ No newline at end of file diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs.meta b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs.meta new file mode 100644 index 000000000..3d3a92804 --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: acc01661ae71a9f459499f85dd49ea7b \ No newline at end of file diff --git a/Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs.meta b/Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs.meta new file mode 100644 index 000000000..e4e1332ee --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 0209773e6a5a490458296fb94a792e18 \ No newline at end of file From ea2af83ea38d10d17adc8a01c97042f8c37e0ef3 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 04:17:31 +0000 Subject: [PATCH 11/41] fix: a jump that lands up to 2 m below its take-off lands on his feet - the jump's own rise no longer lays the hero on his face HeroAirborneDomain measures the lying depth of a jump from its take-off (LyingReferenceY), a fall from its start; a jump stays a jump (S_JUMP, the jump's landing) until that deep. The damage height is still from the top. Tests: a running jump down a slope landing 1.5 m lower lands as a jump, a jump off a 3 m ledge lands lying. Co-Authored-By: Claude Opus 5.5 --- .../Domain/Movement/HeroAirborneDomain.cs | 24 +++++++++++--- .../Services/Movement/HeroFallService.cs | 9 +++--- .../Movement/HeroAirborneDomainTest.cs | 32 +++++++++++++++++++ 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs index 0a033eab3..e1c124237 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs @@ -13,7 +13,9 @@ namespace Gothic.Core.Domain.Movement /// - The phase and the pose are visual/body state only. Damage is never tied to them: a fall flat (S_FALL) from /// 3 m lands lying and costs nothing; HeroFallService computes the damage once, at the landing, from the height. /// - Deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs) he falls flat - on his back if he went over the edge - /// moving backwards (against his facing), else on his face - and lands lying. + /// moving backwards (against his facing), else on his face - and lands lying. A fall measures it from where it + /// started, a jump from its take-off: the jump's own rise doesn't count, a running jump down a slope landing + /// 1.5 m lower lands on his feet. A jump stays a jump (S_JUMP, the jump's landing) until that deep. /// - No fall without real falling: off the ground (beyond the platform's grounded grace) the hero falls only when /// moving down faster than FallSpeed and below MinFallDrop - stairs, slopes and lifts stay walking. /// @@ -29,8 +31,6 @@ public class HeroAirborneDomain /// public const float MinFallDrop = 0.3f; - // A jump that drops this far below its take-off (off a ledge) becomes a fall: S_FALLDN, the fall's landing. - private const float _jumpFallBelowTakeOff = 0.5f; // One frame's step beyond what falling (terminal speed) or jumping can do: a teleport nobody announced. private const float _teleportTolerance = 1f; @@ -47,6 +47,8 @@ public class HeroAirborneDomain private bool _hasLastGrounded; // The last real horizontal movement: kept in the air when the stick lets go, zero once standing still. private Vector3 _moveVelocity; + // The phase began as the hero's jump: the lying depth counts from the take-off, not from the jump's top. + private bool _isFromJump; public HeroAirPhase Phase { get; private set; } @@ -71,6 +73,12 @@ public class HeroAirborneDomain /// public bool IsBackwards { get; private set; } + /// + /// Where the depth for falling flat is measured from: a jump's take-off, else the fall's start (its top). + /// The landing's damage height is always from the top (PeakY). + /// + public float LyingReferenceY => _isFromJump ? TakeOffY : PeakY; + /// /// One frame. Returns what changed; landing is set for HeroAirEvent.Landed only. /// @@ -107,6 +115,7 @@ public HeroAirEvent Tick(in HeroFallSample sample, out HeroLanding landing) TakeOffY = PeakY; IsLyingFall = false; IsBackwards = false; + _isFromJump = false; Phase = HeroAirPhase.Airborne; } PeakY = Mathf.Max(PeakY, feet.y); @@ -114,6 +123,7 @@ public HeroAirEvent Tick(in HeroFallSample sample, out HeroLanding landing) if (Phase == HeroAirPhase.Airborne && sample.IsJumping) { Phase = HeroAirPhase.Jumping; + _isFromJump = true; return HeroAirEvent.JumpStarted; } @@ -123,7 +133,8 @@ public HeroAirEvent Tick(in HeroFallSample sample, out HeroLanding landing) return HeroAirEvent.FallStarted; } - if (Phase == HeroAirPhase.Falling && !IsLyingFall && PeakY - feet.y > NpcFallDomain.LyingFallHeight) + if (Phase == HeroAirPhase.Falling && !IsLyingFall && + LyingReferenceY - feet.y > NpcFallDomain.LyingFallHeight) { IsLyingFall = true; IsBackwards = IsMovingBackwards(sample.Forward); @@ -141,6 +152,7 @@ public void Hold(Vector3 feet) Phase = HeroAirPhase.Grounded; IsLyingFall = false; IsBackwards = false; + _isFromJump = false; _moveVelocity = Vector3.zero; _previousFeet = feet; _hasPrevious = true; @@ -156,6 +168,7 @@ public void Reset() Phase = HeroAirPhase.Grounded; IsLyingFall = false; IsBackwards = false; + _isFromJump = false; _moveVelocity = Vector3.zero; _hasPrevious = false; _hasLastGrounded = false; @@ -187,8 +200,9 @@ private bool IsFalling(float feetY, float verticalSpeed) { if (verticalSpeed >= 0f) return false; + // A jump becomes a fall only once it's deeper than the lying depth below its take-off. if (Phase == HeroAirPhase.Jumping) - return feetY < TakeOffY - _jumpFallBelowTakeOff; + return feetY < TakeOffY - NpcFallDomain.LyingFallHeight; return verticalSpeed <= -FallSpeed && PeakY - feetY >= MinFallDrop; } diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 76bcf6edc..1004b9101 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -20,9 +20,9 @@ namespace Gothic.Core.Services.Movement /// (DeveloperConfig.EnableHeroFallDamage), lying and getting up after a fall flat. The platform measures (VR: the /// rig port, VrHeroJumpFall) and calls Tick every frame; the phases come from HeroAirborneDomain. /// Pose and damage are separate rules: - /// - Pose: S_FALLDN as soon as he falls; deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs) he falls flat - /// (HeroFallPose: on his face, on his back when he went over the edge backwards) and lands lying - he lies a - /// moment and gets up, walking locked meanwhile. + /// - Pose: S_FALLDN as soon as he falls; deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs; a jump below + /// its take-off, not its top) he falls flat (HeroFallPose: on his face, on his back when he went over the edge + /// backwards) and lands lying - he lies a moment and gets up, walking locked meanwhile. /// - Damage - one place, once per landing, never per frame and never from the pose: the drop from the highest point /// of the jump/fall to the landing point, NpcFallDomain.GetFallDamage = (drop - FALLDOWN_HEIGHT) * /// FALLDOWN_DAMAGE - PROT_FALL, at least 0. A lying landing from 3 m costs nothing, damage starts above @@ -122,7 +122,8 @@ public void Tick(in HeroFallSample sample) "no damage within it)", LogCat.Npc); break; case HeroAirEvent.LyingFallStarted: - Logger.Log($"[HeroFall] Deeper than {NpcFallDomain.LyingFallHeight:F1} m - falls flat " + + Logger.Log($"[HeroFall] More than {NpcFallDomain.LyingFallHeight:F1} m below " + + $"{_airborne.LyingReferenceY:F2} (jump take-off or fall start) - falls flat " + $"({(_airborne.IsBackwards ? "on his back" : "on his face")}), lands lying; damage " + $"only above FALLDOWN_HEIGHT {safeHeight:F1} m, at the landing", LogCat.Npc); break; diff --git a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs index 64cfccdd3..cddc675d2 100644 --- a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs +++ b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs @@ -175,6 +175,38 @@ public void HitchesDontLookLikeTeleports() Assert.AreEqual(30f, _landing.Height, 0.01f); } + /// + /// The VR jump's rise (1 m) doesn't count for falling flat: 1.5 m below the take-off is 2.5 m below the top, + /// but he lands on his feet - the damage height is still from the top. + /// + [Test] + public void RunningJumpDownASlopeLandsOnHisFeet() + { + Stand(0f); + Tick(0f, true, true); + FallTo(0f, -1.5f, 4.43f, true); + + Assert.AreEqual(0, _falls); + Assert.AreEqual(0, _lyingFalls); + Assert.IsTrue(_landing.IsJump); + Assert.IsFalse(_landing.IsLying); + Assert.AreEqual(2.5f, _landing.Height, 0.05f); + } + + [Test] + public void JumpOffAThreeMeterLedgeLandsLying() + { + Stand(3f); + Tick(3f, true, true); + FallTo(3f, 0f, 4.43f, true); + + Assert.AreEqual(1, _falls); + Assert.AreEqual(1, _lyingFalls); + Assert.IsFalse(_landing.IsJump); + Assert.IsTrue(_landing.IsLying); + Assert.AreEqual(4f, _landing.Height, 0.05f); + } + [Test] public void JumpOffALedgeBecomesAFallFromTheJumpsTop() { From 3d1288650493aabdb5c00edcb9647c37c3f88fa8 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 04:17:37 +0000 Subject: [PATCH 12/41] feat: a jump at running speed is Gothic's running jump - a long leap at T_RUNL_2_JUMP's speed in the direction of the run VrHeroJumpFall starts the leap when a jump begins at or above VrHeroSpeeds.RunThreshold: IVrRig.SetLeapVelocity (new port member) with VrHeroSpeeds.RunJump - T_RUNL_2_JUMP's root motion at the body's scale (VrHeroLocomotion.UpdateSpeeds), else 1.6x the run. XriRig moves the CharacterController at that velocity with the stick's movement off until it lands, climbs or is teleported; water, a ledge or a teleport also end it from HeroFallService's phase. The standing and walking jump stays vertical, both rise 1 m. Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Player/VrHeroJumpFall.cs | 76 ++++++++++++++++++- .../Adapters/Player/VrHeroLocomotion.cs | 5 +- .../Interaction/Backends/Xri/XriRig.cs | 34 +++++++++ .../Scripts/Interaction/Ports/IVrRig.cs | 10 +++ .../Gothic-VR/Scripts/Models/VrHeroSpeeds.cs | 22 +++++- 5 files changed, 139 insertions(+), 8 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs index 5d5dcdff7..681371492 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs @@ -11,16 +11,28 @@ namespace Gothic.VR.Adapters.Player { /// - /// Feeds the hero's jumps and falls (HeroFallService: body state, fall damage, deep landing) from the VR rig port: + /// Feeds the hero's jumps and falls (HeroFallService: body state, fall damage, lying landing) from the VR rig port: /// feet height, grounded (with the rig's grace time), jumping, climbing, gravity, teleports. Measures only - the /// rules are in Core. Sits next to VRPlayer (added by VRContextInteractionService). + /// A jump taken at running speed (VrHeroSpeeds.RunThreshold, the sprint) is Gothic's running jump: a long leap at + /// T_RUNL_2_JUMP's forward speed (VrHeroSpeeds.RunJump) in the direction of the run, until he lands, grabs or is + /// teleported (IVrRig.SetLeapVelocity). The standing and walking jump stays straight up. /// public class VrHeroJumpFall : MonoBehaviour { [Inject] private readonly HeroFallService _heroFallService; [Inject] private readonly VRSpellTransformService _vrSpellTransformService; + [Inject] private readonly VRPlayerService _vrPlayerService; + + // The horizontal velocity is smoothed over a few frames - a single frame's step jitters. + private const float _velocitySmoothing = 0.5f; private IVrRig _rig; + private Vector3 _lastFeet; + private bool _hasLastFeet; + private Vector3 _horizontalVelocity; + private HeroAirPhase _lastPhase; + private bool _isLeaping; private void Awake() { @@ -43,10 +55,63 @@ private void OnDestroy() private void Update() { - var sample = new HeroFallSample(_rig.Root.position, GetFacing(), _rig.IsGrounded, _rig.IsJumping, - _rig.IsClimbing, _vrSpellTransformService != null && _vrSpellTransformService.IsTransformed, - _rig.Gravity, _rig.MaxFallSpeed, Time.deltaTime); + var feet = _rig.Root.position; + UpdateHorizontalVelocity(feet); + + var sample = new HeroFallSample(feet, GetFacing(), _rig.IsGrounded, _rig.IsJumping, _rig.IsClimbing, + _vrSpellTransformService != null && _vrSpellTransformService.IsTransformed, _rig.Gravity, + _rig.MaxFallSpeed, Time.deltaTime); _heroFallService.Tick(sample); + UpdateLeap(); + } + + private void UpdateHorizontalVelocity(Vector3 feet) + { + if (_hasLastFeet && Time.deltaTime > 0f) + { + var step = new Vector3(feet.x - _lastFeet.x, 0f, feet.z - _lastFeet.z) / Time.deltaTime; + _horizontalVelocity = Vector3.Lerp(_horizontalVelocity, step, _velocitySmoothing); + } + _lastFeet = feet; + _hasLastFeet = true; + } + + /// + /// The leap starts with a jump at running speed and lasts while he is in the air (jumping or falling) - landing, + /// water, a ledge or ladder, a teleport end it (HeroFallService's phase is back on the ground then). + /// + private void UpdateLeap() + { + var phase = _heroFallService.Phase; + var previousPhase = _lastPhase; + _lastPhase = phase; + + if (phase == HeroAirPhase.Jumping && previousPhase != HeroAirPhase.Jumping) + { + var speeds = _vrPlayerService.HeroSpeeds; + var speed = _horizontalVelocity.magnitude; + if (speed < speeds.RunThreshold) + return; + + var leap = _horizontalVelocity / speed * speeds.RunJump; + _rig.SetLeapVelocity(leap); + _isLeaping = true; + Logger.Log($"[VrHeroJumpFall] Running jump ({speed:F2} m/s, run from {speeds.RunThreshold:F2}) - " + + $"leap at {speeds.RunJump:F2} m/s", LogCat.VR); + return; + } + + if (_isLeaping && phase is not (HeroAirPhase.Jumping or HeroAirPhase.Falling)) + EndLeap(phase == HeroAirPhase.Grounded ? "on the ground" : phase.ToString()); + } + + private void EndLeap(string reason) + { + if (!_isLeaping) + return; + _isLeaping = false; + _rig.SetLeapVelocity(Vector3.zero); + Logger.Log($"[VrHeroJumpFall] Leap ended ({reason})", LogCat.VR); } /// @@ -61,6 +126,9 @@ private Vector3 GetFacing() private void OnTeleported(Vector3 feetPosition) { + _lastFeet = feetPosition; + _horizontalVelocity = Vector3.zero; + EndLeap("teleported"); _heroFallService.OnTeleported(feetPosition); } } diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs index 298f89733..0c8d1716c 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs @@ -182,9 +182,12 @@ private void UpdateSpeeds(float scale) if (sneak <= 0f) sneak = walk; + // The running jump's leap (VrHeroJumpFall): T_RUNL_2_JUMP's root motion, 0 = the speeds' fallback. As + // much faster as running (WalkRunFactor), else the leap could be slower than the run. + var runJump = _animator.GetMovementSpeed(_runToJump); var factor = scale * VRConstants.Movement.WalkRunFactor; var speeds = new VrHeroSpeeds(walk * factor, run * factor, sneak * scale, - _animator.IsFromOverlayOverride(_runAnimation)); + _animator.IsFromOverlayOverride(_runAnimation), runJump * factor); _vrPlayerService.HeroBodySpeeds = speeds; if (isNewOverlay) Logger.Log($"[VRHeroBody] Speeds of {_animator.MdsBase}/{overlay} at scale {scale:F2}: {speeds}" + diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs index 4554c84e6..d5bf93e5a 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs @@ -163,6 +163,8 @@ public class XriRig : MonoBehaviour, IVrRig private int _collidingLayers; private bool _isAirborneOnPurpose; private IVrLedgeHandler _ledgeHandler; + // SetLeapVelocity: a running jump's horizontal velocity, zero = none. + private Vector3 _leapVelocity; public event Action Teleported; @@ -455,10 +457,41 @@ private void OnDestroy() private void Update() { UpdateClimbLock(); + UpdateLeap(); UpdateSprint(); UpdateCrouch(); } + public void SetLeapVelocity(Vector3 velocity) + { + velocity.y = 0f; + _leapVelocity = velocity; + } + + /// + /// A running jump's leap (SetLeapVelocity): the stick doesn't move the rig meanwhile (the leap is the whole + /// horizontal speed), the CharacterController moves at the leap's velocity - walls stop it. Ends on the ground + /// after the take-off, when climbing and on a teleport. Gravity and the jump's rise stay XRI's. + /// + private void UpdateLeap() + { + if (_leapVelocity == Vector3.zero) + return; + + var isLanded = !_jumpProvider.isJumping && (_gravityProvider.isGrounded || _characterController.isGrounded); + if (IsClimbing || isLanded || _gravity <= 0f || !_characterController.enabled) + { + _leapVelocity = Vector3.zero; + return; + } + + _moveProvider.enabled = false; + // Teleports move the transform directly. A CharacterController.Move before the sync would undo them. + if (_isTeleportQueued || _lastTeleportFrame == Time.frameCount) + return; + _characterController.Move(_leapVelocity * Time.deltaTime); + } + /// /// Walking and jumping are off while climbing (the thumbstick would fight the climbing hands), and come /// back to what the game set (MovementEnabled/CanJump) afterwards. @@ -759,6 +792,7 @@ public void Teleport(Vector3 position, Quaternion rotation) rotation = Quaternion.identity; ReleaseClimb(); + _leapVelocity = Vector3.zero; _teleportPosition = position; _isTeleportQueued = true; diff --git a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs index 2c7f6ec1c..7f7d334fb 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs @@ -46,6 +46,16 @@ public interface IVrRig /// bool IsJumping => false; + /// + /// A running jump's leap (Gothic's T_RUNL_2_JUMP): the rig moves horizontally at this velocity (m/s) until it + /// lands, instead of the stick's movement - not on top of it. Vector3.zero ends it; the backend also ends it on + /// the ground, on a teleport and when a hand grabs a ladder or ledge. Default: not supported, the jump stays as + /// the stick moves it. + /// + void SetLeapVelocity(Vector3 velocity) + { + } + /// /// The player crouches (crouch button or the head held low). Crouched = sneaking for the scripts. /// diff --git a/Assets/Gothic-VR/Scripts/Models/VrHeroSpeeds.cs b/Assets/Gothic-VR/Scripts/Models/VrHeroSpeeds.cs index 96c14ea52..105d09e9f 100644 --- a/Assets/Gothic-VR/Scripts/Models/VrHeroSpeeds.cs +++ b/Assets/Gothic-VR/Scripts/Models/VrHeroSpeeds.cs @@ -7,6 +7,12 @@ namespace Gothic.VR.Models /// public readonly struct VrHeroSpeeds { + /// + /// The running jump's leap without its animation's root motion: G1's T_RUNL_2_JUMP (5.27 m/s) against its + /// S_RUNL (~3.3 m/s). + /// + public const float RunJumpFallbackFactor = 1.6f; + public readonly float Walk; public readonly float Run; public readonly float Sneak; @@ -16,14 +22,24 @@ public readonly struct VrHeroSpeeds /// public readonly bool IsSpeedOverlayRun; - public VrHeroSpeeds(float walk, float run, float sneak, bool isSpeedOverlayRun = false) + // T_RUNL_2_JUMP's own forward speed, 0 = unknown (RunJump falls back to the run speed's factor). + private readonly float _runJump; + + public VrHeroSpeeds(float walk, float run, float sneak, bool isSpeedOverlayRun = false, float runJump = 0f) { Walk = walk; Run = run; Sneak = sneak; IsSpeedOverlayRun = isSpeedOverlayRun; + _runJump = runJump; } + /// + /// Forward speed of a running jump's leap: T_RUNL_2_JUMP's root motion at the body's scale, else + /// RunJumpFallbackFactor times the run. + /// + public float RunJump => _runJump > 0f ? _runJump : Run * RunJumpFallbackFactor; + /// /// From this speed on the hero runs - BS_RUN for the scripts and the body's run animation: halfway between /// walking and running, so the stick walks and the sprint runs. @@ -36,12 +52,12 @@ public VrHeroSpeeds(float walk, float run, float sneak, bool isSpeedOverlayRun = public VrHeroSpeeds WithSpeedPotion() { var factor = VRConstants.Movement.SpeedPotionFactor; - return new VrHeroSpeeds(Walk * factor, Run * factor, Sneak, IsSpeedOverlayRun); + return new VrHeroSpeeds(Walk * factor, Run * factor, Sneak, IsSpeedOverlayRun, _runJump * factor); } public override string ToString() { - return $"walk {Walk:F2}, run {Run:F2}, sneak {Sneak:F2} m/s"; + return $"walk {Walk:F2}, run {Run:F2}, sneak {Sneak:F2}, running jump {RunJump:F2} m/s"; } } } From dd81be17c938cb595d7e072780ddf8292ea1aea0 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 04:17:41 +0000 Subject: [PATCH 13/41] docs: the jump/fall decision record - a jump's lying depth counts from its take-off, the running jump leaps Co-Authored-By: Claude Opus 5.5 --- Docs/adr/2026-11-29-hero-jump-fall.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md index d17e37052..e95b93672 100644 --- a/Docs/adr/2026-11-29-hero-jump-fall.md +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -15,10 +15,11 @@ In the original game the falling animation starts early and the hero then falls 2. **The damage is computed once, at the landing, from the measured drop: from the highest point of the jump or fall down to where he lands.** Below the safe height it is zero, above it the engine's rule (meters above the safe height times the damage per meter, minus fall protection, never below zero). Nothing ticks while he is in the air, and the falling animations never decide anything: a fall that plays the falling animation, even falling flat and landing lying, and lands within 5 m costs nothing. A jump on flat ground only counts its own small height. Not chosen: deriving the height from the impact speed like OpenGothic, because the VR rig's top falling speed would cap it at about 20 m, so a 50 m drop would not kill. 3. **No fall damage in water, on teleports, while climbing, while transformed into a monster, while lying, and in god mode.** Water means any water level (wading, swimming, diving); a teleport is any move by the game or the player (teleport, Marvin, scripts, loading, ledge and ladder exits) and also a step no fall can make in one frame; grabbing a ladder or ledge mid-air ends the fall, and letting go starts a new one from there. A transformed hero falls as the monster's puppet: no damage, his monster's own rules are not applied. Not chosen: monster fall rules for the transformed hero, left for later. 4. **Falling plays Gothic's animations on the VR hero body:** the take-off (from standing or running, sped up so the body is already in the jump pose while the physical jump is in the air), the jump pose, the short landing; the falling pose, then falling flat, the small landing. Stairs, slopes, small steps and slow lifts are no fall. -5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. -6. **He falls on his back when he went over the edge moving backwards (against where he faces), otherwise on his face.** Each side has its own landing, lying and getting up; if the hero's model lacks the back set, he falls on his face. -7. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** Turning and the hands stay free. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. -8. **A new Immersion option decides the view while he lies after a fall flat: the camera stays at the player's head (default), or it goes down with the body and comes back up while he stands up.** The default spares the player a sudden drop of the view after a long fall. Not chosen: reusing the knockout view option, which is about the game taking the hero down, not about a landing the player caused. +5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. For a jump the 2 m count from where he jumped off, not from the top of the jump: the jump's own rise (1 m) must not make him fall flat, so a running jump down a slope that lands 1.5 m lower lands on his feet. The damage height still counts from the top. Not chosen: measuring the pose from the top as well, which laid him on his face after an ordinary running jump downhill (play test). +6. **A jump at running speed (the sprint) is Gothic's running jump: a long leap forward at the speed of its animation (about 5 m/s for the hero, scaled with the body), in the direction he ran, until he lands.** The stick doesn't add to it in the air, walls stop it, grabbing a ledge or ladder, a teleport or water end it. The standing and walking jump stays straight up; both rise 1 m. The arms don't flail like in Gothic: they are the player's hands. Not chosen: the plain VR jump at running speed, which was a short hop compared to Gothic's leap. +7. **He falls on his back when he went over the edge moving backwards (against where he faces), otherwise on his face.** Each side has its own landing, lying and getting up; if the hero's model lacks the back set, he falls on his face. +8. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** Turning and the hands stay free. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. +9. **A new Immersion option decides the view while he lies after a fall flat: the camera stays at the player's head (default), or it goes down with the body and comes back up while he stands up.** The default spares the player a sudden drop of the view after a long fall. Not chosen: reusing the knockout view option, which is about the game taking the hero down, not about a landing the player caused. ## Consequences From 2c2ae61b8ce548627a7ea3119e7ecc2b8b4bf257 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 04:25:49 +0000 Subject: [PATCH 14/41] fix: the hero can't jump while his walking is blocked (lying after a fall, dialogs, knocked out) - and a running jump logs how far it went Co-Authored-By: Claude Opus 5.5 --- .../Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs | 9 ++++++++- .../Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs index 681371492..b0bc92987 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs @@ -33,6 +33,9 @@ public class VrHeroJumpFall : MonoBehaviour private Vector3 _horizontalVelocity; private HeroAirPhase _lastPhase; private bool _isLeaping; + // Where and when the running jump started - its length is logged at the end. + private Vector3 _leapStart; + private float _leapStartTime; private void Awake() { @@ -96,6 +99,8 @@ private void UpdateLeap() var leap = _horizontalVelocity / speed * speeds.RunJump; _rig.SetLeapVelocity(leap); _isLeaping = true; + _leapStart = _rig.Root.position; + _leapStartTime = Time.time; Logger.Log($"[VrHeroJumpFall] Running jump ({speed:F2} m/s, run from {speeds.RunThreshold:F2}) - " + $"leap at {speeds.RunJump:F2} m/s", LogCat.VR); return; @@ -111,7 +116,9 @@ private void EndLeap(string reason) return; _isLeaping = false; _rig.SetLeapVelocity(Vector3.zero); - Logger.Log($"[VrHeroJumpFall] Leap ended ({reason})", LogCat.VR); + var distance = Vector3.ProjectOnPlane(_rig.Root.position - _leapStart, Vector3.up).magnitude; + Logger.Log($"[VrHeroJumpFall] Leap ended ({reason}) after {distance:F2} m in " + + $"{Time.time - _leapStartTime:F2} s", LogCat.VR); } /// diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs index d5bf93e5a..86cfc796a 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs @@ -505,7 +505,8 @@ private void UpdateClimbLock() _jumpProvider.CancelJump(); _moveProvider.enabled = _isMovementEnabled && !isClimbing; - _jumpProvider.enabled = _isJumpEnabled && !isClimbing; + // A blocked walk (MovementEnabled: lying after a fall, dialogs, knocked out) blocks jumping as well. + _jumpProvider.enabled = _isJumpEnabled && _isMovementEnabled && !isClimbing; } /// From 49ceb2e014719f7d5571f27e2d880545bb5cb407 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 04:39:53 +0000 Subject: [PATCH 15/41] fix: the hands no longer flicker in fast falls - the physical hand follows the rig's movement per physics step, not the frame's average VrPhysicsHand.Drive followed _rigVelocity unlimited and the rest clamped to Max Speed (15 m/s). _rigVelocity was measured per frame in LateUpdate, but the rig moves once per frame: in the second physics step of a frame (editor below 50 fps) the controller stood still while the hand was still driven at the rig's velocity; at 20 m/s the clamp left 5 m/s, the body overshot the controller by ~10 cm, and beyond the 5 mm blocked distance UpdateVisual showed the interpolated body one step behind - the hands jumped every few frames (no snap or stuck log: neither ran). Now the rig's movement since the last step is measured in FixedUpdate. Also a rig move per frame counts as a teleport only beyond (terminal fall speed + 5 m/s) * deltaTime, at least 1 m - a fast fall at a low frame rate snapped the hands; real teleports raise Teleported anyway. Co-Authored-By: Claude Opus 5.5 --- .../Interaction/Components/VrPhysicsHand.cs | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Interaction/Components/VrPhysicsHand.cs b/Assets/Gothic-VR/Scripts/Interaction/Components/VrPhysicsHand.cs index 9628cac80..063db838f 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Components/VrPhysicsHand.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Components/VrPhysicsHand.cs @@ -84,7 +84,8 @@ public class VrPhysicsHand : MonoBehaviour [SerializeField] private float _rigSnapAngle = 10f; - [Tooltip("A rig move larger than this (m per frame) is a teleport: the hand snaps with the rig.")] + [Tooltip("A rig move larger than this (m per frame) is a teleport: the hand snaps with the rig. At least what " + + "the rig can fall in the frame (terminal speed + 5 m/s) - a fast fall at a low frame rate isn't one.")] [SerializeField] private float _rigSnapDistance = 1f; @@ -176,7 +177,13 @@ public class VrPhysicsHand : MonoBehaviour private Vector3 _lastTargetVelocity; private Vector3 _lastRigPosition; private Quaternion _lastRigRotation = Quaternion.identity; + // The rig's movement since the last physics step (m/s), measured in FixedUpdate: the rig moves once per frame, + // so between two steps of one frame it stands still, and after a frame with no step it moved two frames' worth. private Vector3 _rigVelocity; + private Vector3 _lastStepRigPosition; + private bool _isStepRigPositionKnown; + // Above the rig's terminal fall speed, a move per frame is still falling, not a teleport (_rigSnapDistance). + private const float _rigSnapSpeedMargin = 5f; // Inactive hand: offset of the visual from its rest pose (controller space), blended to 0. private Vector3 _inactiveOffsetPosition; @@ -507,7 +514,10 @@ private void FixedUpdate() _heldPassThrough.Update(GetViewpoint()); if (!_isActive) + { + _isStepRigPositionKnown = false; return; + } if (_body == null) { @@ -519,6 +529,7 @@ private void FixedUpdate() } var deltaTime = Time.fixedDeltaTime; + UpdateRigStepVelocity(deltaTime); GetTargetPose(out var targetPosition, out var targetRotation); // Result of the last step: how far the physics kept the hand from where it should be. @@ -1167,19 +1178,23 @@ private void HandleRigJump() return; } + // Real teleports raise Teleported (_isTeleportPending); a long move per frame is one only beyond what + // falling can do in it - at 20 m/s and a low frame rate a fall moved more than 1 m per frame and snapped. + var snapDistance = Mathf.Max(_rigSnapDistance, + (Mathf.Max(_rig.MaxFallSpeed, 0f) + _rigSnapSpeedMargin) * Time.deltaTime); var hasJumped = _isTeleportPending || Quaternion.Angle(_lastRigRotation, rigRotation) > _rigSnapAngle - || (rigPosition - _lastRigPosition).sqrMagnitude > _rigSnapDistance * _rigSnapDistance; + || (rigPosition - _lastRigPosition).sqrMagnitude > snapDistance * snapDistance; _isTeleportPending = false; if (!hasJumped) { - var deltaTime = Time.deltaTime; - _rigVelocity = deltaTime > 0f ? (rigPosition - _lastRigPosition) / deltaTime : Vector3.zero; StoreRigPose(rigPosition, rigRotation); return; } + // The jump is no movement for the next physics step. _rigVelocity = Vector3.zero; + _lastStepRigPosition = rigPosition; var deltaRotation = rigRotation * Quaternion.Inverse(_lastRigRotation); var isItemMoved = MoveHeldItemWithRig(_lastRigPosition, rigPosition, deltaRotation); @@ -1234,6 +1249,29 @@ private bool MoveHeldItemWithRig(Vector3 fromRigPosition, Vector3 toRigPosition, return true; } + /// + /// The rig's movement since the last physics step - Drive follows it unlimited (Max Speed is relative to it). + /// Measured per frame it was the frame's average: in the second step of a frame the rig stood still, but the + /// hand was still driven at the full fall speed (clamped by Max Speed from 20 m/s only to 5 m/s), overshot + /// the controller by ~10 cm, and above the 5 mm blocked distance the visual switched to the interpolated body + /// one step behind - the hands flickered in fast falls at editor frame rates. + /// + private void UpdateRigStepVelocity(float deltaTime) + { + if (_rig == null) + { + _rigVelocity = Vector3.zero; + return; + } + + var rigPosition = _rig.Root.position; + _rigVelocity = _isStepRigPositionKnown && deltaTime > 0f + ? (rigPosition - _lastStepRigPosition) / deltaTime + : Vector3.zero; + _lastStepRigPosition = rigPosition; + _isStepRigPositionKnown = true; + } + private void StoreRigPose(Vector3 position, Quaternion rotation) { _lastRigPosition = position; From 2680741034230d59426d26560d0f24d77a1c9f62 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 04:40:56 +0000 Subject: [PATCH 16/41] fix: standing and walking the hero jumps up (T_STAND_2_JUMPUP, S_JUMPUP), not Gothic's forward leap - and the take-off plays at its own speed until he lands T_STAND_2_JUMP is Gothic's standing forward jump (2.65 m, flailing arms); the vertical VR jump now uses the jump-up, T_STAND_2_JUMP / S_JUMP only for a model without it. The running jump (VRPlayerService.IsRunningJump, set by VrHeroJumpFall with the leap - one decision for the leap and the animation) keeps T_RUNL_2_JUMP -> S_JUMP. The take-off is no longer squeezed into 0.3 s: it plays at its own speed and the landing cuts it. Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Player/VrHeroJumpFall.cs | 4 +- .../Adapters/Player/VrHeroLocomotion.cs | 61 +++++++++++-------- .../Scripts/Services/VRPlayerService.cs | 6 ++ 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs index b0bc92987..d62df2f8b 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs @@ -93,7 +93,8 @@ private void UpdateLeap() { var speeds = _vrPlayerService.HeroSpeeds; var speed = _horizontalVelocity.magnitude; - if (speed < speeds.RunThreshold) + _vrPlayerService.IsRunningJump = speed >= speeds.RunThreshold; + if (!_vrPlayerService.IsRunningJump) return; var leap = _horizontalVelocity / speed * speeds.RunJump; @@ -115,6 +116,7 @@ private void EndLeap(string reason) if (!_isLeaping) return; _isLeaping = false; + _vrPlayerService.IsRunningJump = false; _rig.SetLeapVelocity(Vector3.zero); var distance = Vector3.ProjectOnPlane(_rig.Root.position - _leapStart, Vector3.up).magnitude; Logger.Log($"[VrHeroJumpFall] Leap ended ({reason}) after {distance:F2} m in " + diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs index 0c8d1716c..c2ff2f2f4 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs @@ -38,22 +38,26 @@ public class VrHeroLocomotion private const string _walkBackAnimation = "S_WALKBL"; private const string _fallAnimation = "S_FALLDN"; - // Jumps and falls: take-off -> S_JUMP -> landing, S_FALLDN -> S_FALL / S_FALLB (deeper than 2 m) -> landing. + // Jumps and falls: take-off -> in the air -> landing, S_FALLDN -> S_FALL / S_FALLB (deeper than 2 m) -> landing. + // Standing and walking the VR jump goes straight up: Gothic's jump-up (G1: T_STAND_2_JUMPUP 0.40 s). Its + // T_STAND_2_JUMP is the standing forward jump (2.65 m, flailing arms) - only the fallback for a model without. + private const string _standToJumpUp = "T_STAND_2_JUMPUP"; + private const string _jumpUpAnimation = "S_JUMPUP"; private const string _standToJump = "T_STAND_2_JUMP"; + // Running (VRPlayerService.IsRunningJump, the leap): Gothic's running jump. private const string _runToJump = "T_RUNL_2_JUMP"; private const string _jumpAnimation = "S_JUMP"; private const string _jumpToStand = "T_JUMP_2_STAND"; // Not in G1's HUMANS.MDS: landing from a run goes straight on running then. private const string _jumpToRun = "T_JUMP_2_RUNL"; private const string _fallToStand = "T_FALLDN_2_STAND"; - // The take-off (G1: 0.96 s, the body rising 0.6 m) is over this fast - the physics jump (~1 m rise) is - // already in the air, the body should be in S_JUMP for it. - private const float _takeOffSeconds = 0.3f; private HeroAirPhase _airPhase; private int _landingCount; - // The take-off or landing one-shot running now (null = none) and its playback speed. + // The take-off or landing one-shot running now (null = none), at its own speed - a take-off is cut by the + // landing, so a jump off a slope lands before it ends. private string _airOneShot; - private float _airOneShotSpeed = 1f; + // The jump's pose in the air after its take-off (S_JUMPUP or S_JUMP). + private string _jumpLoop = _jumpAnimation; private VRHeroBodyAnimator _animator; private float _lastBodyYaw; @@ -238,11 +242,8 @@ private bool TryPlayAirAnimation(float speed, bool isMoving) { case HeroAirPhase.Jumping: if (previousPhase != HeroAirPhase.Jumping) - StartAirOneShot(speed >= _vrPlayerService.HeroSpeeds.RunThreshold && - _animator.HasAnimation(_runToJump) - ? _runToJump - : _standToJump, _takeOffSeconds); - return PlayAirOneShot(false) || _animator.Play(_jumpAnimation); + StartTakeOff(); + return PlayAirOneShot(false) || _animator.Play(_jumpLoop); case HeroAirPhase.Falling: _airOneShot = null; return _animator.Play(GetFallAnimation()); @@ -253,6 +254,24 @@ private bool TryPlayAirAnimation(float speed, bool isMoving) return PlayAirOneShot(isMoving && _airOneShot != _jumpToRun); } + /// + /// The running jump (the leap) takes off with T_RUNL_2_JUMP into S_JUMP, the standing and walking jump with + /// the jump-up T_STAND_2_JUMPUP into S_JUMPUP - T_STAND_2_JUMP / S_JUMP for a model without them. + /// + private void StartTakeOff() + { + if (_vrPlayerService.IsRunningJump && _animator.HasAnimation(_runToJump)) + { + StartAirOneShot(_runToJump); + _jumpLoop = _jumpAnimation; + return; + } + + var isJumpUp = _animator.HasAnimation(_standToJumpUp); + StartAirOneShot(isJumpUp ? _standToJumpUp : _standToJump); + _jumpLoop = isJumpUp && _animator.HasAnimation(_jumpUpAnimation) ? _jumpUpAnimation : _jumpAnimation; + } + /// /// S_FALLDN, deeper than NpcFallDomain.LyingFallHeight flat: S_FALL on his face, S_FALLB on his back (the face /// set if the model has no S_FALLB). @@ -280,25 +299,17 @@ private void StartLanding(float speed, bool isMoving) var isRunning = speed >= _vrPlayerService.HeroSpeeds.RunThreshold; if (landing.IsJump && isRunning && _animator.HasAnimation(_jumpToRun)) - StartAirOneShot(_jumpToRun, 0f); + StartAirOneShot(_jumpToRun); else if (!isMoving) - StartAirOneShot(landing.IsJump ? _jumpToStand : _fallToStand, 0f); + StartAirOneShot(landing.IsJump ? _jumpToStand : _fallToStand); } /// - /// seconds: squeeze the one-shot into this time (never slower than its own), 0 = its own speed. + /// Played at its own speed until it ends, the landing or a fall replaces it. /// - private void StartAirOneShot(string animation, float seconds) + private void StartAirOneShot(string animation) { - var track = _animationService.GetTrack(animation, _animator.MdsBase, _animator.MdsOverlay); - if (track == null) - { - _airOneShot = null; - return; - } - - _airOneShot = animation; - _airOneShotSpeed = seconds > 0f && track.Duration > seconds ? track.Duration / seconds : 1f; + _airOneShot = _animator.HasAnimation(animation) ? animation : null; } /// @@ -314,7 +325,7 @@ private bool PlayAirOneShot(bool isCut) return false; } - return _animator.Play(_airOneShot, _airOneShotSpeed); + return _animator.Play(_airOneShot); } /// diff --git a/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs b/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs index 16fbebecc..2c3dbc1ed 100644 --- a/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs +++ b/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs @@ -382,6 +382,12 @@ private void OnPlayerPrefUpdated(string key, object value) /// public bool IsHeroBodyDown { get; set; } + /// + /// The jump running now is a running jump (a leap, VrHeroJumpFall) - the VR hero body plays T_RUNL_2_JUMP for + /// it, the jump-up otherwise (VrHeroLocomotion). Set at the take-off, false again when the leap ends. + /// + public bool IsRunningJump { get; set; } + /// /// The VR hero body's walk, run and sneak speeds from its animations at its scale (VrHeroLocomotion), null /// without an animated body. VRHeroMovement makes the rig's speeds of them. From 8799ec86e014374297896d62b003404abe3ca2a3 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 04:41:55 +0000 Subject: [PATCH 17/41] fix: a jump lands on his feet unless it drops deeper than FALLDOWN_HEIGHT below the take-off - jumping down steep slopes no longer lays him on his face Like OpenGothic, a jump falls flat (and lands lying) only beyond the guild's FALLDOWN_HEIGHT (5 m human) below its take-off; a fall without a jump keeps NpcFallDomain.LyingFallHeight (2 m) below its start. HeroAirborneDomain.Tick takes the safe height again for that (LyingDepth), the damage stays from the top. Tests: a jump 3.5 m down a steep slope lands as a jump, a jump off a 6 m ledge lands lying. Co-Authored-By: Claude Opus 5.5 --- .../Domain/Movement/HeroAirborneDomain.cs | 29 +++++++++++------ .../Services/Movement/HeroFallService.cs | 11 ++++--- .../Movement/HeroAirborneDomainTest.cs | 31 +++++++++++++++---- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs index e1c124237..4f844b5a7 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs @@ -12,10 +12,11 @@ namespace Gothic.Core.Domain.Movement /// landing costs. Platform-neutral: VR feeds it from the rig port, Flat can feed it from its controller. /// - The phase and the pose are visual/body state only. Damage is never tied to them: a fall flat (S_FALL) from /// 3 m lands lying and costs nothing; HeroFallService computes the damage once, at the landing, from the height. - /// - Deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs) he falls flat - on his back if he went over the edge - /// moving backwards (against his facing), else on his face - and lands lying. A fall measures it from where it - /// started, a jump from its take-off: the jump's own rise doesn't count, a running jump down a slope landing - /// 1.5 m lower lands on his feet. A jump stays a jump (S_JUMP, the jump's landing) until that deep. + /// - Falling flat (on his back if he went over the edge moving backwards, against his facing, else on his face) + /// and a lying landing: a fall (walked off an edge) deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs) + /// below where it started; a jump only deeper than the guild's FALLDOWN_HEIGHT (5 m human) below its take-off, + /// like OpenGothic - the jump's own rise doesn't count, and a jump down a steep slope lands on his feet. A jump + /// stays a jump (its pose in the air, the jump's landing) until that deep. /// - No fall without real falling: off the ground (beyond the platform's grounded grace) the hero falls only when /// moving down faster than FallSpeed and below MinFallDrop - stairs, slopes and lifts stay walking. /// @@ -49,6 +50,8 @@ public class HeroAirborneDomain private Vector3 _moveVelocity; // The phase began as the hero's jump: the lying depth counts from the take-off, not from the jump's top. private bool _isFromJump; + // A jump's lying depth: FALLDOWN_HEIGHT (Tick's safeHeight). + private float _jumpLyingDepth = NpcFallDomain.LyingFallHeight; public HeroAirPhase Phase { get; private set; } @@ -80,11 +83,19 @@ public class HeroAirborneDomain public float LyingReferenceY => _isFromJump ? TakeOffY : PeakY; /// - /// One frame. Returns what changed; landing is set for HeroAirEvent.Landed only. + /// How deep below LyingReferenceY he falls flat: FALLDOWN_HEIGHT for a jump, LyingFallHeight for a fall. /// - public HeroAirEvent Tick(in HeroFallSample sample, out HeroLanding landing) + public float LyingDepth => _isFromJump ? _jumpLyingDepth : NpcFallDomain.LyingFallHeight; + + /// + /// One frame. safeHeight: the guild's FALLDOWN_HEIGHT in m - how deep a jump drops below its take-off before + /// he falls flat (0 or less: LyingFallHeight). Returns what changed; landing is set for HeroAirEvent.Landed + /// only. + /// + public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLanding landing) { landing = default; + _jumpLyingDepth = safeHeight > 0f ? safeHeight : NpcFallDomain.LyingFallHeight; var feet = sample.FeetPosition; var deltaTime = sample.DeltaTime; @@ -134,7 +145,7 @@ public HeroAirEvent Tick(in HeroFallSample sample, out HeroLanding landing) } if (Phase == HeroAirPhase.Falling && !IsLyingFall && - LyingReferenceY - feet.y > NpcFallDomain.LyingFallHeight) + LyingReferenceY - feet.y > LyingDepth) { IsLyingFall = true; IsBackwards = IsMovingBackwards(sample.Forward); @@ -200,9 +211,9 @@ private bool IsFalling(float feetY, float verticalSpeed) { if (verticalSpeed >= 0f) return false; - // A jump becomes a fall only once it's deeper than the lying depth below its take-off. + // A jump becomes a fall only once it's deeper than its lying depth (FALLDOWN_HEIGHT) below the take-off. if (Phase == HeroAirPhase.Jumping) - return feetY < TakeOffY - NpcFallDomain.LyingFallHeight; + return feetY < TakeOffY - _jumpLyingDepth; return verticalSpeed <= -FallSpeed && PeakY - feetY >= MinFallDrop; } diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 1004b9101..923900c8a 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -20,9 +20,10 @@ namespace Gothic.Core.Services.Movement /// (DeveloperConfig.EnableHeroFallDamage), lying and getting up after a fall flat. The platform measures (VR: the /// rig port, VrHeroJumpFall) and calls Tick every frame; the phases come from HeroAirborneDomain. /// Pose and damage are separate rules: - /// - Pose: S_FALLDN as soon as he falls; deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs; a jump below - /// its take-off, not its top) he falls flat (HeroFallPose: on his face, on his back when he went over the edge - /// backwards) and lands lying - he lies a moment and gets up, walking locked meanwhile. + /// - Pose: S_FALLDN as soon as he falls; a fall deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs), a jump + /// deeper than FALLDOWN_HEIGHT below its take-off (like OpenGothic), falls flat (HeroFallPose: on his face, on + /// his back when he went over the edge backwards) and lands lying - he lies a moment and gets up, walking locked + /// meanwhile. /// - Damage - one place, once per landing, never per frame and never from the pose: the drop from the highest point /// of the jump/fall to the landing point, NpcFallDomain.GetFallDamage = (drop - FALLDOWN_HEIGHT) * /// FALLDOWN_DAMAGE - PROT_FALL, at least 0. A lying landing from 3 m costs nothing, damage starts above @@ -110,7 +111,7 @@ public void Tick(in HeroFallSample sample) _holdReason = null; var safeHeight = NpcFallDomain.GetSafeFallHeight(_gameStateService.GuildValues, hero); - switch (_airborne.Tick(sample, out var landing)) + switch (_airborne.Tick(sample, safeHeight, out var landing)) { case HeroAirEvent.JumpStarted: SetAirBodyState(hero, VmGothicEnums.BodyState.BsJump); @@ -122,7 +123,7 @@ public void Tick(in HeroFallSample sample) "no damage within it)", LogCat.Npc); break; case HeroAirEvent.LyingFallStarted: - Logger.Log($"[HeroFall] More than {NpcFallDomain.LyingFallHeight:F1} m below " + + Logger.Log($"[HeroFall] More than {_airborne.LyingDepth:F1} m below " + $"{_airborne.LyingReferenceY:F2} (jump take-off or fall start) - falls flat " + $"({(_airborne.IsBackwards ? "on his back" : "on his face")}), lands lying; damage " + $"only above FALLDOWN_HEIGHT {safeHeight:F1} m, at the landing", LogCat.Npc); diff --git a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs index cddc675d2..7566dc611 100644 --- a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs +++ b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs @@ -15,6 +15,8 @@ public class HeroAirborneDomainTest private const float _dt = 1f / 72f; private const float _gravity = 9.81f; private const float _maxFallSpeed = 20f; + // FALLDOWN_HEIGHT of humans: a jump falls flat only this far below its take-off. + private const float _safeHeight = 5f; private HeroAirborneDomain _domain; private HeroLanding _landing; @@ -46,7 +48,7 @@ private void Tick(float feetY, bool isGrounded, bool isJumping = false, float dt _feet = new Vector3(_feet.x, feetY, _feet.z) + _moveVelocity * dt; var sample = new HeroFallSample(_feet, _forward, isGrounded, isJumping, false, false, _gravity, _maxFallSpeed, dt); - switch (_domain.Tick(sample, out var landing)) + switch (_domain.Tick(sample, _safeHeight, out var landing)) { case HeroAirEvent.Landed: _landings++; @@ -193,18 +195,35 @@ public void RunningJumpDownASlopeLandsOnHisFeet() Assert.AreEqual(2.5f, _landing.Height, 0.05f); } + /// + /// A jump falls flat only deeper than FALLDOWN_HEIGHT below its take-off (OpenGothic): 3.5 m down a steep + /// slope is a jump landing on his feet, though a walk off the same edge would land lying (2 m). + /// [Test] - public void JumpOffAThreeMeterLedgeLandsLying() + public void JumpDownASteepSlopeLandsOnHisFeet() { - Stand(3f); - Tick(3f, true, true); - FallTo(3f, 0f, 4.43f, true); + Stand(0f); + Tick(0f, true, true); + FallTo(0f, -3.5f, 4.43f, true); + + Assert.AreEqual(0, _lyingFalls); + Assert.IsTrue(_landing.IsJump); + Assert.IsFalse(_landing.IsLying); + Assert.AreEqual(4.5f, _landing.Height, 0.05f); + } + + [Test] + public void JumpOffASixMeterLedgeLandsLying() + { + Stand(6f); + Tick(6f, true, true); + FallTo(6f, 0f, 4.43f, true); Assert.AreEqual(1, _falls); Assert.AreEqual(1, _lyingFalls); Assert.IsFalse(_landing.IsJump); Assert.IsTrue(_landing.IsLying); - Assert.AreEqual(4f, _landing.Height, 0.05f); + Assert.AreEqual(7f, _landing.Height, 0.05f); } [Test] From 26a0cd6f8594353f2a9c7b9497b18a28fa534745 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 04:41:59 +0000 Subject: [PATCH 18/41] docs: the jump/fall decision record - the jump-up and take-offs at their own speed, a jump falls flat only beyond FALLDOWN_HEIGHT Co-Authored-By: Claude Opus 5.5 --- Docs/adr/2026-11-29-hero-jump-fall.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md index e95b93672..842518af1 100644 --- a/Docs/adr/2026-11-29-hero-jump-fall.md +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -14,8 +14,8 @@ In the original game the falling animation starts early and the hero then falls 1. **The hero takes fall damage like in Gothic, with a developer switch that is on in the released game.** The switch works with or without the combat system, NPCs keep their old behaviour (fall damage only with the combat system). Not chosen: tying it to the combat system, which is still a work-in-progress switch, so a cliff would stay harmless for many players. 2. **The damage is computed once, at the landing, from the measured drop: from the highest point of the jump or fall down to where he lands.** Below the safe height it is zero, above it the engine's rule (meters above the safe height times the damage per meter, minus fall protection, never below zero). Nothing ticks while he is in the air, and the falling animations never decide anything: a fall that plays the falling animation, even falling flat and landing lying, and lands within 5 m costs nothing. A jump on flat ground only counts its own small height. Not chosen: deriving the height from the impact speed like OpenGothic, because the VR rig's top falling speed would cap it at about 20 m, so a 50 m drop would not kill. 3. **No fall damage in water, on teleports, while climbing, while transformed into a monster, while lying, and in god mode.** Water means any water level (wading, swimming, diving); a teleport is any move by the game or the player (teleport, Marvin, scripts, loading, ledge and ladder exits) and also a step no fall can make in one frame; grabbing a ladder or ledge mid-air ends the fall, and letting go starts a new one from there. A transformed hero falls as the monster's puppet: no damage, his monster's own rules are not applied. Not chosen: monster fall rules for the transformed hero, left for later. -4. **Falling plays Gothic's animations on the VR hero body:** the take-off (from standing or running, sped up so the body is already in the jump pose while the physical jump is in the air), the jump pose, the short landing; the falling pose, then falling flat, the small landing. Stairs, slopes, small steps and slow lifts are no fall. -5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. For a jump the 2 m count from where he jumped off, not from the top of the jump: the jump's own rise (1 m) must not make him fall flat, so a running jump down a slope that lands 1.5 m lower lands on his feet. The damage height still counts from the top. Not chosen: measuring the pose from the top as well, which laid him on his face after an ordinary running jump downhill (play test). +4. **Falling plays Gothic's animations on the VR hero body:** the take-off at its own speed, cut short when he lands first (the running jump's from running, Gothic's jump-up from standing or walking - not its standing forward leap, the VR jump goes straight up), the pose in the air, the short landing; the falling pose, then falling flat, the small landing. Stairs, slopes, small steps and slow lifts are no fall. +5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. A jump is different: he falls flat only when he lands deeper than the safe height (5 m) below where he jumped off, like OpenGothic - not counting the jump's own rise (1 m), so jumping down a steep slope lands on his feet. The damage height still counts from the top. Not chosen: the 2 m for jumps too, or measured from the top of the jump, which laid him on his face after ordinary running jumps downhill (play tests). 6. **A jump at running speed (the sprint) is Gothic's running jump: a long leap forward at the speed of its animation (about 5 m/s for the hero, scaled with the body), in the direction he ran, until he lands.** The stick doesn't add to it in the air, walls stop it, grabbing a ledge or ladder, a teleport or water end it. The standing and walking jump stays straight up; both rise 1 m. The arms don't flail like in Gothic: they are the player's hands. Not chosen: the plain VR jump at running speed, which was a short hop compared to Gothic's leap. 7. **He falls on his back when he went over the edge moving backwards (against where he faces), otherwise on his face.** Each side has its own landing, lying and getting up; if the hero's model lacks the back set, he falls on his face. 8. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** Turning and the hands stay free. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. From 5163c8f1b7bb49444983c1f07e1d9a40dba59db3 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 04:51:12 +0000 Subject: [PATCH 19/41] fix: fall damage only when the hero lands lying on his face or back - landing on his feet costs nothing, also from high up Co-Authored-By: Claude Opus 5.5 --- .../Services/Movement/HeroFallService.cs | 22 ++++++++++++------- Docs/adr/2026-11-29-hero-jump-fall.md | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 923900c8a..9a8c81461 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -24,10 +24,11 @@ namespace Gothic.Core.Services.Movement /// deeper than FALLDOWN_HEIGHT below its take-off (like OpenGothic), falls flat (HeroFallPose: on his face, on /// his back when he went over the edge backwards) and lands lying - he lies a moment and gets up, walking locked /// meanwhile. - /// - Damage - one place, once per landing, never per frame and never from the pose: the drop from the highest point - /// of the jump/fall to the landing point, NpcFallDomain.GetFallDamage = (drop - FALLDOWN_HEIGHT) * - /// FALLDOWN_DAMAGE - PROT_FALL, at least 0. A lying landing from 3 m costs nothing, damage starts above - /// FALLDOWN_HEIGHT (5 m for humans). FightService applies it (a deep fall kills, god mode ignores it). + /// - Damage - one place, once per landing, never per frame: only a lying landing hurts (landing on his feet costs + /// nothing, also from high up). It comes from the drop from the highest point of the jump/fall to the landing + /// point, NpcFallDomain.GetFallDamage = (drop - FALLDOWN_HEIGHT) * FALLDOWN_DAMAGE - PROT_FALL, at least 0. A + /// lying landing from 3 m costs nothing, damage starts above FALLDOWN_HEIGHT (5 m for humans). FightService + /// applies it (a deep fall kills, god mode ignores it). /// Not tracked (no damage): in water (water level not normal, swimming, diving, no gravity), climbing, teleported /// (OnTeleported, or a step no fall can make), transformed, down (dead, unconscious) or busy (sitting, mobs). /// Not saved: a loaded game starts on the ground (LoadGameStart / WorldSceneLoaded reset it, the first seconds @@ -191,7 +192,7 @@ private void Hold(NpcContainer hero, Vector3 feet, string reason) } /// - /// The landing, once: damage from the measured drop alone (not the pose), the lying landing's lock, the event + /// The landing, once: damage from the measured drop (lying landings only), the lying landing's lock, the event /// for the VR body. /// private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, float feetY) @@ -206,9 +207,14 @@ private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, floa LastLanding = landing; var isDamageOn = _configService.Dev.EnableHeroFallDamage; - var damage = NpcFallDomain.GetFallDamage(_gameStateService.GuildValues, hero, landing.Height); - var kind = landing.IsJump ? "jump" : !landing.IsLying ? "fall" : - landing.IsBackwards ? "lying landing on his back" : "lying landing on his face"; + // Only a lying landing hurts (author's choice): landing on his feet costs nothing, also from high up - + // without the fall on his face the damage looked like a twisted ankle. + var damage = landing.IsLying + ? NpcFallDomain.GetFallDamage(_gameStateService.GuildValues, hero, landing.Height) + : 0; + var kind = landing.IsLying + ? landing.IsBackwards ? "lying landing on his back" : "lying landing on his face" + : landing.IsJump ? "jump" : "fall"; Logger.Log($"[HeroFall] Landed ({kind}) at {feetY:F2} after {landing.Height:F2} m, FALLDOWN_HEIGHT " + $"{safeHeight:F1} m, damage {damage}" + (isDamageOn ? "" : " - not applied (DeveloperConfig.EnableHeroFallDamage off)"), LogCat.Npc); diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md index 842518af1..e784b923e 100644 --- a/Docs/adr/2026-11-29-hero-jump-fall.md +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -12,7 +12,7 @@ In the original game the falling animation starts early and the hero then falls ## Decisions 1. **The hero takes fall damage like in Gothic, with a developer switch that is on in the released game.** The switch works with or without the combat system, NPCs keep their old behaviour (fall damage only with the combat system). Not chosen: tying it to the combat system, which is still a work-in-progress switch, so a cliff would stay harmless for many players. -2. **The damage is computed once, at the landing, from the measured drop: from the highest point of the jump or fall down to where he lands.** Below the safe height it is zero, above it the engine's rule (meters above the safe height times the damage per meter, minus fall protection, never below zero). Nothing ticks while he is in the air, and the falling animations never decide anything: a fall that plays the falling animation, even falling flat and landing lying, and lands within 5 m costs nothing. A jump on flat ground only counts its own small height. Not chosen: deriving the height from the impact speed like OpenGothic, because the VR rig's top falling speed would cap it at about 20 m, so a 50 m drop would not kill. +2. **The damage is computed once, at the landing, from the measured drop: from the highest point of the jump or fall down to where he lands.** Below the safe height it is zero, above it the engine's rule (meters above the safe height times the damage per meter, minus fall protection, never below zero). Nothing ticks while he is in the air, and the falling animations never decide anything: a fall that plays the falling animation, even falling flat and landing lying, and lands within 5 m costs nothing. A jump on flat ground only counts its own small height. **Only a lying landing hurts:** landing on his feet (a jump that doesn't go flat, see 5) costs nothing, also from high up - in the play test the hit points went down without any fall on the face, like a twisted ankle. Not chosen: deriving the height from the impact speed like OpenGothic, because the VR rig's top falling speed would cap it at about 20 m, so a 50 m drop would not kill. 3. **No fall damage in water, on teleports, while climbing, while transformed into a monster, while lying, and in god mode.** Water means any water level (wading, swimming, diving); a teleport is any move by the game or the player (teleport, Marvin, scripts, loading, ledge and ladder exits) and also a step no fall can make in one frame; grabbing a ladder or ledge mid-air ends the fall, and letting go starts a new one from there. A transformed hero falls as the monster's puppet: no damage, his monster's own rules are not applied. Not chosen: monster fall rules for the transformed hero, left for later. 4. **Falling plays Gothic's animations on the VR hero body:** the take-off at its own speed, cut short when he lands first (the running jump's from running, Gothic's jump-up from standing or walking - not its standing forward leap, the VR jump goes straight up), the pose in the air, the short landing; the falling pose, then falling flat, the small landing. Stairs, slopes, small steps and slow lifts are no fall. 5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. A jump is different: he falls flat only when he lands deeper than the safe height (5 m) below where he jumped off, like OpenGothic - not counting the jump's own rise (1 m), so jumping down a steep slope lands on his feet. The damage height still counts from the top. Not chosen: the 2 m for jumps too, or measured from the top of the jump, which laid him on his face after ordinary running jumps downhill (play tests). From 7166b7a479548d736a5ff78ebcabb768b5c5d900 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 05:21:45 +0000 Subject: [PATCH 20/41] refactor: the hero's movement body states in one place (BodyStateExtension IsLocomotion/IsAirborne) - HeroFallService, VRHeroMovement and VRSwimDive no longer copy the list Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Extensions/BodyStateExtension.cs | 31 +++++++++++++++++++ .../Services/Movement/HeroFallService.cs | 17 +++++----- .../Scripts/Adapters/Player/VRHeroMovement.cs | 4 +-- .../Scripts/Adapters/Player/VRSwimDive.cs | 9 +++--- 4 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 Assets/Gothic-Core/Scripts/Extensions/BodyStateExtension.cs diff --git a/Assets/Gothic-Core/Scripts/Extensions/BodyStateExtension.cs b/Assets/Gothic-Core/Scripts/Extensions/BodyStateExtension.cs new file mode 100644 index 000000000..8c563d9e6 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Extensions/BodyStateExtension.cs @@ -0,0 +1,31 @@ +using Gothic.Core.Models.Vm; + +namespace Gothic.Core.Extensions +{ + /// + /// The hero's movement body states, one list for all who write them - each writer only overwrites these, so the + /// others' states (swimming, lying, sitting, unconscious, ...) stay: + /// - VRHeroMovement: BS_STAND / BS_WALK / BS_RUN / BS_SNEAK (IsLocomotion) from the rig's movement. + /// - HeroFallService: BS_JUMP / BS_FALL (IsAirborne) over the locomotion states, back to BS_STAND at the landing. + /// - VRSwimDive: BS_SWIM / BS_DIVE over locomotion and airborne states (falling into water swims). + /// + public static class BodyStateExtension + { + /// + /// Standing, walking, running or sneaking on the ground - also with a weapon drawn (Gothic keeps these then). + /// + public static bool IsLocomotion(this VmGothicEnums.BodyState bodyState) + { + return bodyState is VmGothicEnums.BodyState.BsStand or VmGothicEnums.BodyState.BsWalk + or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSneak; + } + + /// + /// Jumping or falling (HeroFallService). + /// + public static bool IsAirborne(this VmGothicEnums.BodyState bodyState) + { + return bodyState is VmGothicEnums.BodyState.BsJump or VmGothicEnums.BodyState.BsFall; + } + } +} diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 9a8c81461..0588b45d7 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -1,6 +1,7 @@ using Gothic.Core.Const; using Gothic.Core.Domain.Movement; using Gothic.Core.Domain.Npc; +using Gothic.Core.Extensions; using Gothic.Core.Logging; using Gothic.Core.Models.Container; using Gothic.Core.Models.Context; @@ -33,6 +34,9 @@ namespace Gothic.Core.Services.Movement /// (OnTeleported, or a step no fall can make), transformed, down (dead, unconscious) or busy (sitting, mobs). /// Not saved: a loaded game starts on the ground (LoadGameStart / WorldSceneLoaded reset it, the first seconds /// after it aren't tracked - VOBs under the spawn point may still be loading). + /// Owners of the hero's movement body states (BodyStateExtension): BS_JUMP / BS_FALL are this service's, + /// BS_STAND / BS_WALK / BS_RUN / BS_SNEAK the platform's movement (VR: VRHeroMovement), BS_SWIM / BS_DIVE the + /// water's (VR: VRSwimDive). Each writes only over the others' movement states, never over lying, sitting, ... /// public class HeroFallService { @@ -170,11 +174,8 @@ private static string GetHoldReason(NpcContainer hero, in HeroFallSample sample) if (ai != null && ai.WaterLevel != (int)ZenGineConst.WaterLevel.Normal) return "in water"; - return hero.Props.BodyState is VmGothicEnums.BodyState.BsStand or VmGothicEnums.BodyState.BsWalk - or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSneak or VmGothicEnums.BodyState.BsJump - or VmGothicEnums.BodyState.BsFall - ? null - : $"body state {hero.Props.BodyState}"; + var bodyState = hero.Props.BodyState; + return bodyState.IsLocomotion() || bodyState.IsAirborne() ? null : $"body state {bodyState}"; } private void Hold(NpcContainer hero, Vector3 feet, string reason) @@ -280,9 +281,7 @@ private void Unlock() /// private static void SetAirBodyState(NpcContainer hero, VmGothicEnums.BodyState bodyState) { - if (hero.Props.BodyState is VmGothicEnums.BodyState.BsStand or VmGothicEnums.BodyState.BsWalk - or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSneak or VmGothicEnums.BodyState.BsJump - or VmGothicEnums.BodyState.BsFall) + if (hero.Props.BodyState.IsLocomotion() || hero.Props.BodyState.IsAirborne()) hero.Props.BodyState = bodyState; } @@ -291,7 +290,7 @@ or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSneak or VmGothicE /// private static void EndAirBodyState(NpcContainer hero) { - if (hero.Props.BodyState is VmGothicEnums.BodyState.BsJump or VmGothicEnums.BodyState.BsFall) + if (hero.Props.BodyState.IsAirborne()) hero.Props.BodyState = VmGothicEnums.BodyState.BsStand; } diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs index 4bf5941bd..62ba06f7b 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs @@ -197,9 +197,7 @@ private void UpdateHeroBodyState() _lastBodyStatePosition = position; var props = heroInstance.GetUserData()?.Props; - if (props == null || props.BodyState is not (VmGothicEnums.BodyState.BsStand - or VmGothicEnums.BodyState.BsWalk or VmGothicEnums.BodyState.BsRun - or VmGothicEnums.BodyState.BsSneak)) + if (props == null || !props.BodyState.IsLocomotion()) return; // Crouched = sneaking. diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs index 96a1fa056..8b13d184b 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs @@ -373,10 +373,11 @@ private void UpdateHeroBodyState() return; var bodyState = _heroContainer.Props.BodyState; - // Jumping or falling into the water too (HeroFallService): he swims, not falls. - var isWaterOrMoving = bodyState is VmGothicEnums.BodyState.BsStand or VmGothicEnums.BodyState.BsWalk - or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSwim or VmGothicEnums.BodyState.BsDive - or VmGothicEnums.BodyState.BsJump or VmGothicEnums.BodyState.BsFall; + // Jumping or falling into the water too (HeroFallService): he swims, not falls. Sneaking stays + // VRHeroMovement's. + var isWaterOrMoving = bodyState is VmGothicEnums.BodyState.BsSwim or VmGothicEnums.BodyState.BsDive + || bodyState.IsAirborne() + || (bodyState.IsLocomotion() && bodyState != VmGothicEnums.BodyState.BsSneak); if (!isWaterOrMoving) return; From f76ec98d44a70d6cf617dbbd68f5fd938bccc150 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 05:22:36 +0000 Subject: [PATCH 21/41] fix: why the hero's falls aren't tracked is an enum (HeroFallHold), no string per frame while he sits or lies - logged once when it changes, also in builds Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Models/Movement/HeroFallHold.cs | 49 ++++++++++++ .../Services/Movement/HeroFallService.cs | 75 ++++++++++++------- 2 files changed, 99 insertions(+), 25 deletions(-) create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroFallHold.cs diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallHold.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallHold.cs new file mode 100644 index 000000000..78c4b5aa9 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallHold.cs @@ -0,0 +1,49 @@ +namespace Gothic.Core.Models.Movement +{ + /// + /// Why HeroFallService doesn't track the hero's jumps and falls right now (no phase, no damage). Logged when it + /// changes - compared every frame, so no string per frame. + /// + public enum HeroFallHold + { + /// + /// Tracked. + /// + None, + + /// + /// Just after a world load or a loaded game - objects under the spawn point may still be loading. + /// + WorldLoading, + + /// + /// A hand holds a ladder or a ledge. + /// + Climbing, + + /// + /// Transformed into a monster (spell) - the transformation falls itself. + /// + Transformed, + + /// + /// No gravity (swimming, diving). + /// + NoGravity, + + /// + /// The water level isn't normal (wading, swimming, diving). + /// + InWater, + + /// + /// The hero's body state is no movement state (BodyStateExtension): mobs, sitting, lying, down, ... + /// + BodyState, + + /// + /// The player was teleported - a new fall starts at the target. + /// + Teleported + } +} diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 0588b45d7..11841503a 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -54,17 +54,19 @@ public class HeroFallService // Lock after a lying landing without the hero's animations: T_FALL_2_FALLEN + S_FALLEN + T_FALLEN_2_STAND (G1). private const float _defaultLyingLandingSeconds = 1.7f; + // Just after a world load or a loaded game, objects under the spawn point may still be loading (bridges, + // platforms): a drop through them meanwhile is no fall. + private const float _settleSeconds = 2f; + private readonly HeroAirborneDomain _airborne = new(); private bool _isLandingLocked; private float _landingUnlockTime; - // Why the hero isn't tracked right now (logged when it changes mid-air), null = tracked. - private string _holdReason; - - // Just after a world load or a loaded game, objects under the spawn point may still be loading (bridges, - // platforms): a drop through them meanwhile is no fall. - private const float _settleSeconds = 2f; private float _settleEndTime; + // Why the hero isn't tracked right now (logged once when it changes), None = tracked. + private HeroFallHold _hold; + // The body state of a HeroFallHold.BodyState hold - another one logs again. + private VmGothicEnums.BodyState _holdBodyState; /// /// The hero's phase this frame (VR hero body: which jump/fall animation). @@ -107,13 +109,13 @@ public void Tick(in HeroFallSample sample) if (hero?.Props == null) return; - var holdReason = Time.time < _settleEndTime ? "world just loaded" : GetHoldReason(hero, sample); - if (holdReason != null) + var hold = Time.time < _settleEndTime ? HeroFallHold.WorldLoading : GetHold(hero, sample); + if (hold != HeroFallHold.None) { - Hold(hero, sample.FeetPosition, holdReason); + Hold(hero, sample.FeetPosition, hold); return; } - _holdReason = null; + _hold = HeroFallHold.None; var safeHeight = NpcFallDomain.GetSafeFallHeight(_gameStateService.GuildValues, hero); switch (_airborne.Tick(sample, safeHeight, out var landing)) @@ -153,45 +155,68 @@ public void OnTeleported(Vector3 feetPosition) { var hero = _npcService.GetHeroContainer(); if (hero?.Props != null) - Hold(hero, feetPosition, "teleported"); + Hold(hero, feetPosition, HeroFallHold.Teleported); else _airborne.Hold(feetPosition); } /// - /// Why the hero isn't tracked now, null if he is. + /// Why the hero isn't tracked now, None if he is. A drawn weapon or a VR melee fight keeps him tracked: like + /// Gothic the hero stays BS_STAND / BS_WALK / BS_RUN / BS_SNEAK then (no BS_FIGHT is set for him). /// - private static string GetHoldReason(NpcContainer hero, in HeroFallSample sample) + private static HeroFallHold GetHold(NpcContainer hero, in HeroFallSample sample) { if (sample.IsClimbing) - return "climbing"; + return HeroFallHold.Climbing; if (sample.IsTransformed) - return "transformed (the transformation falls itself)"; + return HeroFallHold.Transformed; if (sample.Gravity <= 0f) - return "no gravity (swimming, diving)"; + return HeroFallHold.NoGravity; var ai = hero.Vob?.AiHuman; if (ai != null && ai.WaterLevel != (int)ZenGineConst.WaterLevel.Normal) - return "in water"; + return HeroFallHold.InWater; var bodyState = hero.Props.BodyState; - return bodyState.IsLocomotion() || bodyState.IsAirborne() ? null : $"body state {bodyState}"; + return bodyState.IsLocomotion() || bodyState.IsAirborne() ? HeroFallHold.None : HeroFallHold.BodyState; } - private void Hold(NpcContainer hero, Vector3 feet, string reason) + /// + /// Not tracked: a running jump or fall ends without a landing. Logged once when the reason changes (strings are + /// only built then). + /// + private void Hold(NpcContainer hero, Vector3 feet, HeroFallHold hold) { + var bodyState = hero.Props.BodyState; + var isChanged = hold != _hold || (hold == HeroFallHold.BodyState && bodyState != _holdBodyState); var feetY = feet.y; if (_airborne.Phase != HeroAirPhase.Grounded) - Logger.Log($"[HeroFall] {_airborne.Phase} ended without a landing ({reason}) at {feetY:F2}, " + - $"{_airborne.PeakY - feetY:F2} m below the top - no fall damage", LogCat.Npc); - else if (reason != _holdReason) - Logger.LogEditor($"[HeroFall] Not tracked: {reason}", LogCat.Npc); - _holdReason = reason; + Logger.Log($"[HeroFall] {_airborne.Phase} ended without a landing ({Describe(hold, bodyState)}) at " + + $"{feetY:F2}, {_airborne.PeakY - feetY:F2} m below the top - no fall damage", LogCat.Npc); + else if (isChanged) + Logger.Log($"[HeroFall] Not tracked: {Describe(hold, bodyState)}", LogCat.Npc); + _hold = hold; + _holdBodyState = bodyState; _airborne.Hold(feet); EndAirBodyState(hero); } + private static string Describe(HeroFallHold hold, VmGothicEnums.BodyState bodyState) + { + return hold switch + { + HeroFallHold.WorldLoading => "world just loaded", + HeroFallHold.Climbing => "climbing", + HeroFallHold.Transformed => "transformed (the transformation falls itself)", + HeroFallHold.NoGravity => "no gravity (swimming, diving)", + HeroFallHold.InWater => "in water", + HeroFallHold.BodyState => $"body state {bodyState}", + HeroFallHold.Teleported => "teleported", + _ => hold.ToString() + }; + } + /// /// The landing, once: damage from the measured drop (lying landings only), the lying landing's lock, the event /// for the VR body. @@ -297,7 +322,7 @@ private static void EndAirBodyState(NpcContainer hero) private void ResetAll() { _airborne.Reset(); - _holdReason = null; + _hold = HeroFallHold.None; _settleEndTime = Time.time + _settleSeconds; Unlock(); } From 5c4a562be6f1438827117dfb66ae20ef9d63aea8 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 05:23:30 +0000 Subject: [PATCH 22/41] fix: a drop past the lying depth in one step lands lying too - the landing checks the depth again (a hitch at low frame rates landed him on his feet, unhurt) Co-Authored-By: Claude Opus 5.5 --- .../Domain/Movement/HeroAirborneDomain.cs | 16 ++++++-- .../Movement/HeroAirborneDomainTest.cs | 40 +++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs index 4f844b5a7..d26b19dd7 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs @@ -117,7 +117,7 @@ public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLan _hasPrevious = true; if (sample.IsGrounded && !sample.IsJumping) - return TickGrounded(feet.y, out landing); + return TickGrounded(feet.y, sample.Forward, out landing); if (Phase == HeroAirPhase.Grounded) { @@ -185,7 +185,7 @@ public void Reset() _hasLastGrounded = false; } - private HeroAirEvent TickGrounded(float feetY, out HeroLanding landing) + private HeroAirEvent TickGrounded(float feetY, Vector3 forward, out HeroLanding landing) { landing = default; _lastGroundedFeetY = feetY; @@ -194,6 +194,14 @@ private HeroAirEvent TickGrounded(float feetY, out HeroLanding landing) var phase = Phase; var isLying = IsLyingFall; var isBackwards = IsBackwards; + // The landing checks the lying depth again: a drop past it in one step (a low frame rate, a big step, the + // frame right after the fall began) never saw the air check, but lands lying all the same. + if (!isLying && phase is HeroAirPhase.Jumping or HeroAirPhase.Falling && + LyingReferenceY - feetY > LyingDepth) + { + isLying = true; + isBackwards = IsMovingBackwards(forward); + } Phase = HeroAirPhase.Grounded; IsLyingFall = false; IsBackwards = false; @@ -203,7 +211,9 @@ private HeroAirEvent TickGrounded(float feetY, out HeroLanding landing) return HeroAirEvent.None; var height = Mathf.Max(0f, PeakY - feetY); - landing = new HeroLanding(height, phase == HeroAirPhase.Jumping, isLying, isLying && isBackwards); + // Lying, a jump dropped deeper than its take-off allows: no jump's landing. + var isJump = phase == HeroAirPhase.Jumping && !isLying; + landing = new HeroLanding(height, isJump, isLying, isLying && isBackwards); return HeroAirEvent.Landed; } diff --git a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs index 7566dc611..baa087455 100644 --- a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs +++ b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs @@ -239,6 +239,46 @@ public void JumpOffALedgeBecomesAFallFromTheJumpsTop() Assert.AreEqual(10.46f, _landing.Height, 0.05f); } + /// + /// A hitch: the fall begins and lands in the next step, 3 m lower - the air never checked the lying depth, the + /// landing does (on his back, he went over the edge backwards). + /// + [Test] + public void FallPastTheLyingDepthInOneStepLandsLying() + { + Stand(3f); + _moveVelocity = Vector3.back * 1.2f; + Stand(3f); + Tick(2.5f, false, dt: 0.25f); + Assert.AreEqual(HeroAirPhase.Falling, _domain.Phase); + Tick(0f, true, dt: 0.25f); + + Assert.AreEqual(0, _teleports); + Assert.AreEqual(0, _lyingFalls); + Assert.AreEqual(1, _landings); + Assert.IsTrue(_landing.IsLying); + Assert.IsTrue(_landing.IsBackwards); + Assert.AreEqual(3f, _landing.Height, 0.01f); + } + + /// + /// A jump that lands in one step deeper than FALLDOWN_HEIGHT below its take-off lands lying, not as a jump. + /// + [Test] + public void JumpPastFalldownHeightInOneStepLandsLying() + { + Stand(6f); + Tick(6f, true, true); + Assert.AreEqual(HeroAirPhase.Jumping, _domain.Phase); + Tick(0f, true, dt: 0.3f); + + Assert.AreEqual(0, _teleports); + Assert.AreEqual(1, _landings); + Assert.IsTrue(_landing.IsLying); + Assert.IsFalse(_landing.IsJump); + Assert.AreEqual(6f, _landing.Height, 0.01f); + } + [Test] public void SteppingOffASmallEdgeIsNoLanding() { From f916b6cb3774315f0e2e64f9921fcb4a9809500b Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 05:23:58 +0000 Subject: [PATCH 23/41] fix: a lying landing's movement lock also ends on a teleport and on the hero's death - not only by the platform's Tick, which may stop meanwhile Co-Authored-By: Claude Opus 5.5 --- Assets/Gothic-Core/Scripts/Models/Context/PlayerLocks.cs | 2 +- .../Scripts/Services/Movement/HeroFallService.cs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Models/Context/PlayerLocks.cs b/Assets/Gothic-Core/Scripts/Models/Context/PlayerLocks.cs index 58723287b..b1c2c602c 100644 --- a/Assets/Gothic-Core/Scripts/Models/Context/PlayerLocks.cs +++ b/Assets/Gothic-Core/Scripts/Models/Context/PlayerLocks.cs @@ -17,7 +17,7 @@ public enum PlayerLocks Death = 1 << 5, // A spell's state on the hero (sleep, freeze) - HeroSpellStateDomain. SpellState = 1 << 6, - // Getting up after a fall deeper than FALLDOWN_HEIGHT - HeroFallService. + // Lying and getting up after a fall flat (a lying landing) - HeroFallService. FallLanding = 1 << 7 } } diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 11841503a..7e25ccc62 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -96,6 +96,8 @@ public HeroFallService() { GlobalEventDispatcher.LoadGameStart.AddListener(ResetAll); GlobalEventDispatcher.WorldSceneLoaded.AddListener(ResetAll); + // The landing's lock is timed by Tick, which only the platform calls - a dead hero doesn't get up. + GlobalEventDispatcher.HeroDied.AddListener(_ => Unlock()); } /// @@ -149,10 +151,11 @@ public void Tick(in HeroFallSample sample) /// /// The player was teleported (thumbstick, Marvin, AI_Teleport, spawn, loading, ledge/ladder exits): whatever - /// fall ran is dropped, a new one starts at the target. + /// fall ran is dropped, a new one starts at the target. A lying landing's lock ends - he arrives standing. /// public void OnTeleported(Vector3 feetPosition) { + Unlock(); var hero = _npcService.GetHeroContainer(); if (hero?.Props != null) Hold(hero, feetPosition, HeroFallHold.Teleported); @@ -299,6 +302,7 @@ private void Unlock() return; _isLandingLocked = false; _contextInteractionService.UnlockPlayer(PlayerLocks.FallLanding); + Logger.Log("[HeroFall] Lying landing over - movement unlocked", LogCat.Npc); } /// From 7b028bcf5ea3603e530cd1010595c439fbc792b9 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 05:24:29 +0000 Subject: [PATCH 24/41] refactor: fall damage is switched where it is raised - NpcJumpFall checks EnableCombatSystem like HeroFallService checks EnableHeroFallDamage, FightService only applies it Co-Authored-By: Claude Opus 5.5 --- .../Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs | 9 +++++++-- Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs | 4 +++- .../Scripts/Services/Npc/FightService.cs | 13 ++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs b/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs index 622ecf05a..d5f6c0de7 100644 --- a/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs +++ b/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs @@ -6,6 +6,7 @@ using Gothic.Core.Models.Movement; using Gothic.Core.Models.Vm; using Gothic.Core.Services; +using Gothic.Core.Services.Config; using Gothic.Core.Services.Movement; using Gothic.Core.Services.Npc; using Gothic.Core.Services.World; @@ -32,6 +33,7 @@ namespace Gothic.Core.Adapters.Npc public class NpcJumpFall : MonoBehaviour, INpcJumpFall { [Inject] private readonly GameStateService _gameStateService; + [Inject] private readonly ConfigService _configService; [Inject] private readonly AnimationService _animationService; [Inject] private readonly PhysicsService _physicsService; [Inject] private readonly LedgeService _ledgeService; @@ -298,10 +300,13 @@ private void Land(float height) ? new[] { "T_FALL_2_FALLEN", "T_FALLEN_2_STAND" } : new[] { "T_FALLDN_2_STAND" }); + // NPCs' fall damage comes with the combat system, the hero's with HeroFallService (EnableHeroFallDamage). var damage = NpcFallDomain.GetFallDamage(_gameStateService.GuildValues, _npc, height); - if (damage > 0) + var isDamageOn = _configService.Dev.EnableCombatSystem; + if (isDamageOn && damage > 0) GlobalEventDispatcher.FallDamage.Invoke(_npc, damage); - Logger.Log($"[NpcJumpFall] {_npc.Go.name} landed after {height:F1} m.", LogCat.Ai); + Logger.Log($"[NpcJumpFall] {_npc.Go.name} landed after {height:F1} m, fall damage {damage}" + + (isDamageOn || damage <= 0 ? "" : " - not applied (EnableCombatSystem off)"), LogCat.Ai); } /// diff --git a/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs b/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs index 7d546cac2..cc3ea6a90 100644 --- a/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs +++ b/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs @@ -176,7 +176,9 @@ public enum HandSide // A fire hit set the NPC on fire (or keeps it burning longer) - NpcBurnService plays it. public static readonly UnityEvent NpcIgnited = new(); - // NPC landed after a fall higher than FALLDOWN_HEIGHT (damage already minus PROT_FALL). + // NPC or hero landed after a fall higher than FALLDOWN_HEIGHT (damage already minus PROT_FALL). Raised only + // when it applies (NpcJumpFall: EnableCombatSystem, HeroFallService: EnableHeroFallDamage), FightService + // applies it. public static readonly UnityEvent FallDamage = new(); /// diff --git a/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs b/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs index 4dcacb1fd..6652d673d 100644 --- a/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs @@ -81,7 +81,8 @@ public void Init() // Scripts (B_KillNpc), drowning and damage zones kill with or without the combat system. GlobalEventDispatcher.HitPointsDepleted.AddListener(OnHitPointsDepleted); GlobalEventDispatcher.LoadGameStart.AddListener(OnLoadGameStart); - // The hero's falls (HeroFallService, EnableHeroFallDamage) hurt without the combat system, NPCs' with it. + // Fall damage hurts also without the combat system - the raisers decide (NpcJumpFall: EnableCombatSystem, + // HeroFallService: EnableHeroFallDamage). GlobalEventDispatcher.FallDamage.AddListener(OnFallDamage); if (!_configService.Dev.EnableCombatSystem) @@ -171,9 +172,8 @@ public void ReportBlockContact(NpcContainer attacker) } /// - /// Fall damage (NpcJumpFall, the hero's HeroFallService). Like the engine a fall can kill. NPCs only with the - /// combat system (as before), the hero whenever HeroFallService raised it (EnableHeroFallDamage) - except in - /// Marvin's god mode. + /// Fall damage (NpcJumpFall, the hero's HeroFallService): applied as raised - the raisers check their switches. + /// Like the engine a fall can kill. Marvin's god mode ignores it. /// private void OnFallDamage(NpcContainer npc, int damage) { @@ -184,13 +184,12 @@ private void OnFallDamage(NpcContainer npc, int damage) Logger.Log($"[FightService] God mode: the hero's fall damage {damage} is ignored", LogCat.Fight); return; } - if (!_configService.Dev.EnableCombatSystem && !npc.Instance.IsHero(_gameStateService.GothicVm)) - return; // Never below 0, like the engine - the hero's health bar showed negative hit points. var hitPoints = Mathf.Max(npc.Vob.GetAttribute((int)NpcAttribute.HitPoints) - damage, 0); _npcService.SetAttribute(npc, NpcAttribute.HitPoints, hitPoints); - Logger.Log($"[FightService] {npc.Instance.GetName(NpcNameSlot.Slot0)} fall damage {damage} -> HP {hitPoints}", LogCat.Fight); + Logger.Log($"[FightService] {npc.Instance.GetName(NpcNameSlot.Slot0)} fall damage {damage} -> " + + $"HP {hitPoints}", LogCat.Fight); if (hitPoints > 0) return; From 66ea64f3e9a95b7e795257f78679a397b322a203 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 05:25:19 +0000 Subject: [PATCH 25/41] fix: a blocked walk blocks jumping in VRContextInteractionService (any backend), not in the XRI rig - and the rig enables its move and jump providers in one place, the leap included, with null guards Co-Authored-By: Claude Opus 5.5 --- .../Interaction/Backends/Xri/XriRig.cs | 29 ++++++++++++------- .../Context/VRContextInteractionService.cs | 16 +++++++++- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs index 86cfc796a..7c7dd067a 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs @@ -456,8 +456,11 @@ private void OnDestroy() private void Update() { - UpdateClimbLock(); + // UpdateClimbLock is the only place that enables the move and jump providers. It runs after UpdateLeap, so + // a leap that ended this frame gives the stick back at once. The providers' own Update may run before or + // after this one - a leap turns the stick off when it starts (SetLeapVelocity), not here. UpdateLeap(); + UpdateClimbLock(); UpdateSprint(); UpdateCrouch(); } @@ -466,18 +469,25 @@ public void SetLeapVelocity(Vector3 velocity) { velocity.y = 0f; _leapVelocity = velocity; + UpdateClimbLock(); } /// - /// A running jump's leap (SetLeapVelocity): the stick doesn't move the rig meanwhile (the leap is the whole - /// horizontal speed), the CharacterController moves at the leap's velocity - walls stop it. Ends on the ground - /// after the take-off, when climbing and on a teleport. Gravity and the jump's rise stay XRI's. + /// A running jump's leap (SetLeapVelocity): the stick doesn't move the rig meanwhile (UpdateClimbLock), the + /// CharacterController moves at the leap's velocity - walls stop it. Ends on the ground after the take-off, + /// when climbing and on a teleport. Gravity and the jump's rise stay XRI's. /// private void UpdateLeap() { if (_leapVelocity == Vector3.zero) return; + if (_jumpProvider == null || _gravityProvider == null || _characterController == null) + { + _leapVelocity = Vector3.zero; + return; + } + var isLanded = !_jumpProvider.isJumping && (_gravityProvider.isGrounded || _characterController.isGrounded); if (IsClimbing || isLanded || _gravity <= 0f || !_characterController.enabled) { @@ -485,7 +495,6 @@ private void UpdateLeap() return; } - _moveProvider.enabled = false; // Teleports move the transform directly. A CharacterController.Move before the sync would undo them. if (_isTeleportQueued || _lastTeleportFrame == Time.frameCount) return; @@ -493,8 +502,9 @@ private void UpdateLeap() } /// - /// Walking and jumping are off while climbing (the thumbstick would fight the climbing hands), and come - /// back to what the game set (MovementEnabled/CanJump) afterwards. + /// Walking and jumping are off while climbing (the thumbstick would fight the climbing hands), the stick also + /// during a running jump's leap (the leap is the whole horizontal speed), and come back to what the game set + /// (MovementEnabled/CanJump) afterwards. The only place that enables the move and jump providers. /// private void UpdateClimbLock() { @@ -504,9 +514,8 @@ private void UpdateClimbLock() if (isClimbing) _jumpProvider.CancelJump(); - _moveProvider.enabled = _isMovementEnabled && !isClimbing; - // A blocked walk (MovementEnabled: lying after a fall, dialogs, knocked out) blocks jumping as well. - _jumpProvider.enabled = _isJumpEnabled && _isMovementEnabled && !isClimbing; + _moveProvider.enabled = _isMovementEnabled && !isClimbing && _leapVelocity == Vector3.zero; + _jumpProvider.enabled = _isJumpEnabled && !isClimbing; } /// diff --git a/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs b/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs index 1e8cfb162..8e3edbfd6 100644 --- a/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs +++ b/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs @@ -75,6 +75,8 @@ public class VRContextInteractionService : IContextInteractionService private bool _isTeleportAllowedHere = true; // Grabbing is off while swimming and diving (as in G1), whatever the locks say. private bool _isGrabbingAllowedHere = true; + // Jumping is off in water (wading, swimming, diving), whatever the locks say. + private bool _isJumpAllowedHere = true; /// /// The player body of the active VR backend. null before SetupPlayerController(). @@ -398,9 +400,18 @@ private void ApplyBlockedControls() _rig.MovementEnabled = (_blockedControls & PlayerControls.Move) == 0; _rig.TurnEnabled = (_blockedControls & PlayerControls.Turn) == 0; _rig.TeleportEnabled = IsTeleportAllowed(); + _rig.CanJump = IsJumpAllowed(); _rig.SetGrabbingEnabled(IsGrabbingAllowed()); } + /// + /// A blocked walk (lying after a fall, dialogs, knocked out) blocks jumping as well - for any backend. + /// + private bool IsJumpAllowed() + { + return _isJumpAllowedHere && (_blockedControls & PlayerControls.Move) == 0; + } + private bool IsTeleportAllowed() { return _isTeleportAllowedHere && (_blockedControls & PlayerControls.Teleport) == 0; @@ -417,7 +428,8 @@ public void SetWalkingControls() _rig.SetGrabbingEnabled(IsGrabbingAllowed()); _rig.CanCrouch = true; - _rig.CanJump = true; + _isJumpAllowedHere = true; + _rig.CanJump = IsJumpAllowed(); _isTeleportAllowedHere = true; _rig.TeleportEnabled = IsTeleportAllowed(); _rig.StepOffset = _defaultStepOffset; @@ -429,6 +441,7 @@ public void SetWaterWalkingControls() _rig.SetGrabbingEnabled(IsGrabbingAllowed()); _rig.CanCrouch = false; + _isJumpAllowedHere = false; _rig.CanJump = false; _isTeleportAllowedHere = false; _rig.TeleportEnabled = false; @@ -442,6 +455,7 @@ public void SetSwimmingControls() _rig.SetGrabbingEnabled(false); _rig.CanCrouch = false; + _isJumpAllowedHere = false; _rig.CanJump = false; _isTeleportAllowedHere = false; _rig.TeleportEnabled = false; From d89ece87845e935e66e234a536dbd70deb49f0e6 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 05:25:51 +0000 Subject: [PATCH 26/41] refactor: the normal jump's 1 m rise is a VR tunable (VRConstants.HeroNormalJumpRise), not a backend literal Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Interaction/Backends/Xri/GothicJumpProvider.cs | 5 +---- Assets/Gothic-VR/Scripts/VRConstants.cs | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/GothicJumpProvider.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/GothicJumpProvider.cs index ecd8dce29..cf9feac94 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/GothicJumpProvider.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/GothicJumpProvider.cs @@ -22,9 +22,6 @@ public class GothicJumpProvider : JumpProvider private const float _jumpHeightClamp = 4f; // Ours: upper bound of the search in GetJumpHeightForRise. private const float _maxJumpHeight = 8f; - // Ours: how high (m) a normal jump lifts the player. The prefab's jumpHeight 0.46 is XRI's force unit, not - // metres - it lifted him only ~0.3 m. It stays the lower bound. - private const float _normalJumpRise = 1f; private IVrLedgeHandler _handler; private float _gravity = 9.81f; @@ -87,7 +84,7 @@ public void CancelJump() private float GetTakeOffJumpHeight() { // A ledge may want a higher jump (IVrLedgeHandler), never a lower one than the normal jump. - var rise = Mathf.Max(_handler?.GetJumpRise() ?? 0f, _normalJumpRise); + var rise = Mathf.Max(_handler?.GetJumpRise() ?? 0f, VRConstants.HeroNormalJumpRise); return Mathf.Max(_normalJumpHeight, GetJumpHeightForRise(rise, _gravity, maxJumpHoldTime, disableGravityDuringJump)); } diff --git a/Assets/Gothic-VR/Scripts/VRConstants.cs b/Assets/Gothic-VR/Scripts/VRConstants.cs index 85470bf8d..341b6a916 100644 --- a/Assets/Gothic-VR/Scripts/VRConstants.cs +++ b/Assets/Gothic-VR/Scripts/VRConstants.cs @@ -172,6 +172,10 @@ public static float GetTextScale(int textSize) // (TextureService.WeaponTrailOpacity, 1 = Gothic). public const float WeaponTrailOpacity = 0.5f; + // How high (m) a normal jump lifts the VR hero (GothicJumpProvider, the lower bound of every jump). The rig + // prefab's XRI jumpHeight 0.46 is a force unit, not metres - it lifted him only ~0.3 m. + public const float HeroNormalJumpRise = 1f; + /// /// VR melee tunables: hero fists, blocking and the stab finish. Serialized prefab fields stay on the prefab. /// From df013b3d313610bcbd549a00c46e1137560896c1 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 05:26:15 +0000 Subject: [PATCH 27/41] docs: the jump/fall decision record follows the code - a body state change mid-fall drops the fall, the landing re-checks the lying depth, a blocked walk blocks jumping, a drawn weapon changes nothing Co-Authored-By: Claude Opus 5.5 --- Docs/adr/2026-11-29-hero-jump-fall.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md index e784b923e..eb0ed67d0 100644 --- a/Docs/adr/2026-11-29-hero-jump-fall.md +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -15,15 +15,16 @@ In the original game the falling animation starts early and the hero then falls 2. **The damage is computed once, at the landing, from the measured drop: from the highest point of the jump or fall down to where he lands.** Below the safe height it is zero, above it the engine's rule (meters above the safe height times the damage per meter, minus fall protection, never below zero). Nothing ticks while he is in the air, and the falling animations never decide anything: a fall that plays the falling animation, even falling flat and landing lying, and lands within 5 m costs nothing. A jump on flat ground only counts its own small height. **Only a lying landing hurts:** landing on his feet (a jump that doesn't go flat, see 5) costs nothing, also from high up - in the play test the hit points went down without any fall on the face, like a twisted ankle. Not chosen: deriving the height from the impact speed like OpenGothic, because the VR rig's top falling speed would cap it at about 20 m, so a 50 m drop would not kill. 3. **No fall damage in water, on teleports, while climbing, while transformed into a monster, while lying, and in god mode.** Water means any water level (wading, swimming, diving); a teleport is any move by the game or the player (teleport, Marvin, scripts, loading, ledge and ladder exits) and also a step no fall can make in one frame; grabbing a ladder or ledge mid-air ends the fall, and letting go starts a new one from there. A transformed hero falls as the monster's puppet: no damage, his monster's own rules are not applied. Not chosen: monster fall rules for the transformed hero, left for later. 4. **Falling plays Gothic's animations on the VR hero body:** the take-off at its own speed, cut short when he lands first (the running jump's from running, Gothic's jump-up from standing or walking - not its standing forward leap, the VR jump goes straight up), the pose in the air, the short landing; the falling pose, then falling flat, the small landing. Stairs, slopes, small steps and slow lifts are no fall. -5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. A jump is different: he falls flat only when he lands deeper than the safe height (5 m) below where he jumped off, like OpenGothic - not counting the jump's own rise (1 m), so jumping down a steep slope lands on his feet. The damage height still counts from the top. Not chosen: the 2 m for jumps too, or measured from the top of the jump, which laid him on his face after ordinary running jumps downhill (play tests). +5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. A jump is different: he falls flat only when he lands deeper than the safe height (5 m) below where he jumped off, like OpenGothic - not counting the jump's own rise (1 m), so jumping down a steep slope lands on his feet. The damage height still counts from the top. The landing checks the depth again, so a drop past it in a single frame (a hitch) lands lying too. Not chosen: the 2 m for jumps too, or measured from the top of the jump, which laid him on his face after ordinary running jumps downhill (play tests). 6. **A jump at running speed (the sprint) is Gothic's running jump: a long leap forward at the speed of its animation (about 5 m/s for the hero, scaled with the body), in the direction he ran, until he lands.** The stick doesn't add to it in the air, walls stop it, grabbing a ledge or ladder, a teleport or water end it. The standing and walking jump stays straight up; both rise 1 m. The arms don't flail like in Gothic: they are the player's hands. Not chosen: the plain VR jump at running speed, which was a short hop compared to Gothic's leap. 7. **He falls on his back when he went over the edge moving backwards (against where he faces), otherwise on his face.** Each side has its own landing, lying and getting up; if the hero's model lacks the back set, he falls on his face. -8. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** Turning and the hands stay free. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. +8. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** Turning and the hands stay free. A blocked walk blocks jumping too - here, in dialogs and when knocked out. A teleport or his death ends the lock. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. 9. **A new Immersion option decides the view while he lies after a fall flat: the camera stays at the player's head (default), or it goes down with the body and comes back up while he stands up.** The default spares the player a sudden drop of the view after a long fall. Not chosen: reusing the knockout view option, which is about the game taking the hero down, not about a landing the player caused. ## Consequences - Nothing new is saved: a loaded game starts on the ground. - Flat mode can feed the same rules from its own controller once it runs again. -- A knocked-out hero who falls takes no fall damage, and a dialog or video starting mid-fall does not stop the landing's damage. +- A knocked-out hero who falls takes no fall damage. Neither does one whose body state leaves walking, running and sneaking mid-fall (a mob, a script's animation): the fall ends there without a landing. A dialog or video that keeps him standing doesn't stop it - he lands and is hurt. +- A drawn weapon or a fight changes nothing: like in Gothic the hero keeps his standing, walking, running and sneaking states with a weapon in his hand, so his jumps and falls are tracked as usual. - The new option needs its texts (label, description, choices) in the localization tables. From cf21dbff2a5ce24e8064291b62718e78af112bc7 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 05:32:06 +0000 Subject: [PATCH 28/41] chore: meta files of BodyStateExtension and HeroFallHold (generated by Unity on import) Co-Authored-By: Claude Opus 5.5 --- .../Gothic-Core/Scripts/Extensions/BodyStateExtension.cs.meta | 2 ++ Assets/Gothic-Core/Scripts/Models/Movement/HeroFallHold.cs.meta | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 Assets/Gothic-Core/Scripts/Extensions/BodyStateExtension.cs.meta create mode 100644 Assets/Gothic-Core/Scripts/Models/Movement/HeroFallHold.cs.meta diff --git a/Assets/Gothic-Core/Scripts/Extensions/BodyStateExtension.cs.meta b/Assets/Gothic-Core/Scripts/Extensions/BodyStateExtension.cs.meta new file mode 100644 index 000000000..8c12b4ff9 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Extensions/BodyStateExtension.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 79f3dea730046784b8e5b1f03bd7a711 \ No newline at end of file diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallHold.cs.meta b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallHold.cs.meta new file mode 100644 index 000000000..2b8990565 --- /dev/null +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallHold.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e3c2c892d09941a4797814a07718422c \ No newline at end of file From a657f02115e7b06f09931f45e6121ba55732cccd Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 15:43:05 +0000 Subject: [PATCH 29/41] refactor: the hero always takes fall damage - DeveloperConfig.EnableHeroFallDamage was only for testing and goes Co-Authored-By: Claude Opus 5.5 --- Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs | 2 +- Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs | 3 +-- .../Scripts/Models/Config/DeveloperConfig.cs | 5 ----- .../Scripts/Services/Movement/HeroFallService.cs | 10 +++------- .../Gothic-Core/Scripts/Services/Npc/FightService.cs | 2 +- Docs/adr/2026-11-29-hero-jump-fall.md | 2 +- 6 files changed, 7 insertions(+), 17 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs b/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs index d5f6c0de7..afdf1415d 100644 --- a/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs +++ b/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs @@ -300,7 +300,7 @@ private void Land(float height) ? new[] { "T_FALL_2_FALLEN", "T_FALLEN_2_STAND" } : new[] { "T_FALLDN_2_STAND" }); - // NPCs' fall damage comes with the combat system, the hero's with HeroFallService (EnableHeroFallDamage). + // NPCs' fall damage comes with the combat system, the hero's always (HeroFallService). var damage = NpcFallDomain.GetFallDamage(_gameStateService.GuildValues, _npc, height); var isDamageOn = _configService.Dev.EnableCombatSystem; if (isDamageOn && damage > 0) diff --git a/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs b/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs index cc3ea6a90..9e0c6a88f 100644 --- a/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs +++ b/Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs @@ -177,8 +177,7 @@ public enum HandSide // A fire hit set the NPC on fire (or keeps it burning longer) - NpcBurnService plays it. public static readonly UnityEvent NpcIgnited = new(); // NPC or hero landed after a fall higher than FALLDOWN_HEIGHT (damage already minus PROT_FALL). Raised only - // when it applies (NpcJumpFall: EnableCombatSystem, HeroFallService: EnableHeroFallDamage), FightService - // applies it. + // when it applies (NpcJumpFall: EnableCombatSystem, HeroFallService: always), FightService applies it. public static readonly UnityEvent FallDamage = new(); /// diff --git a/Assets/Gothic-Core/Scripts/Models/Config/DeveloperConfig.cs b/Assets/Gothic-Core/Scripts/Models/Config/DeveloperConfig.cs index 33b16dc9a..c47400a2d 100644 --- a/Assets/Gothic-Core/Scripts/Models/Config/DeveloperConfig.cs +++ b/Assets/Gothic-Core/Scripts/Models/Config/DeveloperConfig.cs @@ -186,11 +186,6 @@ public class DebugChannelTypesCollection : CollectionWrapper /// The hero's jumps and falls like the engine's: BS_JUMP / BS_FALL while in the air, fall damage at the landing - /// (DeveloperConfig.EnableHeroFallDamage), lying and getting up after a fall flat. The platform measures (VR: the + /// (always, also without the combat system), lying and getting up after a fall flat. The platform measures (VR: the /// rig port, VrHeroJumpFall) and calls Tick every frame; the phases come from HeroAirborneDomain. /// Pose and damage are separate rules: /// - Pose: S_FALLDN as soon as he falls; a fall deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs), a jump @@ -42,7 +41,6 @@ public class HeroFallService { [Inject] private readonly GameStateService _gameStateService; [Inject] private readonly NpcService _npcService; - [Inject] private readonly ConfigService _configService; [Inject] private readonly ContextInteractionService _contextInteractionService; [Inject] private readonly AnimationService _animationService; @@ -235,7 +233,6 @@ private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, floa LandingCount++; LastLanding = landing; - var isDamageOn = _configService.Dev.EnableHeroFallDamage; // Only a lying landing hurts (author's choice): landing on his feet costs nothing, also from high up - // without the fall on his face the damage looked like a twisted ankle. var damage = landing.IsLying @@ -245,15 +242,14 @@ private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, floa ? landing.IsBackwards ? "lying landing on his back" : "lying landing on his face" : landing.IsJump ? "jump" : "fall"; Logger.Log($"[HeroFall] Landed ({kind}) at {feetY:F2} after {landing.Height:F2} m, FALLDOWN_HEIGHT " + - $"{safeHeight:F1} m, damage {damage}" + - (isDamageOn ? "" : " - not applied (DeveloperConfig.EnableHeroFallDamage off)"), LogCat.Npc); + $"{safeHeight:F1} m, damage {damage}", LogCat.Npc); // Before the damage: a deadly fall's HeroDied comes after it, the VR body knows it lands lying. GlobalEventDispatcher.HeroLanded.Invoke(landing); if (landing.IsLying) LockForLyingLanding(hero, landing.Pose); - if (isDamageOn && damage > 0) + if (damage > 0) GlobalEventDispatcher.FallDamage.Invoke(hero, damage); } diff --git a/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs b/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs index 6652d673d..99d640c4e 100644 --- a/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Npc/FightService.cs @@ -82,7 +82,7 @@ public void Init() GlobalEventDispatcher.HitPointsDepleted.AddListener(OnHitPointsDepleted); GlobalEventDispatcher.LoadGameStart.AddListener(OnLoadGameStart); // Fall damage hurts also without the combat system - the raisers decide (NpcJumpFall: EnableCombatSystem, - // HeroFallService: EnableHeroFallDamage). + // HeroFallService: always). GlobalEventDispatcher.FallDamage.AddListener(OnFallDamage); if (!_configService.Dev.EnableCombatSystem) diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md index eb0ed67d0..45ac1c85f 100644 --- a/Docs/adr/2026-11-29-hero-jump-fall.md +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -11,7 +11,7 @@ In the original game the falling animation starts early and the hero then falls ## Decisions -1. **The hero takes fall damage like in Gothic, with a developer switch that is on in the released game.** The switch works with or without the combat system, NPCs keep their old behaviour (fall damage only with the combat system). Not chosen: tying it to the combat system, which is still a work-in-progress switch, so a cliff would stay harmless for many players. +1. **The hero always takes fall damage like in Gothic, with or without the combat system.** NPCs keep their old behaviour (fall damage only with the combat system). Not chosen: tying it to the combat system, which is still a work-in-progress switch, so a cliff would stay harmless for many players. Not chosen either: a developer switch for it - it was only needed while testing. 2. **The damage is computed once, at the landing, from the measured drop: from the highest point of the jump or fall down to where he lands.** Below the safe height it is zero, above it the engine's rule (meters above the safe height times the damage per meter, minus fall protection, never below zero). Nothing ticks while he is in the air, and the falling animations never decide anything: a fall that plays the falling animation, even falling flat and landing lying, and lands within 5 m costs nothing. A jump on flat ground only counts its own small height. **Only a lying landing hurts:** landing on his feet (a jump that doesn't go flat, see 5) costs nothing, also from high up - in the play test the hit points went down without any fall on the face, like a twisted ankle. Not chosen: deriving the height from the impact speed like OpenGothic, because the VR rig's top falling speed would cap it at about 20 m, so a 50 m drop would not kill. 3. **No fall damage in water, on teleports, while climbing, while transformed into a monster, while lying, and in god mode.** Water means any water level (wading, swimming, diving); a teleport is any move by the game or the player (teleport, Marvin, scripts, loading, ledge and ladder exits) and also a step no fall can make in one frame; grabbing a ladder or ledge mid-air ends the fall, and letting go starts a new one from there. A transformed hero falls as the monster's puppet: no damage, his monster's own rules are not applied. Not chosen: monster fall rules for the transformed hero, left for later. 4. **Falling plays Gothic's animations on the VR hero body:** the take-off at its own speed, cut short when he lands first (the running jump's from running, Gothic's jump-up from standing or walking - not its standing forward leap, the VR jump goes straight up), the pose in the air, the short landing; the falling pose, then falling flat, the small landing. Stairs, slopes, small steps and slow lifts are no fall. From cd8985b8b7c3a7c386e74a58a815b90e287fb1f0 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 15:44:18 +0000 Subject: [PATCH 30/41] refactor: HeroFallPose is FallPose - a HUMANS.MDS property, not the hero's - and NpcJumpFall falls and lands with FallPose.Front instead of its own literals Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Npc/NpcJumpFall.cs | 6 +++--- .../Domain/Movement/HeroAirborneDomain.cs | 4 ++-- .../Movement/{HeroFallPose.cs => FallPose.cs} | 17 +++++++++-------- .../{HeroFallPose.cs.meta => FallPose.cs.meta} | 0 .../Scripts/Models/Movement/HeroLanding.cs | 6 +++--- .../Services/Movement/HeroFallService.cs | 14 +++++++------- .../Scripts/Adapters/Player/VrHeroDownPose.cs | 4 ++-- .../Scripts/Adapters/Player/VrHeroLocomotion.cs | 4 ++-- 8 files changed, 28 insertions(+), 27 deletions(-) rename Assets/Gothic-Core/Scripts/Models/Movement/{HeroFallPose.cs => FallPose.cs} (57%) rename Assets/Gothic-Core/Scripts/Models/Movement/{HeroFallPose.cs.meta => FallPose.cs.meta} (100%) diff --git a/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs b/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs index afdf1415d..b88f01536 100644 --- a/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs +++ b/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs @@ -272,10 +272,10 @@ private void TickFall() transform.position = position + moveH + Vector3.up * moveY; var fallen = _fallStartFeetY - (transform.position.y - RestHeight); - if (fallen > NpcFallDomain.LyingFallHeight && _fallAnimName != "S_FALL") + if (fallen > NpcFallDomain.LyingFallHeight && _fallAnimName != FallPose.Front.Flight) { _npc.PrefabProps.AnimationSystem.StopAnimation(_fallAnimName); - _fallAnimName = "S_FALL"; + _fallAnimName = FallPose.Front.Flight; PlayIfExists(_fallAnimName); } else if (!_npc.PrefabProps.AnimationSystem.IsPlaying(_fallAnimName)) @@ -297,7 +297,7 @@ private void Land(float height) var isDeep = height > NpcFallDomain.LyingFallHeight || _isThrown; _isThrown = false; StartSequence(State.Landing, isDeep - ? new[] { "T_FALL_2_FALLEN", "T_FALLEN_2_STAND" } + ? new[] { FallPose.Front.Landing, FallPose.Front.StandUp } : new[] { "T_FALLDN_2_STAND" }); // NPCs' fall damage comes with the combat system, the hero's always (HeroFallService). diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs index d26b19dd7..196ddd0bf 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs @@ -66,13 +66,13 @@ public class HeroAirborneDomain public float TakeOffY { get; private set; } /// - /// Falling deeper than NpcFallDomain.LyingFallHeight so far: he falls flat (HeroFallPose.Flight) and will land + /// Falling deeper than NpcFallDomain.LyingFallHeight so far: he falls flat (FallPose.Flight) and will land /// lying. Pose only. /// public bool IsLyingFall { get; private set; } /// - /// The fall flat is on his back (HeroFallPose.Back): he moved against his facing when it began. + /// The fall flat is on his back (FallPose.Back): he moved against his facing when it began. /// public bool IsBackwards { get; private set; } diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs b/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs similarity index 57% rename from Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs rename to Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs index 71e35d5a3..3dc8930f6 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs @@ -1,16 +1,17 @@ namespace Gothic.Core.Models.Movement { /// - /// The animations of a fall flat (deeper than NpcFallDomain.LyingFallHeight): on his face, or on his back when he - /// went over the edge backwards. HUMANS.MDS of G1 and G2 have both sets. + /// The animations of a fall flat (deeper than NpcFallDomain.LyingFallHeight) in HUMANS.MDS: on the face, or on the + /// back after going over the edge backwards. G1 and G2 have both sets. The hero falls on either (HeroFallService), + /// NPCs on the front only (NpcJumpFall). /// - public readonly struct HeroFallPose + public readonly struct FallPose { - public static readonly HeroFallPose Front = new("S_FALL", "T_FALL_2_FALLEN", "S_FALLEN", "T_FALLEN_2_STAND", + public static readonly FallPose Front = new("S_FALL", "T_FALL_2_FALLEN", "S_FALLEN", "T_FALLEN_2_STAND", "S_DEAD"); - public static readonly HeroFallPose Back = new("S_FALLB", "T_FALLB_2_FALLENB", "S_FALLENB", - "T_FALLENB_2_STAND", "S_DEADB"); + public static readonly FallPose Back = new("S_FALLB", "T_FALLB_2_FALLENB", "S_FALLENB", "T_FALLENB_2_STAND", + "S_DEADB"); /// /// In the air once the drop is deeper than LyingFallHeight. @@ -34,7 +35,7 @@ public readonly struct HeroFallPose /// public readonly string Dead; - private HeroFallPose(string flight, string landing, string lying, string standUp, string dead) + private FallPose(string flight, string landing, string lying, string standUp, string dead) { Flight = flight; Landing = landing; @@ -43,6 +44,6 @@ private HeroFallPose(string flight, string landing, string lying, string standUp Dead = dead; } - public static HeroFallPose Get(bool isBackwards) => isBackwards ? Back : Front; + public static FallPose Get(bool isBackwards) => isBackwards ? Back : Front; } } diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs.meta b/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs.meta similarity index 100% rename from Assets/Gothic-Core/Scripts/Models/Movement/HeroFallPose.cs.meta rename to Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs.meta diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs index 0c4fad367..9ac5790d8 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs @@ -20,13 +20,13 @@ public readonly struct HeroLanding public readonly bool IsJump; /// - /// He fell flat (deeper than NpcFallDomain.LyingFallHeight): lands lying (HeroFallPose.Landing), lies a moment + /// He fell flat (deeper than NpcFallDomain.LyingFallHeight): lands lying (FallPose.Landing), lies a moment /// and gets up, walking locked meanwhile. Only the pose, not the damage. /// public readonly bool IsLying; /// - /// Lying on his back (HeroFallPose.Back): he went over the edge backwards. Otherwise on his face. + /// Lying on his back (FallPose.Back): he went over the edge backwards. Otherwise on his face. /// public readonly bool IsBackwards; @@ -38,6 +38,6 @@ public HeroLanding(float height, bool isJump, bool isLying, bool isBackwards) IsBackwards = isBackwards; } - public HeroFallPose Pose => HeroFallPose.Get(IsBackwards); + public FallPose Pose => FallPose.Get(IsBackwards); } } diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 10add1f77..dbce05f94 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -21,7 +21,7 @@ namespace Gothic.Core.Services.Movement /// rig port, VrHeroJumpFall) and calls Tick every frame; the phases come from HeroAirborneDomain. /// Pose and damage are separate rules: /// - Pose: S_FALLDN as soon as he falls; a fall deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs), a jump - /// deeper than FALLDOWN_HEIGHT below its take-off (like OpenGothic), falls flat (HeroFallPose: on his face, on + /// deeper than FALLDOWN_HEIGHT below its take-off (like OpenGothic), falls flat (FallPose: on his face, on /// his back when he went over the edge backwards) and lands lying - he lies a moment and gets up, walking locked /// meanwhile. /// - Damage - one place, once per landing, never per frame: only a lying landing hurts (landing on his feet costs @@ -45,7 +45,7 @@ public class HeroFallService [Inject] private readonly AnimationService _animationService; /// - /// The hero lies this long (HeroFallPose.Lying) after a fall flat before he gets up (HeroFallPose.StandUp). + /// The hero lies this long (FallPose.Lying) after a fall flat before he gets up (FallPose.StandUp). /// public const float FallenHoldSeconds = 0.3f; @@ -72,13 +72,13 @@ public class HeroFallService public HeroAirPhase Phase => _airborne.Phase; /// - /// Falling deeper than NpcFallDomain.LyingFallHeight: he falls flat (HeroFallPose.Flight) instead of S_FALLDN + /// Falling deeper than NpcFallDomain.LyingFallHeight: he falls flat (FallPose.Flight) instead of S_FALLDN /// and lands lying. Pose only - no damage until the landing, and only above FALLDOWN_HEIGHT. /// public bool IsLyingFall => _airborne.IsLyingFall; /// - /// The fall flat is on his back (HeroFallPose.Back) - the landing falls back to the front set when the model + /// The fall flat is on his back (FallPose.Back) - the landing falls back to the front set when the model /// lacks the back animations (LastLanding). /// public bool IsFallingBackwards => _airborne.IsBackwards; @@ -225,7 +225,7 @@ private static string Describe(HeroFallHold hold, VmGothicEnums.BodyState bodySt private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, float feetY) { // On his back only with the model's back set - else on his face. - if (landing.IsBackwards && !HasPose(hero, HeroFallPose.Back)) + if (landing.IsBackwards && !HasPose(hero, FallPose.Back)) { Logger.Log("[HeroFall] No back fall animations - lands on his face", LogCat.Npc); landing = new HeroLanding(landing.Height, landing.IsJump, landing.IsLying, false); @@ -257,7 +257,7 @@ private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, floa /// He lies and gets up: no walking or teleporting until then (turning and the hands stay free). As long as the /// pose's landing, lying and standing up take. /// - private void LockForLyingLanding(NpcContainer hero, HeroFallPose pose) + private void LockForLyingLanding(NpcContainer hero, FallPose pose) { var seconds = GetAnimationSeconds(hero, pose.Landing) + FallenHoldSeconds + GetAnimationSeconds(hero, pose.StandUp); @@ -274,7 +274,7 @@ private void LockForLyingLanding(NpcContainer hero, HeroFallPose pose) /// The hero's model can land in this pose and get up from it (lying itself may be missing - then he holds the /// landing's last frame). /// - private bool HasPose(NpcContainer hero, HeroFallPose pose) + private bool HasPose(NpcContainer hero, FallPose pose) { return GetAnimationSeconds(hero, pose.Landing) > 0f && GetAnimationSeconds(hero, pose.StandUp) > 0f; } diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs index 7f3afcb41..25b32548b 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs @@ -29,7 +29,7 @@ namespace Gothic.VR.Adapters.Player /// death menu. Tells VRPlayerService whether a body that can fall exists (SetHeroFallBody); "blink" leaves the /// view to VrKnockoutView. /// A fall flat (HeroLanded, IsLying: deeper than 2 m - not tied to the damage) lands him lying in the landing's - /// HeroFallPose - on his face T_FALL_2_FALLEN, S_FALLEN for HeroFallService.FallenHoldSeconds, T_FALLEN_2_STAND, on + /// FallPose - on his face T_FALL_2_FALLEN, S_FALLEN for HeroFallService.FallenHoldSeconds, T_FALLEN_2_STAND, on /// his back the same with FALLB/FALLENB - whatever heroFallMode is; the Immersion option heroLandingView decides /// whether the camera goes with the head (VRPlayerService.HeroLandingView, default: it stays at the player's head). /// HeroFallService locks walking meanwhile. Killed by the fall, he stays lying dead (S_DEAD, on his back S_DEADB). @@ -78,7 +78,7 @@ private enum DownPhase private bool _isAsleep; // A lying landing (HeroLanded) to lie down for, when it was raised, and its pose (face or back). private bool _isLanding; - private HeroFallPose _landingPose = HeroFallPose.Front; + private FallPose _landingPose = FallPose.Front; private float _landedTime; // This down started as a landing: its camera follows the head only with heroLandingView "move with body". private bool _isLandingDown; diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs index c2ff2f2f4..a78e1c9ba 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs @@ -280,10 +280,10 @@ private string GetFallAnimation() { if (!_heroFallService.IsLyingFall) return _fallAnimation; - var flight = HeroFallPose.Get(_heroFallService.IsFallingBackwards).Flight; + var flight = FallPose.Get(_heroFallService.IsFallingBackwards).Flight; if (_animator.HasAnimation(flight)) return flight; - return _animator.HasAnimation(HeroFallPose.Front.Flight) ? HeroFallPose.Front.Flight : _fallAnimation; + return _animator.HasAnimation(FallPose.Front.Flight) ? FallPose.Front.Flight : _fallAnimation; } /// From 773243fa37a11fe5c64ff09c3b31f42a1074f6ff Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 15:46:01 +0000 Subject: [PATCH 31/41] refactor: the smallest drop that falls is the platform's ground snap (HeroFallSample.GroundSnapHeight from IVrRig) - no Core constant mirroring the XRI rig's 0.3 m Co-Authored-By: Claude Opus 5.5 --- .../Domain/Movement/HeroAirborneDomain.cs | 16 ++++++--------- .../Scripts/Models/Movement/HeroFallSample.cs | 9 ++++++++- .../Movement/HeroAirborneDomainTest.cs | 20 ++++++++++++++++++- .../Scripts/Adapters/Player/VrHeroJumpFall.cs | 2 +- .../Interaction/Backends/Xri/XriRig.cs | 9 ++++++++- .../Scripts/Interaction/Ports/IVrRig.cs | 6 ++++++ 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs index 196ddd0bf..abe9ca6ab 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs @@ -18,7 +18,8 @@ namespace Gothic.Core.Domain.Movement /// like OpenGothic - the jump's own rise doesn't count, and a jump down a steep slope lands on his feet. A jump /// stays a jump (its pose in the air, the jump's landing) until that deep. /// - No fall without real falling: off the ground (beyond the platform's grounded grace) the hero falls only when - /// moving down faster than FallSpeed and below MinFallDrop - stairs, slopes and lifts stay walking. + /// moving down faster than FallSpeed and deeper below the top than the platform's ground snap + /// (HeroFallSample.GroundSnapHeight) - stairs, slopes and lifts stay walking. /// public class HeroAirborneDomain { @@ -27,12 +28,6 @@ public class HeroAirborneDomain /// public const float FallSpeed = 1f; - /// - /// m below the highest point before a fall counts - the rig's ground snap (0.3 m) covers smaller steps. - /// - public const float MinFallDrop = 0.3f; - - // One frame's step beyond what falling (terminal speed) or jumping can do: a teleport nobody announced. private const float _teleportTolerance = 1f; private const float _teleportRise = 2f; @@ -138,7 +133,8 @@ public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLan return HeroAirEvent.JumpStarted; } - if (Phase is HeroAirPhase.Airborne or HeroAirPhase.Jumping && IsFalling(feet.y, verticalSpeed)) + if (Phase is HeroAirPhase.Airborne or HeroAirPhase.Jumping && + IsFalling(feet.y, verticalSpeed, sample.GroundSnapHeight)) { Phase = HeroAirPhase.Falling; return HeroAirEvent.FallStarted; @@ -217,14 +213,14 @@ private HeroAirEvent TickGrounded(float feetY, Vector3 forward, out HeroLanding return HeroAirEvent.Landed; } - private bool IsFalling(float feetY, float verticalSpeed) + private bool IsFalling(float feetY, float verticalSpeed, float groundSnapHeight) { if (verticalSpeed >= 0f) return false; // A jump becomes a fall only once it's deeper than its lying depth (FALLDOWN_HEIGHT) below the take-off. if (Phase == HeroAirPhase.Jumping) return feetY < TakeOffY - _jumpLyingDepth; - return verticalSpeed <= -FallSpeed && PeakY - feetY >= MinFallDrop; + return verticalSpeed <= -FallSpeed && PeakY - feetY >= groundSnapHeight; } /// diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs index 006b8e8ce..5565b9a69 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs @@ -48,12 +48,18 @@ public readonly struct HeroFallSample /// public readonly float MaxFallSpeed; + /// + /// m the platform pulls the feet down to the ground per frame (VR: the rig's ground snap) - a drop within it is + /// a step or a slope, no fall. + /// + public readonly float GroundSnapHeight; + public readonly float DeltaTime; public float FeetY => FeetPosition.y; public HeroFallSample(Vector3 feetPosition, Vector3 forward, bool isGrounded, bool isJumping, bool isClimbing, - bool isTransformed, float gravity, float maxFallSpeed, float deltaTime) + bool isTransformed, float gravity, float maxFallSpeed, float groundSnapHeight, float deltaTime) { FeetPosition = feetPosition; Forward = forward; @@ -63,6 +69,7 @@ public HeroFallSample(Vector3 feetPosition, Vector3 forward, bool isGrounded, bo IsTransformed = isTransformed; Gravity = gravity; MaxFallSpeed = maxFallSpeed; + GroundSnapHeight = groundSnapHeight; DeltaTime = deltaTime; } } diff --git a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs index baa087455..f92090d1f 100644 --- a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs +++ b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs @@ -19,6 +19,8 @@ public class HeroAirborneDomainTest private const float _safeHeight = 5f; private HeroAirborneDomain _domain; + // The platform's ground snap (the XRI rig's 0.3 m). + private float _groundSnapHeight; private HeroLanding _landing; private int _landings; private int _falls; @@ -33,6 +35,7 @@ public class HeroAirborneDomainTest public void SetUp() { _domain = new HeroAirborneDomain(); + _groundSnapHeight = 0.3f; _landing = default; _landings = 0; _falls = 0; @@ -47,7 +50,7 @@ private void Tick(float feetY, bool isGrounded, bool isJumping = false, float dt { _feet = new Vector3(_feet.x, feetY, _feet.z) + _moveVelocity * dt; var sample = new HeroFallSample(_feet, _forward, isGrounded, isJumping, false, false, _gravity, - _maxFallSpeed, dt); + _maxFallSpeed, _groundSnapHeight, dt); switch (_domain.Tick(sample, _safeHeight, out var landing)) { case HeroAirEvent.Landed: @@ -289,6 +292,21 @@ public void SteppingOffASmallEdgeIsNoLanding() Assert.AreEqual(0, _landings); } + /// + /// The small edge is no step only by the platform's ground snap: without one the drop is a fall. + /// + [Test] + public void WithoutGroundSnapASmallEdgeIsAFall() + { + _groundSnapHeight = 0f; + Stand(0.2f); + FallTo(0.2f, 0f); + + Assert.AreEqual(1, _falls); + Assert.AreEqual(1, _landings); + Assert.AreEqual(0.2f, _landing.Height, 0.01f); + } + [Test] public void SlowLiftIsNoFall() { diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs index d62df2f8b..d32f309b8 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs @@ -63,7 +63,7 @@ private void Update() var sample = new HeroFallSample(feet, GetFacing(), _rig.IsGrounded, _rig.IsJumping, _rig.IsClimbing, _vrSpellTransformService != null && _vrSpellTransformService.IsTransformed, _rig.Gravity, - _rig.MaxFallSpeed, Time.deltaTime); + _rig.MaxFallSpeed, _rig.GroundSnapHeight, Time.deltaTime); _heroFallService.Tick(sample); UpdateLeap(); } diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs index 7c7dd067a..0f9cec68f 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs @@ -199,6 +199,13 @@ public bool IsGrounded /// public bool IsJumping => _jumpProvider != null && _jumpProvider.isJumping; + /// + /// The ground snap's reach per frame (SnapToGround): the snap distance, at most the step offset. + /// + public float GroundSnapHeight => _snapToGround + ? Mathf.Min(_groundSnapDistance, _characterController.stepOffset) + : 0f; + /// /// Height the origin adds below the HMD (Device mode's CameraYOffset, 0 on the floor) and the tracking space's /// scale (Standing) - XriHvrStyleSimulator keeps the simulated eyes at a fixed height with them. @@ -577,7 +584,7 @@ private void SnapToGround() var bottom = _characterController.transform.TransformPoint(_characterController.center) - up * (_characterController.height * 0.5f); var origin = bottom + up * (radius + skinWidth); - var maxDistance = Mathf.Min(_groundSnapDistance, _characterController.stepOffset) + 2f * skinWidth; + var maxDistance = GroundSnapHeight + 2f * skinWidth; if (!Physics.SphereCast(origin, radius, -up, out var hit, maxDistance, _collidingLayers, QueryTriggerInteraction.Ignore)) diff --git a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs index 7f7d334fb..b8423ddb2 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs @@ -46,6 +46,12 @@ public interface IVrRig /// bool IsJumping => false; + /// + /// How far in m the backend pulls the player down to the ground per frame (slopes, stairs) - a smaller drop is + /// no fall for the hero (HeroFallSample). Default: 0, for backends without snapping. + /// + float GroundSnapHeight => 0f; + /// /// A running jump's leap (Gothic's T_RUNL_2_JUMP): the rig moves horizontally at this velocity (m/s) until it /// lands, instead of the stick's movement - not on top of it. Vector3.zero ends it; the backend also ends it on From 12ae8e8bd9d5d364c068f2fe8639e4754c955253 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 15:48:49 +0000 Subject: [PATCH 32/41] refactor: Core decides the running jump (HeroAirborneDomain.IsRunningJump: the take-off's speed against HeroFallSample.RunSpeed) - VR only leaps, VRPlayerService.IsRunningJump goes Co-Authored-By: Claude Opus 5.5 --- .../Domain/Movement/HeroAirborneDomain.cs | 13 +++++ .../Scripts/Models/Movement/HeroFallSample.cs | 10 +++- .../Services/Movement/HeroFallService.cs | 9 +++- .../Movement/HeroAirborneDomainTest.cs | 47 ++++++++++++++++++- .../Scripts/Adapters/Player/VrHeroJumpFall.cs | 34 +++++++------- .../Adapters/Player/VrHeroLocomotion.cs | 4 +- .../Scripts/Services/VRPlayerService.cs | 6 --- Docs/adr/2026-11-29-hero-jump-fall.md | 2 +- 8 files changed, 96 insertions(+), 29 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs index abe9ca6ab..b78d4cdd3 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs @@ -17,6 +17,8 @@ namespace Gothic.Core.Domain.Movement /// below where it started; a jump only deeper than the guild's FALLDOWN_HEIGHT (5 m human) below its take-off, /// like OpenGothic - the jump's own rise doesn't count, and a jump down a steep slope lands on his feet. A jump /// stays a jump (its pose in the air, the jump's landing) until that deep. + /// - A jump taken at running speed (HeroFallSample.RunSpeed) is Gothic's running jump (IsRunningJump), the + /// platform makes it the leap. /// - No fall without real falling: off the ground (beyond the platform's grounded grace) the hero falls only when /// moving down faster than FallSpeed and deeper below the top than the platform's ground snap /// (HeroFallSample.GroundSnapHeight) - stairs, slopes and lifts stay walking. @@ -71,6 +73,12 @@ public class HeroAirborneDomain /// public bool IsBackwards { get; private set; } + /// + /// The current jump was taken at running speed: Gothic's running jump (T_RUNL_2_JUMP, a leap forward), until + /// the landing - also when it becomes a fall. + /// + public bool IsRunningJump { get; private set; } + /// /// Where the depth for falling flat is measured from: a jump's take-off, else the fall's start (its top). /// The landing's damage height is always from the top (PeakY). @@ -121,6 +129,7 @@ public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLan TakeOffY = PeakY; IsLyingFall = false; IsBackwards = false; + IsRunningJump = false; _isFromJump = false; Phase = HeroAirPhase.Airborne; } @@ -130,6 +139,7 @@ public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLan { Phase = HeroAirPhase.Jumping; _isFromJump = true; + IsRunningJump = sample.RunSpeed > 0f && _moveVelocity.sqrMagnitude >= sample.RunSpeed * sample.RunSpeed; return HeroAirEvent.JumpStarted; } @@ -159,6 +169,7 @@ public void Hold(Vector3 feet) Phase = HeroAirPhase.Grounded; IsLyingFall = false; IsBackwards = false; + IsRunningJump = false; _isFromJump = false; _moveVelocity = Vector3.zero; _previousFeet = feet; @@ -175,6 +186,7 @@ public void Reset() Phase = HeroAirPhase.Grounded; IsLyingFall = false; IsBackwards = false; + IsRunningJump = false; _isFromJump = false; _moveVelocity = Vector3.zero; _hasPrevious = false; @@ -201,6 +213,7 @@ private HeroAirEvent TickGrounded(float feetY, Vector3 forward, out HeroLanding Phase = HeroAirPhase.Grounded; IsLyingFall = false; IsBackwards = false; + IsRunningJump = false; // A step down or a flicker: no jump, no fall - no landing. if (phase is HeroAirPhase.Grounded or HeroAirPhase.Airborne) diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs index 5565b9a69..61fb71266 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroFallSample.cs @@ -54,12 +54,19 @@ public readonly struct HeroFallSample /// public readonly float GroundSnapHeight; + /// + /// m/s horizontally from which the hero runs (VR: VrHeroSpeeds.RunThreshold, where BS_RUN starts) - a jump + /// taken this fast is a running jump. 0: no running jumps. + /// + public readonly float RunSpeed; + public readonly float DeltaTime; public float FeetY => FeetPosition.y; public HeroFallSample(Vector3 feetPosition, Vector3 forward, bool isGrounded, bool isJumping, bool isClimbing, - bool isTransformed, float gravity, float maxFallSpeed, float groundSnapHeight, float deltaTime) + bool isTransformed, float gravity, float maxFallSpeed, float groundSnapHeight, float runSpeed, + float deltaTime) { FeetPosition = feetPosition; Forward = forward; @@ -70,6 +77,7 @@ public HeroFallSample(Vector3 feetPosition, Vector3 forward, bool isGrounded, bo Gravity = gravity; MaxFallSpeed = maxFallSpeed; GroundSnapHeight = groundSnapHeight; + RunSpeed = runSpeed; DeltaTime = deltaTime; } } diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index dbce05f94..1d7c59775 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -83,6 +83,12 @@ public class HeroFallService /// public bool IsFallingBackwards => _airborne.IsBackwards; + /// + /// The jump running now was taken at running speed: Gothic's running jump - the platform leaps forward (VR: + /// VrHeroJumpFall) and plays T_RUNL_2_JUMP, a jump-up otherwise. From the take-off until the landing. + /// + public bool IsRunningJump => _airborne.IsRunningJump; + /// /// Counts the landings - a new value: LastLanding just happened (the VR hero body picks the landing animation). /// @@ -122,7 +128,8 @@ public void Tick(in HeroFallSample sample) { case HeroAirEvent.JumpStarted: SetAirBodyState(hero, VmGothicEnums.BodyState.BsJump); - Logger.Log($"[HeroFall] Jump from {_airborne.TakeOffY:F2}", LogCat.Npc); + Logger.Log($"[HeroFall] {(_airborne.IsRunningJump ? "Running jump" : "Jump")} from " + + $"{_airborne.TakeOffY:F2} (running from {sample.RunSpeed:F2} m/s)", LogCat.Npc); break; case HeroAirEvent.FallStarted: SetAirBodyState(hero, VmGothicEnums.BodyState.BsFall); diff --git a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs index f92090d1f..c99f4a49b 100644 --- a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs +++ b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs @@ -17,6 +17,8 @@ public class HeroAirborneDomainTest private const float _maxFallSpeed = 20f; // FALLDOWN_HEIGHT of humans: a jump falls flat only this far below its take-off. private const float _safeHeight = 5f; + // From this horizontal speed the hero runs (VR: halfway between walking and running). + private const float _runSpeed = 2.5f; private HeroAirborneDomain _domain; // The platform's ground snap (the XRI rig's 0.3 m). @@ -50,7 +52,7 @@ private void Tick(float feetY, bool isGrounded, bool isJumping = false, float dt { _feet = new Vector3(_feet.x, feetY, _feet.z) + _moveVelocity * dt; var sample = new HeroFallSample(_feet, _forward, isGrounded, isJumping, false, false, _gravity, - _maxFallSpeed, _groundSnapHeight, dt); + _maxFallSpeed, _groundSnapHeight, _runSpeed, dt); switch (_domain.Tick(sample, _safeHeight, out var landing)) { case HeroAirEvent.Landed: @@ -105,6 +107,49 @@ public void JumpOnFlatGroundLandsAsJumpWithItsOwnHeight() Assert.AreEqual(0.46f, _landing.Height, 0.05f); } + /// + /// Taken at running speed: Gothic's running jump (the leap) from the take-off until the landing. + /// + [Test] + public void JumpAtRunningSpeedIsARunningJumpUntilTheLanding() + { + _moveVelocity = Vector3.forward * 4f; + Stand(0f); + Tick(0f, true, true); + Assert.AreEqual(HeroAirPhase.Jumping, _domain.Phase); + Assert.IsTrue(_domain.IsRunningJump); + Tick(0.05f, false, true); + Assert.IsTrue(_domain.IsRunningJump); + FallTo(0.05f, 0f - 0.0001f, 3f, true); + + Assert.AreEqual(1, _landings); + Assert.IsTrue(_landing.IsJump); + Assert.IsFalse(_domain.IsRunningJump); + } + + [Test] + public void JumpAtWalkingSpeedIsNoRunningJump() + { + _moveVelocity = Vector3.forward * 1.2f; + Stand(0f); + Tick(0f, true, true); + + Assert.AreEqual(HeroAirPhase.Jumping, _domain.Phase); + Assert.IsFalse(_domain.IsRunningJump); + } + + [Test] + public void RunningOffAnEdgeIsNoRunningJump() + { + _moveVelocity = Vector3.forward * 4f; + Stand(3f); + Tick(2.9f, false); + Tick(2.6f, false); + + Assert.AreEqual(HeroAirPhase.Falling, _domain.Phase); + Assert.IsFalse(_domain.IsRunningJump); + } + [Test] public void SmallFallLandsStanding() { diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs index d32f309b8..db18cdfa3 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs @@ -12,11 +12,12 @@ namespace Gothic.VR.Adapters.Player { /// /// Feeds the hero's jumps and falls (HeroFallService: body state, fall damage, lying landing) from the VR rig port: - /// feet height, grounded (with the rig's grace time), jumping, climbing, gravity, teleports. Measures only - the - /// rules are in Core. Sits next to VRPlayer (added by VRContextInteractionService). - /// A jump taken at running speed (VrHeroSpeeds.RunThreshold, the sprint) is Gothic's running jump: a long leap at - /// T_RUNL_2_JUMP's forward speed (VrHeroSpeeds.RunJump) in the direction of the run, until he lands, grabs or is - /// teleported (IVrRig.SetLeapVelocity). The standing and walking jump stays straight up. + /// feet height, grounded (with the rig's grace time), jumping, climbing, gravity, ground snap, the speed he runs + /// from (VrHeroSpeeds.RunThreshold), teleports. Measures only - the rules are in Core. + /// Sits next to VRPlayer (added by VRContextInteractionService). + /// A running jump (HeroFallService.IsRunningJump, the sprint) is a long leap at T_RUNL_2_JUMP's forward speed + /// (VrHeroSpeeds.RunJump) in the direction of the run, until he lands, grabs or is teleported + /// (IVrRig.SetLeapVelocity). The standing and walking jump stays straight up. /// public class VrHeroJumpFall : MonoBehaviour { @@ -63,7 +64,7 @@ private void Update() var sample = new HeroFallSample(feet, GetFacing(), _rig.IsGrounded, _rig.IsJumping, _rig.IsClimbing, _vrSpellTransformService != null && _vrSpellTransformService.IsTransformed, _rig.Gravity, - _rig.MaxFallSpeed, _rig.GroundSnapHeight, Time.deltaTime); + _rig.MaxFallSpeed, _rig.GroundSnapHeight, _vrPlayerService.HeroSpeeds.RunThreshold, Time.deltaTime); _heroFallService.Tick(sample); UpdateLeap(); } @@ -80,8 +81,8 @@ private void UpdateHorizontalVelocity(Vector3 feet) } /// - /// The leap starts with a jump at running speed and lasts while he is in the air (jumping or falling) - landing, - /// water, a ledge or ladder, a teleport end it (HeroFallService's phase is back on the ground then). + /// The leap starts with a running jump and lasts while he is in the air (jumping or falling) - landing, water, + /// a ledge or ladder, a teleport end it (HeroFallService's phase is back on the ground then). /// private void UpdateLeap() { @@ -91,19 +92,19 @@ private void UpdateLeap() if (phase == HeroAirPhase.Jumping && previousPhase != HeroAirPhase.Jumping) { - var speeds = _vrPlayerService.HeroSpeeds; - var speed = _horizontalVelocity.magnitude; - _vrPlayerService.IsRunningJump = speed >= speeds.RunThreshold; - if (!_vrPlayerService.IsRunningJump) + if (!_heroFallService.IsRunningJump) return; - var leap = _horizontalVelocity / speed * speeds.RunJump; - _rig.SetLeapVelocity(leap); + var runJump = _vrPlayerService.HeroSpeeds.RunJump; + var direction = _horizontalVelocity.sqrMagnitude > 0.0001f + ? _horizontalVelocity.normalized + : GetFacing().normalized; + _rig.SetLeapVelocity(direction * runJump); _isLeaping = true; _leapStart = _rig.Root.position; _leapStartTime = Time.time; - Logger.Log($"[VrHeroJumpFall] Running jump ({speed:F2} m/s, run from {speeds.RunThreshold:F2}) - " + - $"leap at {speeds.RunJump:F2} m/s", LogCat.VR); + Logger.Log($"[VrHeroJumpFall] Running jump ({_horizontalVelocity.magnitude:F2} m/s) - leap at " + + $"{runJump:F2} m/s", LogCat.VR); return; } @@ -116,7 +117,6 @@ private void EndLeap(string reason) if (!_isLeaping) return; _isLeaping = false; - _vrPlayerService.IsRunningJump = false; _rig.SetLeapVelocity(Vector3.zero); var distance = Vector3.ProjectOnPlane(_rig.Root.position - _leapStart, Vector3.up).magnitude; Logger.Log($"[VrHeroJumpFall] Leap ended ({reason}) after {distance:F2} m in " + diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs index a78e1c9ba..2ef61464f 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs @@ -44,7 +44,7 @@ public class VrHeroLocomotion private const string _standToJumpUp = "T_STAND_2_JUMPUP"; private const string _jumpUpAnimation = "S_JUMPUP"; private const string _standToJump = "T_STAND_2_JUMP"; - // Running (VRPlayerService.IsRunningJump, the leap): Gothic's running jump. + // Running (HeroFallService.IsRunningJump, the leap): Gothic's running jump. private const string _runToJump = "T_RUNL_2_JUMP"; private const string _jumpAnimation = "S_JUMP"; private const string _jumpToStand = "T_JUMP_2_STAND"; @@ -260,7 +260,7 @@ private bool TryPlayAirAnimation(float speed, bool isMoving) /// private void StartTakeOff() { - if (_vrPlayerService.IsRunningJump && _animator.HasAnimation(_runToJump)) + if (_heroFallService.IsRunningJump && _animator.HasAnimation(_runToJump)) { StartAirOneShot(_runToJump); _jumpLoop = _jumpAnimation; diff --git a/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs b/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs index 2c3dbc1ed..16fbebecc 100644 --- a/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs +++ b/Assets/Gothic-VR/Scripts/Services/VRPlayerService.cs @@ -382,12 +382,6 @@ private void OnPlayerPrefUpdated(string key, object value) /// public bool IsHeroBodyDown { get; set; } - /// - /// The jump running now is a running jump (a leap, VrHeroJumpFall) - the VR hero body plays T_RUNL_2_JUMP for - /// it, the jump-up otherwise (VrHeroLocomotion). Set at the take-off, false again when the leap ends. - /// - public bool IsRunningJump { get; set; } - /// /// The VR hero body's walk, run and sneak speeds from its animations at its scale (VrHeroLocomotion), null /// without an animated body. VRHeroMovement makes the rig's speeds of them. diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md index 45ac1c85f..ca505c4fd 100644 --- a/Docs/adr/2026-11-29-hero-jump-fall.md +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -16,7 +16,7 @@ In the original game the falling animation starts early and the hero then falls 3. **No fall damage in water, on teleports, while climbing, while transformed into a monster, while lying, and in god mode.** Water means any water level (wading, swimming, diving); a teleport is any move by the game or the player (teleport, Marvin, scripts, loading, ledge and ladder exits) and also a step no fall can make in one frame; grabbing a ladder or ledge mid-air ends the fall, and letting go starts a new one from there. A transformed hero falls as the monster's puppet: no damage, his monster's own rules are not applied. Not chosen: monster fall rules for the transformed hero, left for later. 4. **Falling plays Gothic's animations on the VR hero body:** the take-off at its own speed, cut short when he lands first (the running jump's from running, Gothic's jump-up from standing or walking - not its standing forward leap, the VR jump goes straight up), the pose in the air, the short landing; the falling pose, then falling flat, the small landing. Stairs, slopes, small steps and slow lifts are no fall. 5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. A jump is different: he falls flat only when he lands deeper than the safe height (5 m) below where he jumped off, like OpenGothic - not counting the jump's own rise (1 m), so jumping down a steep slope lands on his feet. The damage height still counts from the top. The landing checks the depth again, so a drop past it in a single frame (a hitch) lands lying too. Not chosen: the 2 m for jumps too, or measured from the top of the jump, which laid him on his face after ordinary running jumps downhill (play tests). -6. **A jump at running speed (the sprint) is Gothic's running jump: a long leap forward at the speed of its animation (about 5 m/s for the hero, scaled with the body), in the direction he ran, until he lands.** The stick doesn't add to it in the air, walls stop it, grabbing a ledge or ladder, a teleport or water end it. The standing and walking jump stays straight up; both rise 1 m. The arms don't flail like in Gothic: they are the player's hands. Not chosen: the plain VR jump at running speed, which was a short hop compared to Gothic's leap. +6. **A jump at running speed (the sprint) is Gothic's running jump: a long leap forward at the speed of its animation (about 5 m/s for the hero, scaled with the body), in the direction he ran, until he lands.** The stick doesn't add to it in the air, walls stop it, grabbing a ledge or ladder, a teleport or water end it. The standing and walking jump stays straight up; both rise 1 m. The arms don't flail like in Gothic: they are the player's hands. The rules decide it from the speed at the take-off against the speed the hero runs from, which the platform gives; the platform only performs the leap. Not chosen: the plain VR jump at running speed, which was a short hop compared to Gothic's leap. Not chosen either: deciding it from BS_RUN, which stays for a moment after he stops running (so NPCs give up a chase like in Gothic) - a jump just after stopping would have leapt. 7. **He falls on his back when he went over the edge moving backwards (against where he faces), otherwise on his face.** Each side has its own landing, lying and getting up; if the hero's model lacks the back set, he falls on his face. 8. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** Turning and the hands stay free. A blocked walk blocks jumping too - here, in dialogs and when knocked out. A teleport or his death ends the lock. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. 9. **A new Immersion option decides the view while he lies after a fall flat: the camera stays at the player's head (default), or it goes down with the body and comes back up while he stands up.** The default spares the player a sudden drop of the view after a long fall. Not chosen: reusing the knockout view option, which is about the game taking the hero down, not about a landing the player caused. From 2a351094efc4f1cc1b76e2930764aef910a49cf8 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 15:49:59 +0000 Subject: [PATCH 33/41] refactor: VrHeroLocomotion hears the landing from HeroLanded (listening while bound) - HeroFallService.LandingCount and LastLanding go, one channel for one fact Co-Authored-By: Claude Opus 5.5 --- .../Services/Movement/HeroFallService.cs | 11 +----- .../Scripts/Adapters/Player/VRHeroBody.cs | 2 +- .../Adapters/Player/VrHeroLocomotion.cs | 37 +++++++++++++++---- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 1d7c59775..09c5c2702 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -79,7 +79,7 @@ public class HeroFallService /// /// The fall flat is on his back (FallPose.Back) - the landing falls back to the front set when the model - /// lacks the back animations (LastLanding). + /// lacks the back animations (HeroLanded). /// public bool IsFallingBackwards => _airborne.IsBackwards; @@ -89,13 +89,6 @@ public class HeroFallService /// public bool IsRunningJump => _airborne.IsRunningJump; - /// - /// Counts the landings - a new value: LastLanding just happened (the VR hero body picks the landing animation). - /// - public int LandingCount { get; private set; } - - public HeroLanding LastLanding { get; private set; } - public HeroFallService() { GlobalEventDispatcher.LoadGameStart.AddListener(ResetAll); @@ -237,8 +230,6 @@ private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, floa Logger.Log("[HeroFall] No back fall animations - lands on his face", LogCat.Npc); landing = new HeroLanding(landing.Height, landing.IsJump, landing.IsLying, false); } - LandingCount++; - LastLanding = landing; // Only a lying landing hurts (author's choice): landing on his feet costs nothing, also from high up - // without the fall on his face the damage looked like a twisted ankle. diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroBody.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroBody.cs index dab6931ab..a85d1f75a 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroBody.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroBody.cs @@ -145,7 +145,7 @@ private void OnDestroy() _hands.RestoreHeldItemAttachPoints(); _meshCutter.DestroyCreatedMeshes(); _hands.Dispose(); - _locomotion.ForgetSpeeds(); + _locomotion.Unbind(); if (_rig != null) _rig.CrouchHeightOverride = null; } diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs index 2ef61464f..c91ff4614 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Gothic.Core; using Gothic.Core.Logging; using Gothic.Core.Models.Container; using Gothic.Core.Models.Movement; @@ -38,7 +39,7 @@ public class VrHeroLocomotion private const string _walkBackAnimation = "S_WALKBL"; private const string _fallAnimation = "S_FALLDN"; - // Jumps and falls: take-off -> in the air -> landing, S_FALLDN -> S_FALL / S_FALLB (deeper than 2 m) -> landing. + // Jumps and falls: take-off -> in the air -> landing, S_FALLDN -> S_FALL / S_FALLB (deeper than 2 m) -> landing // Standing and walking the VR jump goes straight up: Gothic's jump-up (G1: T_STAND_2_JUMPUP 0.40 s). Its // T_STAND_2_JUMP is the standing forward jump (2.65 m, flailing arms) - only the fallback for a model without. private const string _standToJumpUp = "T_STAND_2_JUMPUP"; @@ -52,7 +53,9 @@ public class VrHeroLocomotion private const string _jumpToRun = "T_JUMP_2_RUNL"; private const string _fallToStand = "T_FALLDN_2_STAND"; private HeroAirPhase _airPhase; - private int _landingCount; + // A landing since the last frame (HeroLanded), its animation not picked yet. + private HeroLanding? _newLanding; + private bool _isListening; // The take-off or landing one-shot running now (null = none), at its own speed - a take-off is cut by the // landing, so a jump off a slope lands before it ends. private string _airOneShot; @@ -87,6 +90,25 @@ public void Bind(VRHeroBodyAnimator animator) _missingAnimationFallbacks.Clear(); _isMissingSpeedLogged = false; ForgetSpeeds(); + if (_isListening) + return; + GlobalEventDispatcher.HeroLanded.AddListener(OnHeroLanded); + _isListening = true; + } + + /// + /// The body is gone for good (VRHeroBody destroyed): no landings anymore, the rig moves at its own speeds. + /// + public void Unbind() + { + GlobalEventDispatcher.HeroLanded.RemoveListener(OnHeroLanded); + _isListening = false; + ForgetSpeeds(); + } + + private void OnHeroLanded(HeroLanding landing) + { + _newLanding = landing; } /// @@ -230,8 +252,8 @@ private bool TryPlayAirAnimation(float speed, bool isMoving) { var previousPhase = _airPhase; _airPhase = _heroFallService.Phase; - var isNewLanding = _heroFallService.LandingCount != _landingCount; - _landingCount = _heroFallService.LandingCount; + var newLanding = _newLanding; + _newLanding = null; if (_swimPose.IsInWater) { _airOneShot = null; @@ -249,8 +271,8 @@ private bool TryPlayAirAnimation(float speed, bool isMoving) return _animator.Play(GetFallAnimation()); } - if (isNewLanding) - StartLanding(speed, isMoving); + if (newLanding.HasValue) + StartLanding(newLanding.Value, speed, isMoving); return PlayAirOneShot(isMoving && _airOneShot != _jumpToRun); } @@ -290,10 +312,9 @@ private string GetFallAnimation() /// Standing landings only - a lying one lies down and gets up (VrHeroDownPose). Moving on: straight into the /// walk. /// - private void StartLanding(float speed, bool isMoving) + private void StartLanding(HeroLanding landing, float speed, bool isMoving) { _airOneShot = null; - var landing = _heroFallService.LastLanding; if (landing.IsLying) return; From 1288a4673d5ccf0a5e5b7d8b562406f295578468 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 15:54:35 +0000 Subject: [PATCH 34/41] refactor: the lying landing's timeline has one owner - HeroFallService times it (HeroLanding.StandUpStart / StandUpEnd) and decides the back set once (LyingFallPose), VrHeroDownPose follows those times with one DownReason and an animation set per reason (VrHeroDownAnimations) instead of its own chain and four landing flags Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Models/Movement/FallPose.cs | 2 +- .../Scripts/Models/Movement/HeroLanding.cs | 16 +- .../Services/Movement/HeroFallService.cs | 92 ++++--- .../Scripts/Adapters/Player/VrHeroDownPose.cs | 254 +++++++++--------- .../Adapters/Player/VrHeroLocomotion.cs | 10 +- .../Scripts/Models/VrHeroDownAnimations.cs | 49 ++++ .../Scripts/Models/VrHeroLandingView.cs | 4 +- Docs/adr/2026-11-29-hero-jump-fall.md | 2 +- 8 files changed, 258 insertions(+), 171 deletions(-) create mode 100644 Assets/Gothic-VR/Scripts/Models/VrHeroDownAnimations.cs diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs b/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs index 3dc8930f6..a8c373c86 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs @@ -24,7 +24,7 @@ public readonly struct FallPose public readonly string Landing; /// - /// Lying (a loop) for HeroFallService.FallenHoldSeconds. + /// Lying (a loop) until getting up (the hero: HeroLanding.StandUpStart). /// public readonly string Lying; diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs b/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs index 9ac5790d8..bef163f85 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/HeroLanding.cs @@ -30,12 +30,26 @@ public readonly struct HeroLanding /// public readonly bool IsBackwards; - public HeroLanding(float height, bool isJump, bool isLying, bool isBackwards) + /// + /// Lying landing: s after the landing when he starts getting up (Pose.StandUp) - Pose.Landing, then lying + /// (Pose.Lying) until then. HeroFallService times it from the hero's animations, the VR hero body follows it. + /// + public readonly float StandUpStart; + + /// + /// Lying landing: s after the landing when he stands again - walking is locked until then. + /// + public readonly float StandUpEnd; + + public HeroLanding(float height, bool isJump, bool isLying, bool isBackwards, float standUpStart = 0f, + float standUpEnd = 0f) { Height = height; IsJump = isJump; IsLying = isLying; IsBackwards = isBackwards; + StandUpStart = standUpStart; + StandUpEnd = standUpEnd; } public FallPose Pose => FallPose.Get(IsBackwards); diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 09c5c2702..96ded70aa 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -17,13 +17,14 @@ namespace Gothic.Core.Services.Movement { /// /// The hero's jumps and falls like the engine's: BS_JUMP / BS_FALL while in the air, fall damage at the landing - /// (always, also without the combat system), lying and getting up after a fall flat. The platform measures (VR: the - /// rig port, VrHeroJumpFall) and calls Tick every frame; the phases come from HeroAirborneDomain. + /// (always, also without the combat system), lying and getting up after a fall flat. The platform measures (VR: + /// the rig port, VrHeroJumpFall) and calls Tick every frame; the phases come from HeroAirborneDomain. /// Pose and damage are separate rules: /// - Pose: S_FALLDN as soon as he falls; a fall deeper than NpcFallDomain.LyingFallHeight (2 m, like NPCs), a jump /// deeper than FALLDOWN_HEIGHT below its take-off (like OpenGothic), falls flat (FallPose: on his face, on - /// his back when he went over the edge backwards) and lands lying - he lies a moment and gets up, walking locked - /// meanwhile. + /// his back when he went over the edge backwards and his model has the back set) and lands lying - he lies a + /// moment and gets up, walking locked meanwhile. This service times it from his animations (HeroLanding + /// StandUpStart / StandUpEnd), the platform's body follows those times. /// - Damage - one place, once per landing, never per frame: only a lying landing hurts (landing on his feet costs /// nothing, also from high up). It comes from the drop from the highest point of the jump/fall to the landing /// point, NpcFallDomain.GetFallDamage = (drop - FALLDOWN_HEIGHT) * FALLDOWN_DAMAGE - PROT_FALL, at least 0. A @@ -44,12 +45,10 @@ public class HeroFallService [Inject] private readonly ContextInteractionService _contextInteractionService; [Inject] private readonly AnimationService _animationService; - /// - /// The hero lies this long (FallPose.Lying) after a fall flat before he gets up (FallPose.StandUp). - /// - public const float FallenHoldSeconds = 0.3f; + // The hero lies this long (FallPose.Lying) after a fall flat's landing before he gets up (FallPose.StandUp). + private const float _fallenHoldSeconds = 0.3f; - // Lock after a lying landing without the hero's animations: T_FALL_2_FALLEN + S_FALLEN + T_FALLEN_2_STAND (G1). + // A lying landing without the hero's animations: T_FALL_2_FALLEN + S_FALLEN + T_FALLEN_2_STAND (G1). private const float _defaultLyingLandingSeconds = 1.7f; // Just after a world load or a loaded game, objects under the spawn point may still be loading (bridges, @@ -78,10 +77,10 @@ public class HeroFallService public bool IsLyingFall => _airborne.IsLyingFall; /// - /// The fall flat is on his back (FallPose.Back) - the landing falls back to the front set when the model - /// lacks the back animations (HeroLanded). + /// The fall flat's animations (IsLyingFall): on his back (FallPose.Back) when he went over the edge backwards + /// and his model has the back set, else on his face. The landing's pose is HeroLanding.Pose. /// - public bool IsFallingBackwards => _airborne.IsBackwards; + public FallPose LyingFallPose { get; private set; } = FallPose.Front; /// /// The jump running now was taken at running speed: Gothic's running jump - the platform leaps forward (VR: @@ -130,10 +129,12 @@ public void Tick(in HeroFallSample sample) "no damage within it)", LogCat.Npc); break; case HeroAirEvent.LyingFallStarted: + var isBackwards = IsBackFall(hero, _airborne.IsBackwards); + LyingFallPose = FallPose.Get(isBackwards); Logger.Log($"[HeroFall] More than {_airborne.LyingDepth:F1} m below " + $"{_airborne.LyingReferenceY:F2} (jump take-off or fall start) - falls flat " + - $"({(_airborne.IsBackwards ? "on his back" : "on his face")}), lands lying; damage " + - $"only above FALLDOWN_HEIGHT {safeHeight:F1} m, at the landing", LogCat.Npc); + $"({(isBackwards ? "on his back" : "on his face")}), lands lying; damage only above " + + $"FALLDOWN_HEIGHT {safeHeight:F1} m, at the landing", LogCat.Npc); break; case HeroAirEvent.Landed: EndAirBodyState(hero); @@ -219,17 +220,13 @@ private static string Describe(HeroFallHold hold, VmGothicEnums.BodyState bodySt } /// - /// The landing, once: damage from the measured drop (lying landings only), the lying landing's lock, the event - /// for the VR body. + /// The landing, once: damage from the measured drop (lying landings only), the lying landing's times and lock, + /// the event for the platform's body. /// private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, float feetY) { - // On his back only with the model's back set - else on his face. - if (landing.IsBackwards && !HasPose(hero, FallPose.Back)) - { - Logger.Log("[HeroFall] No back fall animations - lands on his face", LogCat.Npc); - landing = new HeroLanding(landing.Height, landing.IsJump, landing.IsLying, false); - } + if (landing.IsLying) + landing = TimeLyingLanding(hero, landing); // Only a lying landing hurts (author's choice): landing on his feet costs nothing, also from high up - // without the fall on his face the damage looked like a twisted ankle. @@ -245,36 +242,61 @@ private void Land(NpcContainer hero, HeroLanding landing, float safeHeight, floa // Before the damage: a deadly fall's HeroDied comes after it, the VR body knows it lands lying. GlobalEventDispatcher.HeroLanded.Invoke(landing); if (landing.IsLying) - LockForLyingLanding(hero, landing.Pose); + LockForLyingLanding(landing); if (damage > 0) GlobalEventDispatcher.FallDamage.Invoke(hero, damage); } /// - /// He lies and gets up: no walking or teleporting until then (turning and the hands stay free). As long as the - /// pose's landing, lying and standing up take. + /// The lying landing's pose and timeline, the one for the lock and the platform's body: the pose's landing, + /// lying for _fallenHoldSeconds, standing up - as long as the hero's animations take. /// - private void LockForLyingLanding(NpcContainer hero, FallPose pose) + private HeroLanding TimeLyingLanding(NpcContainer hero, HeroLanding landing) { - var seconds = GetAnimationSeconds(hero, pose.Landing) + FallenHoldSeconds + - GetAnimationSeconds(hero, pose.StandUp); - if (seconds <= FallenHoldSeconds) - seconds = _defaultLyingLandingSeconds; + var isBackwards = IsBackFall(hero, landing.IsBackwards); + var pose = FallPose.Get(isBackwards); + var standUpStart = GetAnimationSeconds(hero, pose.Landing) + _fallenHoldSeconds; + var standUpEnd = standUpStart + GetAnimationSeconds(hero, pose.StandUp); + if (standUpEnd <= _fallenHoldSeconds) + { + standUpStart = _defaultLyingLandingSeconds; + standUpEnd = _defaultLyingLandingSeconds; + } + return new HeroLanding(landing.Height, landing.IsJump, true, isBackwards, standUpStart, standUpEnd); + } + /// + /// He lies and gets up: no walking or teleporting until then (turning and the hands stay free). + /// + private void LockForLyingLanding(HeroLanding landing) + { _contextInteractionService.LockPlayer(PlayerLocks.FallLanding, PlayerControls.Walking); _isLandingLocked = true; - _landingUnlockTime = Time.time + seconds; - Logger.Log($"[HeroFall] Lying landing ({pose.Landing}) - movement locked for {seconds:F2} s", LogCat.Npc); + _landingUnlockTime = Time.time + landing.StandUpEnd; + Logger.Log($"[HeroFall] Lying landing ({landing.Pose.Landing}) - gets up after " + + $"{landing.StandUpStart:F2} s, movement locked for {landing.StandUpEnd:F2} s", LogCat.Npc); + } + + /// + /// On his back only when he went over the edge backwards and his model has the back set - else on his face. + /// + private bool IsBackFall(NpcContainer hero, bool isBackwards) + { + if (!isBackwards || HasPose(hero, FallPose.Back)) + return isBackwards; + Logger.Log("[HeroFall] No back fall animations - falls on his face", LogCat.Npc); + return false; } /// - /// The hero's model can land in this pose and get up from it (lying itself may be missing - then he holds the - /// landing's last frame). + /// The hero's model can fall flat in this pose, land in it and get up from it (lying itself may be missing - + /// then he holds the landing's last frame). /// private bool HasPose(NpcContainer hero, FallPose pose) { - return GetAnimationSeconds(hero, pose.Landing) > 0f && GetAnimationSeconds(hero, pose.StandUp) > 0f; + return GetAnimationSeconds(hero, pose.Flight) > 0f && GetAnimationSeconds(hero, pose.Landing) > 0f && + GetAnimationSeconds(hero, pose.StandUp) > 0f; } private float GetAnimationSeconds(NpcContainer hero, string animationName) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs index 25b32548b..e8167366f 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs @@ -5,7 +5,6 @@ using Gothic.Core.Models.Container; using Gothic.Core.Models.Movement; using Gothic.Core.Models.Vm; -using Gothic.Core.Services.Movement; using Gothic.Core.Services.Npc; using Gothic.VR.Interaction.Components; using Gothic.VR.Interaction.Ports; @@ -29,10 +28,10 @@ namespace Gothic.VR.Adapters.Player /// death menu. Tells VRPlayerService whether a body that can fall exists (SetHeroFallBody); "blink" leaves the /// view to VrKnockoutView. /// A fall flat (HeroLanded, IsLying: deeper than 2 m - not tied to the damage) lands him lying in the landing's - /// FallPose - on his face T_FALL_2_FALLEN, S_FALLEN for HeroFallService.FallenHoldSeconds, T_FALLEN_2_STAND, on - /// his back the same with FALLB/FALLENB - whatever heroFallMode is; the Immersion option heroLandingView decides - /// whether the camera goes with the head (VRPlayerService.HeroLandingView, default: it stays at the player's head). - /// HeroFallService locks walking meanwhile. Killed by the fall, he stays lying dead (S_DEAD, on his back S_DEADB). + /// FallPose (T_FALL_2_FALLEN, S_FALLEN, T_FALLEN_2_STAND, on his back FALLB/FALLENB) at HeroFallService's times + /// (HeroLanding.StandUpStart / StandUpEnd, the same as its walking lock) - whatever heroFallMode is; the Immersion + /// option heroLandingView decides whether the camera goes with the head (VRPlayerService.HeroLandingView, default: + /// it stays at the player's head). Killed by the fall, he stays lying dead (S_DEAD, on his back S_DEADB). /// Worker of VRHeroBody (new().Inject(), Initialize, Bind, Dispose). /// public class VrHeroDownPose @@ -40,51 +39,36 @@ public class VrHeroDownPose [Inject] private readonly VRPlayerService _vrPlayerService; [Inject] private readonly NpcService _npcService; - private enum DownPhase + /// + /// Why the body lies. Asked for together, the stronger one wins: dead, knocked out, asleep, a lying landing. + /// + private enum DownReason { None, - Knockout, - Asleep, - Dead, - // After a fall flat, until he starts getting up (Rising). Landing, - Rising + Asleep, + Knockout, + Dead } - private const string _standToWounded = "T_STAND_2_WOUNDEDB"; - private const string _wounded = "S_WOUNDEDB"; - private const string _standToDead = "T_DEADB"; - private const string _dead = "S_DEADB"; - private const string _woundedToDead = "T_WOUNDEDB_2_DEADB"; - private const string _woundedToStand = "T_WOUNDEDB_2_STAND"; - // ZS_MagicSleep's animations. - private const string _standToSleep = "T_STAND_2_VICTIM_SLE"; - private const string _sleep = "S_VICTIM_SLE"; - private const string _sleepToStand = "T_VICTIM_SLE_2_STAND"; - // A landing not started within this time (no body update meanwhile) is forgotten. - private const float _landingStartTimeout = 0.5f; - private const float _downFloorMargin = 0.03f; private const float _minDownEyeHeight = 0.2f; // The neck sits this far below the eyes (scaled with the body). private readonly float _neckBelowEyes; private readonly Action _solveArms; - private DownPhase _downPhase; + // Why the body lies now (None: it stands) and whether it gets up from it. + private DownReason _downReason; + private bool _isRising; // The hero's state from the events (HeroKnockedOut, HeroRecovered, HeroDied, HeroFellAsleep, HeroWokeUp, // LoadGameStart). private bool _isKnockedOut; private bool _isDead; private bool _isAsleep; - // A lying landing (HeroLanded) to lie down for, when it was raised, and its pose (face or back). - private bool _isLanding; - private FallPose _landingPose = FallPose.Front; + // A lying landing (HeroLanded) to lie down for or lying now, and when it was raised - its times count from + // then. + private HeroLanding? _landing; private float _landedTime; - // This down started as a landing: its camera follows the head only with heroLandingView "move with body". - private bool _isLandingDown; - private bool _isLandingViewOnBody; - // When S_FALLEN started (-1 = T_FALL_2_FALLEN still plays). - private float _fallenStartTime = -1f; // The hands' physics before the hero went down. private readonly Dictionary _physicalBeforeDown = new(); private readonly Queue _downAnimations = new(); @@ -210,8 +194,7 @@ private void OnHeroLanded(HeroLanding landing) { if (!landing.IsLying) return; - _landingPose = landing.Pose; - _isLanding = true; + _landing = landing; _landedTime = Time.time; } @@ -221,7 +204,6 @@ private void OnLoadGameStart() _isKnockedOut = false; _isDead = false; _isAsleep = false; - _isLanding = false; EndDown(); } @@ -242,15 +224,17 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig { _rig = rig; var isDown = _isDead || _isKnockedOut || _isAsleep; - if (!isDown && _downPhase == DownPhase.Dead) + if (!isDown && _downReason == DownReason.Dead) { EndDown(); return false; } - if (_isLanding && _downPhase == DownPhase.None && Time.time - _landedTime > _landingStartTimeout) - _isLanding = false; + // A landing whose lying is over before the body could lie down (no body update meanwhile) is forgotten. + if (_landing.HasValue && _downReason == DownReason.None && + Time.time - _landedTime >= _landing.Value.StandUpStart) + _landing = null; // A lying landing lies down in either heroFallMode - "blink" is for knocked out, dead, asleep. - var isLandingOnly = !isDown && (_isLanding || _downPhase == DownPhase.Landing || _isLandingDown); + var isLandingOnly = !isDown && (_landing.HasValue || _downReason == DownReason.Landing); if ((_vrPlayerService.HeroFallMode != VrHeroFallMode.MoveWithBody && !isLandingOnly) || _body == null || _animator == null || !_animator.IsValid || _headBone == null || standingScale <= 0f) { @@ -258,52 +242,36 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig return false; } - if (_downPhase == DownPhase.None) + if (_downReason == DownReason.None) { - if (!isDown && !_isLanding) + if (!isDown && !_landing.HasValue) return false; StartDown(head, standingScale, feetY); } - if (_isDead && _downPhase != DownPhase.Dead) + if (_isDead && _downReason != DownReason.Dead) { - if (_downPhase == DownPhase.Knockout) - SetDownAnimations(_woundedToDead, _dead); - else if (_downPhase == DownPhase.Landing) - SetDownAnimations(_landingPose.Dead); - else - SetDownAnimations(_standToDead, _dead); - _downPhase = DownPhase.Dead; - _isLandingDown = false; + // Lying dies in its own pose, getting up falls dead from standing. + var dying = _isRising ? VrHeroDownAnimations.Dead : GetAnimations(_downReason); + SetDownAnimations(dying.ToDead, dying.LyingDead); + SetDownReason(DownReason.Dead); } // Knocked out while asleep (the hit woke him), while getting up or lying after a fall. - else if (!_isDead && _isKnockedOut && _downPhase is DownPhase.Rising or DownPhase.Asleep - or DownPhase.Landing) - { - SetDownAnimations(_standToWounded, _wounded); - _downPhase = DownPhase.Knockout; - _isLandingDown = false; - _isLanding = false; - } - else if (!isDown && _downPhase == DownPhase.Landing) + else if (!_isDead && _isKnockedOut && (_isRising || _downReason is DownReason.Asleep or DownReason.Landing)) + LieDown(DownReason.Knockout); + else if (!isDown && _downReason == DownReason.Landing && !_isRising) UpdateLanding(); - else if (!_isDead && !_isKnockedOut && _isAsleep && _downPhase == DownPhase.Rising) - { - SetDownAnimations(_standToSleep, _sleep); - _downPhase = DownPhase.Asleep; - } - else if (!isDown && _downPhase is DownPhase.Knockout or DownPhase.Asleep) - { - SetDownAnimations(_downPhase == DownPhase.Asleep ? _sleepToStand : _woundedToStand); - _downPhase = DownPhase.Rising; - } + else if (!_isDead && !_isKnockedOut && _isAsleep && _isRising) + LieDown(DownReason.Asleep); + else if (!isDown && !_isRising && _downReason is DownReason.Knockout or DownReason.Asleep) + GetUp(); if (_downAnimation != null && _animator.IsDone(_downAnimation) && _downAnimations.Count > 0) { _downAnimation = _downAnimations.Dequeue(); _animator.Play(_downAnimation); } - if (_downPhase == DownPhase.Rising && (_downAnimation == null || _animator.IsDone(_downAnimation))) + if (_isRising && IsUp()) { EndDown(); return false; @@ -336,40 +304,49 @@ public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig var eyeHeight = _headBone.position.y + _neckBelowEyes * scale - feetY; if (_downStartEyeHeight < 0f) _downStartEyeHeight = eyeHeight; - if (IsRigAlive() && (!_isLandingDown || _isLandingViewOnBody)) + if (IsRigAlive() && IsCameraOnBody()) _rig.CameraYOffset = _downBaseCameraOffset + Mathf.Max(eyeHeight, _minDownEyeHeight) - _downStartEyeHeight; // Dead, the arms stay in the death pose - reaching for the controllers, the player moved his own corpse. - if (_downPhase != DownPhase.Dead) + if (_downReason != DownReason.Dead) _solveArms(); // ...and the corpse goes while the menu is open: lying in front of the low camera, it was in the way. - SetBodyShown(_downPhase != DownPhase.Dead || !_isMenuOpen); + SetBodyShown(_downReason != DownReason.Dead || !_isMenuOpen); return true; } /// - /// Lying after a fall flat: the pose's landing to its end, lying for HeroFallService.FallenHoldSeconds, then - /// standing up (Rising, which ends the down when done). Lying loops - timed, not IsDone. + /// Lying after a fall flat until HeroFallService's stand-up time (HeroLanding.StandUpStart) - the landing and + /// lying play in the queue meanwhile - then standing up. /// private void UpdateLanding() { - if (_fallenStartTime >= 0f) - { - if (Time.time - _fallenStartTime < HeroFallService.FallenHoldSeconds) - return; - SetDownAnimations(_landingPose.StandUp); - _downPhase = DownPhase.Rising; - _isLanding = false; - Logger.Log($"[VRHeroBody] Lying landing - getting up ({_landingPose.StandUp})", LogCat.VR); + if (Time.time - _landedTime < _landing.Value.StandUpStart) return; - } + GetUp(); + Logger.Log($"[VRHeroBody] Lying landing - getting up ({_landing.Value.Pose.StandUp})", LogCat.VR); + } - if (_downAnimation == null || _animator.IsDone(_downAnimation)) - { - _fallenStartTime = Time.time; - SetDownAnimations(_landingPose.Lying); - } + /// + /// Getting up is over: a landing at HeroFallService's time (HeroLanding.StandUpEnd, its walking lock ends + /// then), the others when their animation is done. + /// + private bool IsUp() + { + if (_downReason == DownReason.Landing && _landing.HasValue) + return Time.time - _landedTime >= _landing.Value.StandUpEnd; + return _downAnimation == null || _animator.IsDone(_downAnimation); + } + + /// + /// A lying landing's camera stays at the player's head unless heroLandingView "move with the body" - the + /// others always follow the animated head. + /// + private bool IsCameraOnBody() + { + return _downReason != DownReason.Landing || + _vrPlayerService.HeroLandingView == VrHeroLandingView.MoveWithBody; } /// @@ -421,7 +398,7 @@ private Transform[] GetFloorBones() /// /// Knocked out he falls wounded (T_STAND_2_WOUNDEDB), dead straight from standing (T_DEADB), asleep like - /// ZS_MagicSleep (T_STAND_2_VICTIM_SLE). The camera's + /// ZS_MagicSleep (T_STAND_2_VICTIM_SLE), after a fall flat in its pose. The camera's /// start height is the standing pose of the frame before: the first frame of a fall can already be low /// (T_DEADB), then the camera never went down. /// @@ -437,45 +414,73 @@ private void StartDown(Transform head, float standingScale, float feetY) _bodyBones = null; SetHandsThroughFloor(true); _vrPlayerService.IsHeroBodyDown = true; - _fallenStartTime = -1f; - _isLandingDown = false; - if (_isDead) + + var reason = _isDead ? DownReason.Dead + : _isKnockedOut ? DownReason.Knockout + : _isAsleep ? DownReason.Asleep + : DownReason.Landing; + if (reason == DownReason.Dead && _landing.HasValue) { - _downPhase = DownPhase.Dead; // Killed by the fall: he lands on his face or back and stays there. - if (_isLanding) - SetDownAnimations(_landingPose.Landing, _landingPose.Dead); - else - SetDownAnimations(_standToDead, _dead); - } - else if (_isKnockedOut) - { - _downPhase = DownPhase.Knockout; - SetDownAnimations(_standToWounded, _wounded); - } - else if (_isAsleep) - { - _downPhase = DownPhase.Asleep; - SetDownAnimations(_standToSleep, _sleep); + var fall = GetAnimations(DownReason.Landing); + SetDownAnimations(fall.Down, fall.LyingDead); + SetDownReason(DownReason.Dead); } else + LieDown(reason); + + if (reason == DownReason.Landing) + Logger.Log($"[VRHeroBody] Lying landing ({_landing.Value.Pose.Landing}) - body lies down, camera " + + (IsCameraOnBody() ? "follows its head" : "stays at the player's head"), LogCat.VR); + else + Logger.Log("[VRHeroBody] Hero down - body falls, camera follows its head", LogCat.VR); + } + + /// + /// Goes down for this reason and lies (its down and lying animations). Only a landing keeps the landing. + /// + private void LieDown(DownReason reason) + { + var animations = GetAnimations(reason); + SetDownReason(reason); + SetDownAnimations(animations.Down, animations.Lying); + } + + /// + /// Gets up from the reason he lies for (its up animation). + /// + private void GetUp() + { + SetDownAnimations(GetAnimations(_downReason).Up); + _isRising = true; + } + + private void SetDownReason(DownReason reason) + { + _downReason = reason; + _isRising = false; + if (reason != DownReason.Landing) + _landing = null; + } + + private VrHeroDownAnimations GetAnimations(DownReason reason) + { + return reason switch { - _downPhase = DownPhase.Landing; - _isLandingDown = true; - _isLandingViewOnBody = _vrPlayerService.HeroLandingView == VrHeroLandingView.MoveWithBody; - SetDownAnimations(_landingPose.Landing); - Logger.Log($"[VRHeroBody] Lying landing ({_landingPose.Landing}) - body lies down, camera " + - (_isLandingViewOnBody ? "follows its head" : "stays at the player's head"), LogCat.VR); - return; - } - _isLanding = false; - Logger.Log("[VRHeroBody] Hero down - body falls, camera follows its head", LogCat.VR); + DownReason.Knockout => VrHeroDownAnimations.Knockout, + DownReason.Asleep => VrHeroDownAnimations.Asleep, + DownReason.Landing => VrHeroDownAnimations.Of(_landing?.Pose ?? FallPose.Front), + _ => VrHeroDownAnimations.Dead + }; } + /// + /// Plays these in turn - missing ones (null, or not in the hero's model) are left out. + /// private void SetDownAnimations(string first, string second = null) { _downAnimations.Clear(); - if (_animator.HasAnimation(first)) + if (first != null && _animator.HasAnimation(first)) _downAnimations.Enqueue(first); if (second != null && _animator.HasAnimation(second)) _downAnimations.Enqueue(second); @@ -489,13 +494,12 @@ private void SetDownAnimations(string first, string second = null) /// private void EndDown() { - _isLanding = false; - if (_downPhase == DownPhase.None) + _landing = null; + if (_downReason == DownReason.None) return; - _downPhase = DownPhase.None; - _isLandingDown = false; - _fallenStartTime = -1f; + _downReason = DownReason.None; + _isRising = false; SetBodyShown(true); SetHandsThroughFloor(false); _vrPlayerService.IsHeroBodyDown = false; diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs index c91ff4614..9853a165e 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs @@ -295,17 +295,15 @@ private void StartTakeOff() } /// - /// S_FALLDN, deeper than NpcFallDomain.LyingFallHeight flat: S_FALL on his face, S_FALLB on his back (the face - /// set if the model has no S_FALLB). + /// S_FALLDN, deeper than NpcFallDomain.LyingFallHeight flat: HeroFallService's pose, S_FALL on his face or + /// S_FALLB on his back. /// private string GetFallAnimation() { if (!_heroFallService.IsLyingFall) return _fallAnimation; - var flight = FallPose.Get(_heroFallService.IsFallingBackwards).Flight; - if (_animator.HasAnimation(flight)) - return flight; - return _animator.HasAnimation(FallPose.Front.Flight) ? FallPose.Front.Flight : _fallAnimation; + var flight = _heroFallService.LyingFallPose.Flight; + return _animator.HasAnimation(flight) ? flight : _fallAnimation; } /// diff --git a/Assets/Gothic-VR/Scripts/Models/VrHeroDownAnimations.cs b/Assets/Gothic-VR/Scripts/Models/VrHeroDownAnimations.cs new file mode 100644 index 000000000..c55591032 --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Models/VrHeroDownAnimations.cs @@ -0,0 +1,49 @@ +using Gothic.Core.Models.Movement; + +namespace Gothic.VR.Models +{ + /// + /// The VR hero body's animations for one reason to lie (VrHeroDownPose): going down, lying (a loop), getting up, + /// from lying to dead and lying dead. Knocked out and dead on his back, asleep like ZS_MagicSleep, a lying landing + /// in its FallPose. + /// + public readonly struct VrHeroDownAnimations + { + public static readonly VrHeroDownAnimations Knockout = new("T_STAND_2_WOUNDEDB", "S_WOUNDEDB", + "T_WOUNDEDB_2_STAND", "T_WOUNDEDB_2_DEADB", "S_DEADB"); + + public static readonly VrHeroDownAnimations Asleep = new("T_STAND_2_VICTIM_SLE", "S_VICTIM_SLE", + "T_VICTIM_SLE_2_STAND", "T_DEADB", "S_DEADB"); + + public static readonly VrHeroDownAnimations Dead = new("T_DEADB", "S_DEADB", null, "T_DEADB", "S_DEADB"); + + public readonly string Down; + public readonly string Lying; + + /// + /// Lying to standing, null: he doesn't get up. + /// + public readonly string Up; + + /// + /// Lying to dead, null: straight to LyingDead. + /// + public readonly string ToDead; + + public readonly string LyingDead; + + private VrHeroDownAnimations(string down, string lying, string up, string toDead, string lyingDead) + { + Down = down; + Lying = lying; + Up = up; + ToDead = toDead; + LyingDead = lyingDead; + } + + public static VrHeroDownAnimations Of(FallPose pose) + { + return new VrHeroDownAnimations(pose.Landing, pose.Lying, pose.StandUp, null, pose.Dead); + } + } +} diff --git a/Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs b/Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs index 90b7661b2..395656d12 100644 --- a/Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs +++ b/Assets/Gothic-VR/Scripts/Models/VrHeroLandingView.cs @@ -1,8 +1,8 @@ namespace Gothic.VR.Models { /// - /// Where the view is while the hero lies after a fall deeper than FALLDOWN_HEIGHT and gets up again - /// (VrHeroDownPose, HeroFallService's deep landing). + /// Where the view is while the hero lies after a fall flat and gets up again (VrHeroDownPose, HeroFallService's + /// lying landing). /// HINT: Stored as int in Gothic.ini (VRConstants.IniNames.HeroLandingView). Never change the values. /// public enum VrHeroLandingView diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md index ca505c4fd..3d61371ee 100644 --- a/Docs/adr/2026-11-29-hero-jump-fall.md +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -18,7 +18,7 @@ In the original game the falling animation starts early and the hero then falls 5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. A jump is different: he falls flat only when he lands deeper than the safe height (5 m) below where he jumped off, like OpenGothic - not counting the jump's own rise (1 m), so jumping down a steep slope lands on his feet. The damage height still counts from the top. The landing checks the depth again, so a drop past it in a single frame (a hitch) lands lying too. Not chosen: the 2 m for jumps too, or measured from the top of the jump, which laid him on his face after ordinary running jumps downhill (play tests). 6. **A jump at running speed (the sprint) is Gothic's running jump: a long leap forward at the speed of its animation (about 5 m/s for the hero, scaled with the body), in the direction he ran, until he lands.** The stick doesn't add to it in the air, walls stop it, grabbing a ledge or ladder, a teleport or water end it. The standing and walking jump stays straight up; both rise 1 m. The arms don't flail like in Gothic: they are the player's hands. The rules decide it from the speed at the take-off against the speed the hero runs from, which the platform gives; the platform only performs the leap. Not chosen: the plain VR jump at running speed, which was a short hop compared to Gothic's leap. Not chosen either: deciding it from BS_RUN, which stays for a moment after he stops running (so NPCs give up a chase like in Gothic) - a jump just after stopping would have leapt. 7. **He falls on his back when he went over the edge moving backwards (against where he faces), otherwise on his face.** Each side has its own landing, lying and getting up; if the hero's model lacks the back set, he falls on his face. -8. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** Turning and the hands stay free. A blocked walk blocks jumping too - here, in dialogs and when knocked out. A teleport or his death ends the lock. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. +8. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** The rules time it once - when he starts getting up and when he stands - and the VR hero body follows those times, so the body and the lock end together. Turning and the hands stay free. A blocked walk blocks jumping too - here, in dialogs and when knocked out. A teleport or his death ends the lock. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. 9. **A new Immersion option decides the view while he lies after a fall flat: the camera stays at the player's head (default), or it goes down with the body and comes back up while he stands up.** The default spares the player a sudden drop of the view after a long fall. Not chosen: reusing the knockout view option, which is about the game taking the hero down, not about a landing the player caused. ## Consequences From a60039a57a26672d2ebbc1ece880b736905e8a5c Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 15:55:34 +0000 Subject: [PATCH 35/41] chore: EnableHeroFallDamage out of Production.asset - the flag is gone, the hero's fall damage is always on Co-Authored-By: Claude Opus 5.5 --- Assets/Gothic-Core/Resources/DeveloperConfigs/Production.asset | 1 - 1 file changed, 1 deletion(-) diff --git a/Assets/Gothic-Core/Resources/DeveloperConfigs/Production.asset b/Assets/Gothic-Core/Resources/DeveloperConfigs/Production.asset index f6ab967a1..dfc440af2 100644 --- a/Assets/Gothic-Core/Resources/DeveloperConfigs/Production.asset +++ b/Assets/Gothic-Core/Resources/DeveloperConfigs/Production.asset @@ -55,7 +55,6 @@ MonoBehaviour: ShowCapsuleOverlapGizmos: 0 EnableNpcs: 1 EnableCombatSystem: 1 - EnableHeroFallDamage: 1 EnableNpcMeshCulling: 1 NpcCullingDistance: 50 SpawnNpcInstances: From 57c2bd70fe6baa0f766a0bd78db079ceb623d8f3 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 16:11:44 +0000 Subject: [PATCH 36/41] chore: meta file of VrHeroDownAnimations (generated by Unity on import) Co-Authored-By: Claude Opus 5.5 --- Assets/Gothic-VR/Scripts/Models/VrHeroDownAnimations.cs.meta | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Assets/Gothic-VR/Scripts/Models/VrHeroDownAnimations.cs.meta diff --git a/Assets/Gothic-VR/Scripts/Models/VrHeroDownAnimations.cs.meta b/Assets/Gothic-VR/Scripts/Models/VrHeroDownAnimations.cs.meta new file mode 100644 index 000000000..652ddccef --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Models/VrHeroDownAnimations.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 2c200726c60337f4ba86647fbfed511e \ No newline at end of file From da03be810c15e252041ee877396f30f006a783a1 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 16:14:40 +0000 Subject: [PATCH 37/41] feat: texts of the Immersion option "Deep fall view" (heroLandingView) in all 8 languages - aside or with the body (added through Unity MCP) Co-Authored-By: Claude Opus 5.5 --- .../Localizations/Gothic-UI Shared Data.asset | 12 ++++++++++++ .../Localizations/Gothic-UI_cs.asset | 13 +++++++++++++ .../Localizations/Gothic-UI_de.asset | 13 +++++++++++++ .../Localizations/Gothic-UI_en.asset | 13 +++++++++++++ .../Localizations/Gothic-UI_es.asset | 13 +++++++++++++ .../Localizations/Gothic-UI_fr.asset | 14 ++++++++++++++ .../Localizations/Gothic-UI_it.asset | 13 +++++++++++++ .../Localizations/Gothic-UI_pl.asset | 13 +++++++++++++ .../Localizations/Gothic-UI_ru.asset | 18 ++++++++++++++++++ 9 files changed, 122 insertions(+) diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI Shared Data.asset b/Assets/Gothic-Core/Localizations/Gothic-UI Shared Data.asset index 13af945fc..05deaaae1 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI Shared Data.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI Shared Data.asset @@ -567,6 +567,18 @@ MonoBehaviour: m_Key: vr.help.ring.text m_Metadata: m_Items: [] + - m_Id: 199062989374627840 + m_Key: menuitem.heroLandingView.label + m_Metadata: + m_Items: [] + - m_Id: 199062989416570880 + m_Key: menuitem.heroLandingView.value + m_Metadata: + m_Items: [] + - m_Id: 199062989416570881 + m_Key: menuitem.heroLandingView.description + m_Metadata: + m_Items: [] m_Metadata: m_Items: [] m_KeyGenerator: diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_cs.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_cs.asset index 86544ba3a..8ca0925b0 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_cs.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_cs.asset @@ -469,6 +469,19 @@ MonoBehaviour: m_Localized: "s t\u011Blem|prolnut\xED" m_Metadata: m_Items: [] + - m_Id: 199062989374627840 + m_Localized: "Pohled po p\xE1du" + m_Metadata: + m_Items: [] + - m_Id: 199062989416570880 + m_Localized: "stranou|s t\u011Blem" + m_Metadata: + m_Items: [] + - m_Id: 199062989416570881 + m_Localized: "Po hlubok\xE9m p\xE1du hrdina le\u017E\xED a vst\xE1v\xE1: pohled + z\u016Fstane stranou (nekles\xE1) nebo klesne a vstane s t\u011Blem" + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_de.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_de.asset index 8daf4c595..38b6584e1 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_de.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_de.asset @@ -595,6 +595,19 @@ MonoBehaviour: \"Favoriten-Ring\"." m_Metadata: m_Items: [] + - m_Id: 199062989374627840 + m_Localized: Sicht nach Sturz + m_Metadata: + m_Items: [] + - m_Id: 199062989416570880 + m_Localized: "daneben|mit K\xF6rper" + m_Metadata: + m_Items: [] + - m_Id: 199062989416570881 + m_Localized: "Nach einem tiefen Sturz liegt der Held und steht auf: die Sicht + bleibt daneben (sie sinkt nicht) oder geht mit dem K\xF6rper runter und hoch" + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_en.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_en.asset index 418df7bd8..c8728bcaf 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_en.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_en.asset @@ -607,6 +607,19 @@ MonoBehaviour: it off in Immersion: "Favorites ring".' m_Metadata: m_Items: [] + - m_Id: 199062989374627840 + m_Localized: Deep Fall View + m_Metadata: + m_Items: [] + - m_Id: 199062989416570880 + m_Localized: aside|with body + m_Metadata: + m_Items: [] + - m_Id: 199062989416570881 + m_Localized: 'After a deep fall the hero lies down and gets up: the view stays + aside (it doesn''t go down) or goes down and up with the body' + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_es.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_es.asset index 57e8ee258..9194dac85 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_es.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_es.asset @@ -458,6 +458,19 @@ MonoBehaviour: m_Localized: con el cuerpo|fundido m_Metadata: m_Items: [] + - m_Id: 199062989374627840 + m_Localized: "Vista tras ca\xEDda" + m_Metadata: + m_Items: [] + - m_Id: 199062989416570880 + m_Localized: a un lado|con el cuerpo + m_Metadata: + m_Items: [] + - m_Id: 199062989416570881 + m_Localized: "Tras una ca\xEDda profunda el h\xE9roe queda tendido y se levanta: + la vista se queda a un lado (no baja) o baja y sube con el cuerpo" + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_fr.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_fr.asset index a111644b4..141239cfd 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_fr.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_fr.asset @@ -463,6 +463,20 @@ MonoBehaviour: m_Localized: avec le corps|fondu m_Metadata: m_Items: [] + - m_Id: 199062989374627840 + m_Localized: "Vue apr\xE8s chute" + m_Metadata: + m_Items: [] + - m_Id: 199062989416570880 + m_Localized: "\xE0 c\xF4t\xE9|avec le corps" + m_Metadata: + m_Items: [] + - m_Id: 199062989416570881 + m_Localized: "Apr\xE8s une chute profonde le h\xE9ros reste \xE0 terre et se + rel\xE8ve : la vue reste \xE0 c\xF4t\xE9 (elle ne descend pas) ou descend et + remonte avec le corps" + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_it.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_it.asset index 45f797f75..5456bf584 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_it.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_it.asset @@ -459,6 +459,19 @@ MonoBehaviour: m_Localized: col corpo|dissolvenza m_Metadata: m_Items: [] + - m_Id: 199062989374627840 + m_Localized: Visuale dopo caduta + m_Metadata: + m_Items: [] + - m_Id: 199062989416570880 + m_Localized: a lato|col corpo + m_Metadata: + m_Items: [] + - m_Id: 199062989416570881 + m_Localized: 'Dopo una caduta profonda l''eroe resta a terra e si rialza: la + visuale resta a lato (non scende) o scende e risale col corpo' + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_pl.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_pl.asset index 9bd41a227..bf4c32307 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_pl.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_pl.asset @@ -465,6 +465,19 @@ MonoBehaviour: dr\u0105\u017Cek, gdy jest otwarty)" m_Metadata: m_Items: [] + - m_Id: 199062989374627840 + m_Localized: Widok po upadku + m_Metadata: + m_Items: [] + - m_Id: 199062989416570880 + m_Localized: "z boku|z cia\u0142em" + m_Metadata: + m_Items: [] + - m_Id: 199062989416570881 + m_Localized: "Po g\u0142\u0119bokim upadku bohater le\u017Cy i wstaje: widok + zostaje z boku (nie opada) albo opada i wstaje razem z cia\u0142em" + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_ru.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_ru.asset index c4fd61883..54b13c3a7 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_ru.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_ru.asset @@ -549,6 +549,24 @@ MonoBehaviour: m_Localized: "\u0441 \u0442\u0435\u043B\u043E\u043C|\u0437\u0430\u0442\u0435\u043C\u043D\u0435\u043D\u0438\u0435" m_Metadata: m_Items: [] + - m_Id: 199062989374627840 + m_Localized: "\u0412\u0438\u0434 \u043F\u043E\u0441\u043B\u0435 \u043F\u0430\u0434\u0435\u043D\u0438\u044F" + m_Metadata: + m_Items: [] + - m_Id: 199062989416570880 + m_Localized: "\u0441\u0431\u043E\u043A\u0443|\u0441 \u0442\u0435\u043B\u043E\u043C" + m_Metadata: + m_Items: [] + - m_Id: 199062989416570881 + m_Localized: "\u041F\u043E\u0441\u043B\u0435 \u0433\u043B\u0443\u0431\u043E\u043A\u043E\u0433\u043E + \u043F\u0430\u0434\u0435\u043D\u0438\u044F \u0433\u0435\u0440\u043E\u0439 \u043B\u0435\u0436\u0438\u0442 + \u0438 \u0432\u0441\u0442\u0430\u0451\u0442: \u0432\u0438\u0434 \u043E\u0441\u0442\u0430\u0451\u0442\u0441\u044F + \u0441\u0431\u043E\u043A\u0443 (\u043D\u0435 \u043E\u043F\u0443\u0441\u043A\u0430\u0435\u0442\u0441\u044F) + \u0438\u043B\u0438 \u043E\u043F\u0443\u0441\u043A\u0430\u0435\u0442\u0441\u044F + \u0438 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u0435\u0442\u0441\u044F \u0432\u043C\u0435\u0441\u0442\u0435 + \u0441 \u0442\u0435\u043B\u043E\u043C" + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] From 7303f233f3ce73f6ef4fae2e6ee6f37eb3889796 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 16:24:44 +0000 Subject: [PATCH 38/41] refactor: one measurement for the running jump - Core keeps the take-off velocity (HeroAirborneDomain/HeroFallService.TakeOffVelocity next to IsRunningJump), HeroFallService.Tick returns the event it handled and VrHeroJumpFall starts the leap on JumpStarted in that direction (its own smoothed velocity and phase-edge check are gone); tests for the take-off velocity Co-Authored-By: Claude Opus 5.5 --- .../Domain/Movement/HeroAirborneDomain.cs | 17 +++- .../Services/Movement/HeroFallService.cs | 18 ++++- .../Movement/HeroAirborneDomainTest.cs | 31 ++++++- .../Scripts/Adapters/Player/VrHeroJumpFall.cs | 81 +++++++------------ Docs/adr/2026-11-29-hero-jump-fall.md | 2 +- 5 files changed, 91 insertions(+), 58 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs index b78d4cdd3..3da5e4ee5 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/HeroAirborneDomain.cs @@ -18,7 +18,7 @@ namespace Gothic.Core.Domain.Movement /// like OpenGothic - the jump's own rise doesn't count, and a jump down a steep slope lands on his feet. A jump /// stays a jump (its pose in the air, the jump's landing) until that deep. /// - A jump taken at running speed (HeroFallSample.RunSpeed) is Gothic's running jump (IsRunningJump), the - /// platform makes it the leap. + /// platform makes it the leap in the direction of TakeOffVelocity - one measurement for both. /// - No fall without real falling: off the ground (beyond the platform's grounded grace) the hero falls only when /// moving down faster than FallSpeed and deeper below the top than the platform's ground snap /// (HeroFallSample.GroundSnapHeight) - stairs, slopes and lifts stay walking. @@ -79,6 +79,13 @@ public class HeroAirborneDomain /// public bool IsRunningJump { get; private set; } + /// + /// The hero's horizontal movement (m/s) when the current jump was taken - what IsRunningJump is decided from, + /// and the running jump's direction. Zero before a take-off and after the landing, kept when the jump becomes + /// a fall. + /// + public Vector3 TakeOffVelocity { get; private set; } + /// /// Where the depth for falling flat is measured from: a jump's take-off, else the fall's start (its top). /// The landing's damage height is always from the top (PeakY). @@ -130,6 +137,7 @@ public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLan IsLyingFall = false; IsBackwards = false; IsRunningJump = false; + TakeOffVelocity = Vector3.zero; _isFromJump = false; Phase = HeroAirPhase.Airborne; } @@ -139,7 +147,9 @@ public HeroAirEvent Tick(in HeroFallSample sample, float safeHeight, out HeroLan { Phase = HeroAirPhase.Jumping; _isFromJump = true; - IsRunningJump = sample.RunSpeed > 0f && _moveVelocity.sqrMagnitude >= sample.RunSpeed * sample.RunSpeed; + TakeOffVelocity = _moveVelocity; + IsRunningJump = sample.RunSpeed > 0f && + TakeOffVelocity.sqrMagnitude >= sample.RunSpeed * sample.RunSpeed; return HeroAirEvent.JumpStarted; } @@ -170,6 +180,7 @@ public void Hold(Vector3 feet) IsLyingFall = false; IsBackwards = false; IsRunningJump = false; + TakeOffVelocity = Vector3.zero; _isFromJump = false; _moveVelocity = Vector3.zero; _previousFeet = feet; @@ -187,6 +198,7 @@ public void Reset() IsLyingFall = false; IsBackwards = false; IsRunningJump = false; + TakeOffVelocity = Vector3.zero; _isFromJump = false; _moveVelocity = Vector3.zero; _hasPrevious = false; @@ -214,6 +226,7 @@ private HeroAirEvent TickGrounded(float feetY, Vector3 forward, out HeroLanding IsLyingFall = false; IsBackwards = false; IsRunningJump = false; + TakeOffVelocity = Vector3.zero; // A step down or a flicker: no jump, no fall - no landing. if (phase is HeroAirPhase.Grounded or HeroAirPhase.Airborne) diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs index 96ded70aa..f5ddcb702 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/HeroFallService.cs @@ -88,6 +88,12 @@ public class HeroFallService /// public bool IsRunningJump => _airborne.IsRunningJump; + /// + /// The hero's horizontal movement (m/s) at the take-off of the jump running now - IsRunningJump is decided + /// from it, the platform's leap goes in its direction. Zero on the ground. + /// + public Vector3 TakeOffVelocity => _airborne.TakeOffVelocity; + public HeroFallService() { GlobalEventDispatcher.LoadGameStart.AddListener(ResetAll); @@ -98,25 +104,28 @@ public HeroFallService() /// /// One frame's measurement of the player's body. Called every frame by the platform, also on the ground. + /// Returns what this frame changed, handled already (None while not tracked) - the platform acts on it (VR: + /// JumpStarted starts the running jump's leap). /// - public void Tick(in HeroFallSample sample) + public HeroAirEvent Tick(in HeroFallSample sample) { UpdateLandingLock(); var hero = _npcService.GetHeroContainer(); if (hero?.Props == null) - return; + return HeroAirEvent.None; var hold = Time.time < _settleEndTime ? HeroFallHold.WorldLoading : GetHold(hero, sample); if (hold != HeroFallHold.None) { Hold(hero, sample.FeetPosition, hold); - return; + return HeroAirEvent.None; } _hold = HeroFallHold.None; var safeHeight = NpcFallDomain.GetSafeFallHeight(_gameStateService.GuildValues, hero); - switch (_airborne.Tick(sample, safeHeight, out var landing)) + var airEvent = _airborne.Tick(sample, safeHeight, out var landing); + switch (airEvent) { case HeroAirEvent.JumpStarted: SetAirBodyState(hero, VmGothicEnums.BodyState.BsJump); @@ -146,6 +155,7 @@ public void Tick(in HeroFallSample sample) "fall is ignored", LogCat.Npc); break; } + return airEvent; } /// diff --git a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs index c99f4a49b..1389e465a 100644 --- a/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs +++ b/Assets/Gothic-Tests/EditMode/Movement/HeroAirborneDomainTest.cs @@ -92,6 +92,11 @@ private void FallTo(float y, float groundY, float velocityY = 0f, bool isJumping Stand(groundY, 2); } + private static void AssertVector(Vector3 expected, Vector3 actual) + { + Assert.AreEqual(0f, Vector3.Distance(expected, actual), 0.01f, $"expected {expected}, was {actual}"); + } + [Test] public void JumpOnFlatGroundLandsAsJumpWithItsOwnHeight() { @@ -108,7 +113,8 @@ public void JumpOnFlatGroundLandsAsJumpWithItsOwnHeight() } /// - /// Taken at running speed: Gothic's running jump (the leap) from the take-off until the landing. + /// Taken at running speed: Gothic's running jump (the leap) from the take-off until the landing, its take-off + /// velocity (the leap's direction) as long. /// [Test] public void JumpAtRunningSpeedIsARunningJumpUntilTheLanding() @@ -118,13 +124,34 @@ public void JumpAtRunningSpeedIsARunningJumpUntilTheLanding() Tick(0f, true, true); Assert.AreEqual(HeroAirPhase.Jumping, _domain.Phase); Assert.IsTrue(_domain.IsRunningJump); + AssertVector(Vector3.forward * 4f, _domain.TakeOffVelocity); Tick(0.05f, false, true); Assert.IsTrue(_domain.IsRunningJump); + AssertVector(Vector3.forward * 4f, _domain.TakeOffVelocity); FallTo(0.05f, 0f - 0.0001f, 3f, true); Assert.AreEqual(1, _landings); Assert.IsTrue(_landing.IsJump); Assert.IsFalse(_domain.IsRunningJump); + AssertVector(Vector3.zero, _domain.TakeOffVelocity); + } + + /// + /// The leap goes where he ran at the take-off: turning the stick in the air doesn't change it. + /// + [Test] + public void TakeOffVelocityIsTheRunAtTheTakeOff() + { + var run = new Vector3(3f, 0f, -3f); + _moveVelocity = run; + Stand(0f); + Tick(0f, true, true); + _moveVelocity = Vector3.left * 1f; + Tick(0.05f, false, true); + Tick(0.1f, false, true); + + Assert.IsTrue(_domain.IsRunningJump); + AssertVector(run, _domain.TakeOffVelocity); } [Test] @@ -136,6 +163,7 @@ public void JumpAtWalkingSpeedIsNoRunningJump() Assert.AreEqual(HeroAirPhase.Jumping, _domain.Phase); Assert.IsFalse(_domain.IsRunningJump); + AssertVector(Vector3.forward * 1.2f, _domain.TakeOffVelocity); } [Test] @@ -148,6 +176,7 @@ public void RunningOffAnEdgeIsNoRunningJump() Assert.AreEqual(HeroAirPhase.Falling, _domain.Phase); Assert.IsFalse(_domain.IsRunningJump); + AssertVector(Vector3.zero, _domain.TakeOffVelocity); } [Test] diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs index db18cdfa3..86216b1dd 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroJumpFall.cs @@ -16,7 +16,8 @@ namespace Gothic.VR.Adapters.Player /// from (VrHeroSpeeds.RunThreshold), teleports. Measures only - the rules are in Core. /// Sits next to VRPlayer (added by VRContextInteractionService). /// A running jump (HeroFallService.IsRunningJump, the sprint) is a long leap at T_RUNL_2_JUMP's forward speed - /// (VrHeroSpeeds.RunJump) in the direction of the run, until he lands, grabs or is teleported + /// (VrHeroSpeeds.RunJump) in the direction of the run (HeroFallService.TakeOffVelocity - Core's measurement, the + /// same that decided the running jump), started on Tick's JumpStarted, until he lands, grabs or is teleported /// (IVrRig.SetLeapVelocity). The standing and walking jump stays straight up. /// public class VrHeroJumpFall : MonoBehaviour @@ -25,14 +26,7 @@ public class VrHeroJumpFall : MonoBehaviour [Inject] private readonly VRSpellTransformService _vrSpellTransformService; [Inject] private readonly VRPlayerService _vrPlayerService; - // The horizontal velocity is smoothed over a few frames - a single frame's step jitters. - private const float _velocitySmoothing = 0.5f; - private IVrRig _rig; - private Vector3 _lastFeet; - private bool _hasLastFeet; - private Vector3 _horizontalVelocity; - private HeroAirPhase _lastPhase; private bool _isLeaping; // Where and when the running jump started - its length is logged at the end. private Vector3 _leapStart; @@ -59,59 +53,48 @@ private void OnDestroy() private void Update() { - var feet = _rig.Root.position; - UpdateHorizontalVelocity(feet); - - var sample = new HeroFallSample(feet, GetFacing(), _rig.IsGrounded, _rig.IsJumping, _rig.IsClimbing, - _vrSpellTransformService != null && _vrSpellTransformService.IsTransformed, _rig.Gravity, - _rig.MaxFallSpeed, _rig.GroundSnapHeight, _vrPlayerService.HeroSpeeds.RunThreshold, Time.deltaTime); - _heroFallService.Tick(sample); - UpdateLeap(); - } - - private void UpdateHorizontalVelocity(Vector3 feet) - { - if (_hasLastFeet && Time.deltaTime > 0f) - { - var step = new Vector3(feet.x - _lastFeet.x, 0f, feet.z - _lastFeet.z) / Time.deltaTime; - _horizontalVelocity = Vector3.Lerp(_horizontalVelocity, step, _velocitySmoothing); - } - _lastFeet = feet; - _hasLastFeet = true; + var sample = new HeroFallSample(_rig.Root.position, GetFacing(), _rig.IsGrounded, _rig.IsJumping, + _rig.IsClimbing, _vrSpellTransformService != null && _vrSpellTransformService.IsTransformed, + _rig.Gravity, _rig.MaxFallSpeed, _rig.GroundSnapHeight, _vrPlayerService.HeroSpeeds.RunThreshold, + Time.deltaTime); + UpdateLeap(_heroFallService.Tick(sample)); } /// - /// The leap starts with a running jump and lasts while he is in the air (jumping or falling) - landing, water, - /// a ledge or ladder, a teleport end it (HeroFallService's phase is back on the ground then). + /// The leap starts with a running jump (JumpStarted) and lasts while he is in the air (jumping or falling) - + /// landing, water, a ledge or ladder, a teleport end it (HeroFallService's phase is back on the ground then). /// - private void UpdateLeap() + private void UpdateLeap(HeroAirEvent airEvent) { - var phase = _heroFallService.Phase; - var previousPhase = _lastPhase; - _lastPhase = phase; - - if (phase == HeroAirPhase.Jumping && previousPhase != HeroAirPhase.Jumping) + if (airEvent == HeroAirEvent.JumpStarted) { - if (!_heroFallService.IsRunningJump) - return; - - var runJump = _vrPlayerService.HeroSpeeds.RunJump; - var direction = _horizontalVelocity.sqrMagnitude > 0.0001f - ? _horizontalVelocity.normalized - : GetFacing().normalized; - _rig.SetLeapVelocity(direction * runJump); - _isLeaping = true; - _leapStart = _rig.Root.position; - _leapStartTime = Time.time; - Logger.Log($"[VrHeroJumpFall] Running jump ({_horizontalVelocity.magnitude:F2} m/s) - leap at " + - $"{runJump:F2} m/s", LogCat.VR); + if (_heroFallService.IsRunningJump) + StartLeap(_heroFallService.TakeOffVelocity); return; } + var phase = _heroFallService.Phase; if (_isLeaping && phase is not (HeroAirPhase.Jumping or HeroAirPhase.Falling)) EndLeap(phase == HeroAirPhase.Grounded ? "on the ground" : phase.ToString()); } + /// + /// The running jump's leap in the direction he ran at the take-off (his facing if that measured nothing). + /// + private void StartLeap(Vector3 takeOffVelocity) + { + var runJump = _vrPlayerService.HeroSpeeds.RunJump; + var direction = takeOffVelocity.sqrMagnitude > 0.0001f + ? takeOffVelocity.normalized + : GetFacing().normalized; + _rig.SetLeapVelocity(direction * runJump); + _isLeaping = true; + _leapStart = _rig.Root.position; + _leapStartTime = Time.time; + Logger.Log($"[VrHeroJumpFall] Running jump ({takeOffVelocity.magnitude:F2} m/s) - leap at " + + $"{runJump:F2} m/s", LogCat.VR); + } + private void EndLeap(string reason) { if (!_isLeaping) @@ -135,8 +118,6 @@ private Vector3 GetFacing() private void OnTeleported(Vector3 feetPosition) { - _lastFeet = feetPosition; - _horizontalVelocity = Vector3.zero; EndLeap("teleported"); _heroFallService.OnTeleported(feetPosition); } diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md index 3d61371ee..d69da1072 100644 --- a/Docs/adr/2026-11-29-hero-jump-fall.md +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -16,7 +16,7 @@ In the original game the falling animation starts early and the hero then falls 3. **No fall damage in water, on teleports, while climbing, while transformed into a monster, while lying, and in god mode.** Water means any water level (wading, swimming, diving); a teleport is any move by the game or the player (teleport, Marvin, scripts, loading, ledge and ladder exits) and also a step no fall can make in one frame; grabbing a ladder or ledge mid-air ends the fall, and letting go starts a new one from there. A transformed hero falls as the monster's puppet: no damage, his monster's own rules are not applied. Not chosen: monster fall rules for the transformed hero, left for later. 4. **Falling plays Gothic's animations on the VR hero body:** the take-off at its own speed, cut short when he lands first (the running jump's from running, Gothic's jump-up from standing or walking - not its standing forward leap, the VR jump goes straight up), the pose in the air, the short landing; the falling pose, then falling flat, the small landing. Stairs, slopes, small steps and slow lifts are no fall. 5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. A jump is different: he falls flat only when he lands deeper than the safe height (5 m) below where he jumped off, like OpenGothic - not counting the jump's own rise (1 m), so jumping down a steep slope lands on his feet. The damage height still counts from the top. The landing checks the depth again, so a drop past it in a single frame (a hitch) lands lying too. Not chosen: the 2 m for jumps too, or measured from the top of the jump, which laid him on his face after ordinary running jumps downhill (play tests). -6. **A jump at running speed (the sprint) is Gothic's running jump: a long leap forward at the speed of its animation (about 5 m/s for the hero, scaled with the body), in the direction he ran, until he lands.** The stick doesn't add to it in the air, walls stop it, grabbing a ledge or ladder, a teleport or water end it. The standing and walking jump stays straight up; both rise 1 m. The arms don't flail like in Gothic: they are the player's hands. The rules decide it from the speed at the take-off against the speed the hero runs from, which the platform gives; the platform only performs the leap. Not chosen: the plain VR jump at running speed, which was a short hop compared to Gothic's leap. Not chosen either: deciding it from BS_RUN, which stays for a moment after he stops running (so NPCs give up a chase like in Gothic) - a jump just after stopping would have leapt. +6. **A jump at running speed (the sprint) is Gothic's running jump: a long leap forward at the speed of its animation (about 5 m/s for the hero, scaled with the body), in the direction he ran, until he lands.** The stick doesn't add to it in the air, walls stop it, grabbing a ledge or ladder, a teleport or water end it. The standing and walking jump stays straight up; both rise 1 m. The arms don't flail like in Gothic: they are the player's hands. The rules decide it from the speed at the take-off against the speed the hero runs from, which the platform gives, and keep that take-off speed for the leap's direction - one measurement for both; the platform only performs the leap. Not chosen: the plain VR jump at running speed, which was a short hop compared to Gothic's leap. Not chosen either: deciding it from BS_RUN, which stays for a moment after he stops running (so NPCs give up a chase like in Gothic) - a jump just after stopping would have leapt. 7. **He falls on his back when he went over the edge moving backwards (against where he faces), otherwise on his face.** Each side has its own landing, lying and getting up; if the hero's model lacks the back set, he falls on his face. 8. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** The rules time it once - when he starts getting up and when he stands - and the VR hero body follows those times, so the body and the lock end together. Turning and the hands stay free. A blocked walk blocks jumping too - here, in dialogs and when knocked out. A teleport or his death ends the lock. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. 9. **A new Immersion option decides the view while he lies after a fall flat: the camera stays at the player's head (default), or it goes down with the body and comes back up while he stands up.** The default spares the player a sudden drop of the view after a long fall. Not chosen: reusing the knockout view option, which is about the game taking the hero down, not about a landing the player caused. From 2bdf4d26cf8c269f4ef3acd076454ee1a6d31800 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 16:25:18 +0000 Subject: [PATCH 39/41] refactor: the upright fall's names (S_FALLDN, T_FALLDN_2_STAND) next to the fall flat's - FallPose.FallDown / FallDownToStand, used by NpcJumpFall and VrHeroLocomotion instead of their own literals Co-Authored-By: Claude Opus 5.5 --- .../Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs | 4 ++-- .../Gothic-Core/Scripts/Models/Movement/FallPose.cs | 13 ++++++++++++- .../Scripts/Adapters/Player/VrHeroLocomotion.cs | 8 +++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs b/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs index b88f01536..279390f44 100644 --- a/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs +++ b/Assets/Gothic-Core/Scripts/Adapters/Npc/NpcJumpFall.cs @@ -219,7 +219,7 @@ private void StartFall(Vector3 velocityH) _physicsService.DisablePhysicsForNpc(_npc.PrefabProps); _npc.PrefabProps.AnimationSystem.StopAllAnimations(); - _fallAnimName = "S_FALLDN"; + _fallAnimName = FallPose.FallDown; PlayIfExists(_fallAnimName); Logger.Log($"[NpcJumpFall] {_npc.Go.name} falls (speed {_fallVelocityH.magnitude:F1} m/s).", LogCat.Ai); @@ -298,7 +298,7 @@ private void Land(float height) _isThrown = false; StartSequence(State.Landing, isDeep ? new[] { FallPose.Front.Landing, FallPose.Front.StandUp } - : new[] { "T_FALLDN_2_STAND" }); + : new[] { FallPose.FallDownToStand }); // NPCs' fall damage comes with the combat system, the hero's always (HeroFallService). var damage = NpcFallDomain.GetFallDamage(_gameStateService.GuildValues, _npc, height); diff --git a/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs b/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs index a8c373c86..ddf839dc6 100644 --- a/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs +++ b/Assets/Gothic-Core/Scripts/Models/Movement/FallPose.cs @@ -3,10 +3,21 @@ namespace Gothic.Core.Models.Movement /// /// The animations of a fall flat (deeper than NpcFallDomain.LyingFallHeight) in HUMANS.MDS: on the face, or on the /// back after going over the edge backwards. G1 and G2 have both sets. The hero falls on either (HeroFallService), - /// NPCs on the front only (NpcJumpFall). + /// NPCs on the front only (NpcJumpFall). Before that, and for any shallower fall, both fall upright: FallDown, + /// landing on the feet with FallDownToStand. /// public readonly struct FallPose { + /// + /// The upright fall in the air (the first falling pose, before a fall flat). + /// + public const string FallDown = "S_FALLDN"; + + /// + /// Landing on the feet from the upright fall. + /// + public const string FallDownToStand = "T_FALLDN_2_STAND"; + public static readonly FallPose Front = new("S_FALL", "T_FALL_2_FALLEN", "S_FALLEN", "T_FALLEN_2_STAND", "S_DEAD"); diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs index 9853a165e..03b592d8b 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroLocomotion.cs @@ -37,7 +37,6 @@ public class VrHeroLocomotion private const string _runAnimation = "S_RUNL"; private const string _sneakAnimation = "S_SNEAKL"; private const string _walkBackAnimation = "S_WALKBL"; - private const string _fallAnimation = "S_FALLDN"; // Jumps and falls: take-off -> in the air -> landing, S_FALLDN -> S_FALL / S_FALLB (deeper than 2 m) -> landing // Standing and walking the VR jump goes straight up: Gothic's jump-up (G1: T_STAND_2_JUMPUP 0.40 s). Its @@ -51,7 +50,6 @@ public class VrHeroLocomotion private const string _jumpToStand = "T_JUMP_2_STAND"; // Not in G1's HUMANS.MDS: landing from a run goes straight on running then. private const string _jumpToRun = "T_JUMP_2_RUNL"; - private const string _fallToStand = "T_FALLDN_2_STAND"; private HeroAirPhase _airPhase; // A landing since the last frame (HeroLanded), its animation not picked yet. private HeroLanding? _newLanding; @@ -301,9 +299,9 @@ private void StartTakeOff() private string GetFallAnimation() { if (!_heroFallService.IsLyingFall) - return _fallAnimation; + return FallPose.FallDown; var flight = _heroFallService.LyingFallPose.Flight; - return _animator.HasAnimation(flight) ? flight : _fallAnimation; + return _animator.HasAnimation(flight) ? flight : FallPose.FallDown; } /// @@ -320,7 +318,7 @@ private void StartLanding(HeroLanding landing, float speed, bool isMoving) if (landing.IsJump && isRunning && _animator.HasAnimation(_jumpToRun)) StartAirOneShot(_jumpToRun); else if (!isMoving) - StartAirOneShot(landing.IsJump ? _jumpToStand : _fallToStand); + StartAirOneShot(landing.IsJump ? _jumpToStand : FallPose.FallDownToStand); } /// From 99f05ee187a5494ca26c2aa50f2c8dbab236f168 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 16:26:00 +0000 Subject: [PATCH 40/41] fix: a teleport during a lying landing (also a ledge or ladder exit) ends the VR body's lying too - VrHeroDownPose listens to IVrRig.Teleported, so the body no longer lies on after HeroFallService ended the walking lock Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Player/VrHeroDownPose.cs | 35 +++++++++++++++++-- Docs/adr/2026-11-29-hero-jump-fall.md | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs index e8167366f..7f35ac05c 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VrHeroDownPose.cs @@ -31,7 +31,8 @@ namespace Gothic.VR.Adapters.Player /// FallPose (T_FALL_2_FALLEN, S_FALLEN, T_FALLEN_2_STAND, on his back FALLB/FALLENB) at HeroFallService's times /// (HeroLanding.StandUpStart / StandUpEnd, the same as its walking lock) - whatever heroFallMode is; the Immersion /// option heroLandingView decides whether the camera goes with the head (VRPlayerService.HeroLandingView, default: - /// it stays at the player's head). Killed by the fall, he stays lying dead (S_DEAD, on his back S_DEADB). + /// it stays at the player's head). Killed by the fall, he stays lying dead (S_DEAD, on his back S_DEADB). A + /// teleport (IVrRig.Teleported, also a ledge or ladder exit) ends the lying landing at once, like the walking lock. /// Worker of VRHeroBody (new().Inject(), Initialize, Bind, Dispose). /// public class VrHeroDownPose @@ -126,6 +127,7 @@ public void Dispose() GlobalEventDispatcher.MenuOpened.RemoveListener(OnMenuOpened); GlobalEventDispatcher.MenuClosed.RemoveListener(OnMenuClosed); EndDown(); + SetRig(null); _body = null; _vrPlayerService.SetHeroFallBody(false); } @@ -207,6 +209,35 @@ private void OnLoadGameStart() EndDown(); } + /// + /// The rig whose teleports end a lying landing (UpdateDown gives it every frame, Dispose none). + /// + private void SetRig(IVrRig rig) + { + if (ReferenceEquals(rig, _rig)) + return; + if (_rig != null) + _rig.Teleported -= OnTeleported; + _rig = rig; + if (_rig != null) + _rig.Teleported += OnTeleported; + } + + /// + /// Teleported (thumbstick, Marvin, scripts, a ledge or ladder exit): a lying landing ends at once - he arrives + /// standing, HeroFallService ends the walking lock too. Dead, knocked out or asleep he stays down. + /// + private void OnTeleported(Vector3 feetPosition) + { + if (_downReason == DownReason.Landing) + { + Logger.Log("[VRHeroBody] Teleported - the lying landing ends", LogCat.VR); + EndDown(); + } + else if (_downReason == DownReason.None) + _landing = null; + } + private void OnMenuOpened(GameObject menu) { _isMenuOpen = true; @@ -222,7 +253,7 @@ private void OnMenuClosed() /// public bool UpdateDown(Transform head, float feetY, float standingScale, IVrRig rig) { - _rig = rig; + SetRig(rig); var isDown = _isDead || _isKnockedOut || _isAsleep; if (!isDown && _downReason == DownReason.Dead) { diff --git a/Docs/adr/2026-11-29-hero-jump-fall.md b/Docs/adr/2026-11-29-hero-jump-fall.md index d69da1072..e16760ca6 100644 --- a/Docs/adr/2026-11-29-hero-jump-fall.md +++ b/Docs/adr/2026-11-29-hero-jump-fall.md @@ -18,7 +18,7 @@ In the original game the falling animation starts early and the hero then falls 5. **Deeper than 2 m the hero falls flat and lands lying, the same height NPCs use - not the 5 m where the damage starts.** The first falling pose is almost upright; waiting for 5 m showed the flat fall hardly ever (play test). So a 3 m fall is a flat fall, a lying landing, and no damage: how he lands and what it costs are separate rules. Not chosen: falling flat only above the safe height, which tied the look to the damage. A jump is different: he falls flat only when he lands deeper than the safe height (5 m) below where he jumped off, like OpenGothic - not counting the jump's own rise (1 m), so jumping down a steep slope lands on his feet. The damage height still counts from the top. The landing checks the depth again, so a drop past it in a single frame (a hitch) lands lying too. Not chosen: the 2 m for jumps too, or measured from the top of the jump, which laid him on his face after ordinary running jumps downhill (play tests). 6. **A jump at running speed (the sprint) is Gothic's running jump: a long leap forward at the speed of its animation (about 5 m/s for the hero, scaled with the body), in the direction he ran, until he lands.** The stick doesn't add to it in the air, walls stop it, grabbing a ledge or ladder, a teleport or water end it. The standing and walking jump stays straight up; both rise 1 m. The arms don't flail like in Gothic: they are the player's hands. The rules decide it from the speed at the take-off against the speed the hero runs from, which the platform gives, and keep that take-off speed for the leap's direction - one measurement for both; the platform only performs the leap. Not chosen: the plain VR jump at running speed, which was a short hop compared to Gothic's leap. Not chosen either: deciding it from BS_RUN, which stays for a moment after he stops running (so NPCs give up a chase like in Gothic) - a jump just after stopping would have leapt. 7. **He falls on his back when he went over the edge moving backwards (against where he faces), otherwise on his face.** Each side has its own landing, lying and getting up; if the hero's model lacks the back set, he falls on his face. -8. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** The rules time it once - when he starts getting up and when he stands - and the VR hero body follows those times, so the body and the lock end together. Turning and the hands stay free. A blocked walk blocks jumping too - here, in dialogs and when knocked out. A teleport or his death ends the lock. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. +8. **After a fall flat he lands lying, stays down a moment and gets up; walking is locked meanwhile, as long as that side's animations take (about one and a half seconds).** The rules time it once - when he starts getting up and when he stands - and the VR hero body follows those times, so the body and the lock end together. Turning and the hands stay free. A blocked walk blocks jumping too - here, in dialogs and when knocked out. A teleport (also a ledge or ladder exit) ends the lock and the body's lying at once, so he arrives standing; his death ends the lock. Both controllers give a short strong pulse. If the fall kills him, he stays lying on his face or back and the usual death takes over. 9. **A new Immersion option decides the view while he lies after a fall flat: the camera stays at the player's head (default), or it goes down with the body and comes back up while he stands up.** The default spares the player a sudden drop of the view after a long fall. Not chosen: reusing the knockout view option, which is about the game taking the hero down, not about a landing the player caused. ## Consequences From 2f667fa52017571306397a0ebb22f78c50fd9831 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 16:26:34 +0000 Subject: [PATCH 41/41] style: the VrPhysicsHand snap-distance tooltip and the heroLandingView menu comment wrapped to 120 columns Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Interaction/Components/VrPhysicsHand.cs | 5 +++-- .../Scripts/Services/Context/VRContextMenuService.cs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Interaction/Components/VrPhysicsHand.cs b/Assets/Gothic-VR/Scripts/Interaction/Components/VrPhysicsHand.cs index 063db838f..d40fa5f28 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Components/VrPhysicsHand.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Components/VrPhysicsHand.cs @@ -84,8 +84,9 @@ public class VrPhysicsHand : MonoBehaviour [SerializeField] private float _rigSnapAngle = 10f; - [Tooltip("A rig move larger than this (m per frame) is a teleport: the hand snaps with the rig. At least what " + - "the rig can fall in the frame (terminal speed + 5 m/s) - a fast fall at a low frame rate isn't one.")] + [Tooltip("A rig move larger than this (m per frame) is a teleport: the hand snaps with the rig. At least " + + "what the rig can fall in the frame (terminal speed + 5 m/s) - a fast fall at a low frame rate " + + "isn't one.")] [SerializeField] private float _rigSnapDistance = 1f; diff --git a/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs b/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs index 6c07040d9..4dfe92f35 100644 --- a/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs +++ b/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs @@ -116,7 +116,8 @@ public void UpdateMainMenu(AbstractMenuInstance mainMenu) CreateOptionChoice(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_MOVE_VIGNETTE", "moveVignette", VRConstants.IniNames.MoveVignette, VRConstants.IniSectionImmersion, VRConstants.MoveVignetteDefaultValue)), - // After a deep fall: the camera stays at the head or goes down and up with the body (VrHeroLandingView). + // After a deep fall: the camera stays at the head or goes down and up with the body + // (VrHeroLandingView). (CreateOptionLabel(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_HERO_LANDING_VIEW", "heroLandingView"), CreateOptionChoice(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_HERO_LANDING_VIEW", "heroLandingView", VRConstants.IniNames.HeroLandingView, VRConstants.IniSectionImmersion,