From aa7dddc4516905505c1a85b5548968d057fb7614 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Tue, 24 Nov 2026 23:43:06 +0000 Subject: [PATCH 1/3] fix: NPCs hear the VR hero walking or running behind them again - the hero had no body state and never walked, ran or sneaked The hero's BodyState stayed 0 the whole game (BS_STAND is 98304, it carries flags), so UpdateHeroBodyState returned early every frame: hearing (walk/run only), sneaking, ZS_Attack_Loop's run-away and the pickpocket rules never saw a moving hero. Under the XRI rig CharacterController.velocity was also 0 in every moving frame (the ground snap's downward Move comes last), so the speed now comes from the rig's movement per frame. G2: Mika turns and talks when approached from behind, sneaking up makes him observe the hero. Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Player/VRHeroMovement.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs index dde896027..bae5c5388 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs @@ -196,7 +196,19 @@ private void UpdateHeroBodyState() _lastBodyStatePosition = position; var props = heroInstance.GetUserData()?.Props; - if (props == null || props.BodyState is not (VmGothicEnums.BodyState.BsStand + if (props == null) + return; + + // A hero nothing has set a body state for yet is 0 - not BS_STAND (that one carries flags). It counts as + // standing: before, the hero stayed 0 for the whole game, never walked or ran, and NPCs never heard him. + if (props.BodyState == 0) + { + Logger.Log("[VRHeroMovement] The hero had no body state yet - set from his movement from now on.", + LogCat.VR); + props.BodyState = VmGothicEnums.BodyState.BsStand; + } + + if (props.BodyState is not (VmGothicEnums.BodyState.BsStand or VmGothicEnums.BodyState.BsWalk or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSneak)) return; @@ -213,8 +225,10 @@ or VmGothicEnums.BodyState.BsWalk or VmGothicEnums.BodyState.BsRun return; } - var velocity = _rig.CharacterController.velocity; - var speed = new Vector2(velocity.x, velocity.z).magnitude; + // The rig's own movement this frame, not CharacterController.velocity: that is only the last Move() of the + // frame, and the XRI rig's ground snap (XriRig.SnapToGround) moves straight down after the walk - the + // hero stayed BS_STAND while walking, so NPCs never heard him behind their backs. + var speed = isFirstCheck || Time.deltaTime <= 0f ? 0f : horizontalJump / Time.deltaTime; var bodyState = speed switch { >= _bodyStateRunSpeed => VmGothicEnums.BodyState.BsRun, From e5d67d3a9d592adcc2a7021928080b34f9105681 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Tue, 24 Nov 2026 23:44:55 +0000 Subject: [PATCH 2/3] fix: every NPC and the hero start standing (BS_STAND) - idle NPCs count as standing for the scripts, not as no body state NpcProperties.BodyState had no start value, so every NPC, the hero (VR and Flat) and NPCs rebuilt on save load started at 0. BS_STAND is 98304 (it carries the interruptable and free-hands flags), so 0 is no Gothic body state: Npc_GetBodyState gave 0 to the scripts, C_BodyStateContains(npc, BS_STAND) and Npc_HasBodyFlag were false for every idle NPC until a walk action ran, and the writers (VR hero movement, swimming, water, falling) skipped it. The start value now lives next to the field, so VRHeroMovement no longer patches the hero's 0. G1: a standing hero blocking an NPC gets the B_MoveNpc reaction; spells on idle NPCs no longer make them stand up first. NPCs already chest-deep in water at spawn count as swimming. Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Properties/NpcProperties.cs | 4 +++- .../Scripts/Adapters/Player/VRHeroMovement.cs | 14 +------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Adapters/Properties/NpcProperties.cs b/Assets/Gothic-Core/Scripts/Adapters/Properties/NpcProperties.cs index 31d2f4a7c..c6a587fe0 100644 --- a/Assets/Gothic-Core/Scripts/Adapters/Properties/NpcProperties.cs +++ b/Assets/Gothic-Core/Scripts/Adapters/Properties/NpcProperties.cs @@ -121,7 +121,9 @@ public bool AreAllQueued(Func match) // HINT: This information isn't set within Daedalus. We need to define it manually. // HINT: i.e. every animation might have a BS. E.g. when AI_TakeItem() is called, we set BS.BS_TAKEITEM - public VmGothicEnums.BodyState BodyState; + // Starts as BS_STAND, not 0: BS_STAND carries flags (interruptable, free hands), so 0 is no body state and + // C_BodyStateContains(npc, BS_STAND) was false for every NPC (and the hero) until a walk action ran. + public VmGothicEnums.BodyState BodyState = VmGothicEnums.BodyState.BsStand; /// /// Npc_IsDead(). Like Gothic, it's the death transition (FightService, loading a dead NPC), not HP <= 0: diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs index bae5c5388..b14762b66 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs @@ -196,19 +196,7 @@ private void UpdateHeroBodyState() _lastBodyStatePosition = position; var props = heroInstance.GetUserData()?.Props; - if (props == null) - return; - - // A hero nothing has set a body state for yet is 0 - not BS_STAND (that one carries flags). It counts as - // standing: before, the hero stayed 0 for the whole game, never walked or ran, and NPCs never heard him. - if (props.BodyState == 0) - { - Logger.Log("[VRHeroMovement] The hero had no body state yet - set from his movement from now on.", - LogCat.VR); - props.BodyState = VmGothicEnums.BodyState.BsStand; - } - - if (props.BodyState is not (VmGothicEnums.BodyState.BsStand + if (props == null || props.BodyState is not (VmGothicEnums.BodyState.BsStand or VmGothicEnums.BodyState.BsWalk or VmGothicEnums.BodyState.BsRun or VmGothicEnums.BodyState.BsSneak)) return; From 79b0e198be7e60229eb91e54619c1b38c585f5dc Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Tue, 24 Nov 2026 23:45:38 +0000 Subject: [PATCH 3/3] style: wrap the hero body state comments at 120 columns Co-Authored-By: Claude Haiku 5.5 --- Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs index b14762b66..4672d4360 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRHeroMovement.cs @@ -202,8 +202,8 @@ or VmGothicEnums.BodyState.BsWalk or VmGothicEnums.BodyState.BsRun return; // Crouched = sneaking. - // Lying or standing up (the VR hero body's fall camera lowers the head) isn't sneaking - an NPC asked "why are you - // sneaking around" while the hero got up. + // Lying or standing up (the VR hero body's fall camera lowers the head) isn't sneaking - an NPC asked "why + // are you sneaking around" while the hero got up. // Like the engine (OpenGothic Npc::canSneak) only with the sneak // talent - without it a crouching hero just walks: guards turn to him, Lukis hears him coming. if (_rig.IsCrouching && !_vrPlayerService.IsHeroBodyDown &&