Skip to content

fix: NPCs hear the VR hero walking or running behind them again - every NPC starts standing, the hero's speed comes from the rig - #567

Open
BoroBongo wants to merge 3 commits into
developfrom
fix/hero-body-state
Open

BoroBongo wants to merge 3 commits into
developfrom
fix/hero-body-state

Conversation

@BoroBongo

Copy link
Copy Markdown
Contributor

What

NPCs hear the VR hero again: a guard turns around when the hero walks or runs up behind him. Sneaking works again too: crouching with the sneak talent makes the hero quiet, and guards watch him (ZS_ObservePlayer).

Two bugs together kept the hero from ever walking, running or sneaking for the scripts:

  • No start value for the body state. NpcProperties.BodyState started at 0, but BS_STAND is 98304 because it carries the interruptable and free-hands flags. So 0 is no body state at all. VRHeroMovement only updates stand/walk/run/sneak, so it skipped the hero every frame, for the whole game. Every idle NPC was 0 too, and C_BodyStateContains(npc, BS_STAND) was false for it. The field now starts at BsStand for NPCs, the hero (VR and Flat) and NPCs rebuilt on load.
  • Zero speed under XRI. CharacterController.velocity was 0 in every frame the rig moved: XriRig.SnapToGround does a downward Move() after the walk, and Unity's velocity only reflects the last Move(). The speed now comes from how far the rig root moved this frame.

Why

Regression from the XRI rig (HVR reported a real velocity) and the PR split. Reported in a playtest: Mika at Khorinis' east gate (G2) ignored the hero standing right behind him.

How to test manually

Hero body states are not logged per frame. The script reactions below are the visible proof.

  • G2, Khorinis east gate: walk up behind Mika (no crouch). Within ~5 m he turns and starts his "where are you going" dialog.
  • G2: with the sneak talent, crouch and move up behind a guard. He observes the hero (ZS_ObservePlayer in the log), or stays unaware where the scripts say so.
  • G1: stand in the way of a walking NPC. B_MoveNpc now gets past its C_BodyStateContains(other, BS_STAND) check (it always returned early before), so the NPC reacts.
  • Run away from an NPC chasing you: ZS_Attack_Loop gives up the chase after a while ($RUNCOWARD).
  • Hero footsteps play while walking. Swimming, sitting on a bench, getting knocked out and standing up again all return to standing and walking.
  • G1 + G2 smoke test: NPC routines (sitting, sleeping, eating) and spells cast on idle NPCs (sleep, shrink) look as before. Idle NPCs now count as standing, so the spell states skip an extra AI_StandUp.

No DeveloperConfig flags.

Save/load

BodyState is not saved. After a load, every NPC starts standing again (dead NPCs are set dead afterwards, as before). Nothing is applied twice.

Known gaps / follow-ups

🤖 Generated with Claude Code

BoroBongo and others added 3 commits November 24, 2026 23:43
… 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 <[email protected]>
…nt 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 <[email protected]>
@BoroBongo

Copy link
Copy Markdown
Contributor Author

Review (architecture-reviewer + gothic-reviewer) on 73a8054

Verdicts:

  • Architecture: fits, with concerns (1 Major, 2 Minor).
  • Gothic: approve with minor findings (no blockers). The script side effects were checked: sneak reactions, chase run-away, pickpocket, swimming, flags.
# Agent Severity Finding Answer
1 arch Major NpcProperties.BodyState has no start value, so every NPC starts at 0 (no body state). The fix belongs in Core, not in the VR adapter. Fixed in e5d67d3: the field starts at BsStand, and the VR workaround is gone. Measured after a G2 load: no NPC at 0 (995 standing, the rest lying, sitting, dead or holding an item).
2 arch Minor The hero's speed is measured in two places, and VRSpellTransformPuppet still reads CharacterController.velocity. Follow-up #566
3 arch Minor The speed -> walk/run/sneak rule lives in VR, and Flat has none. Follow-up #566
4 gothic Medium-low Per-frame speed noise: one fast frame gives 1.5 s of run. Disagree. VR movement is 1.5 m/s, above the 1 m/s run threshold on purpose (Gothic runs by default). Measured in play mode: only BsRun/BsStand, no flicker.
5 gothic Low BsRun for 1.5 s after a load or teleport. Keep. It was there before this PR and is harmless.
6 gothic Low Vague log wording. Resolved by #1 (the block and its log are gone).
7 gothic Nit Comments over 120 columns; BodyState == 0 reads poorly. Fixed in 79b0e19 (the == 0 went with #1).

Editor checks (G2, save in Khorinis), all passed:

  • Per-frame probe before the fix: the hero was 0 in all 483 frames, while moving at up to 3.5 m/s.
  • CharacterController.velocity was 0 in all 96 frames where the rig moved.
  • After the fix, Mika talks when approached from behind at 3.4 m.
  • Sneaking up makes him observe the hero (ZS_ObservePlayer).
  • No exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant