From 6949cf7e2628f4c648d3795983e327e4f7c73abf Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Mon, 30 Nov 2026 00:17:12 +0000 Subject: [PATCH 1/2] fix: a hero who died in water no longer swims - the corpse and the death menu stay still, "New game" and "Load" can be hit Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Player/VRSwimDive.cs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs index 929752dbe..44997d00b 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs @@ -53,6 +53,8 @@ public class VRSwimDive : MonoBehaviour, IMarvinPropertyCollector // Swim + Dive properties private Vector3 _currentVelocity; + // The hero died (in water or wherever): swimming stops until a game is loaded - one log per death. + private bool _isStoppedByDeath; // If we lift the grips, we set it to false again to re-enable sounds later. private bool _isSwimDiveForceLeftJustStarted; private bool _isSwimDiveForceRightJustStarted; @@ -178,7 +180,7 @@ SfxModel FindSwimSfx(string animName) private void Update() { - if (_playerAi == null) + if (_playerAi == null || IsStoppedByDeath()) return; if (_mode == VmGothicEnums.WalkMode.Swim) @@ -195,7 +197,7 @@ private void FixedUpdate() * 3. Check if we need to swim as w are chest deep in water. */ - if (_playerVob == null) + if (_playerVob == null || IsStoppedByDeath()) return; // FIXME - As we have different sizes of people in VR, we should use the size based on real heights. @@ -541,6 +543,28 @@ private void HandleSwim() } } + /// + /// A dead hero doesn't swim: no strokes (the hands moving for the death menu pushed the corpse and the menu + /// with it), no dive, no switch of the water controls. Loading a game makes him alive again. + /// + private bool IsStoppedByDeath() + { + if (_gameStateService.IsHeroAlive) + { + _isStoppedByDeath = false; + return false; + } + + if (!_isStoppedByDeath) + { + _isStoppedByDeath = true; + _currentVelocity = Vector3.zero; + Logger.Log($"[VRSwimDive] The hero is dead - swimming stops (was {_mode}).", LogCat.VR); + } + + return true; + } + private bool IsHandBelowWater(Transform handTransform) { RaycastHit hit; From 787f698e9d767a4c9b3a9043aaea9f624b078664 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Mon, 30 Nov 2026 00:21:49 +0000 Subject: [PATCH 2/2] fix: a hero who died in water stops bobbing and diving too - HeroDied stops it all at once, a loaded game starts over without reading the old world's hero Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Adapters/Player/VRSwimDive.cs | 53 ++++++++++++++----- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs index 44997d00b..edfd4c5bb 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs @@ -53,7 +53,7 @@ public class VRSwimDive : MonoBehaviour, IMarvinPropertyCollector // Swim + Dive properties private Vector3 _currentVelocity; - // The hero died (in water or wherever): swimming stops until a game is loaded - one log per death. + // The hero died (HeroDied): swimming, diving and the bobbing stop until a game is loaded (LoadGameStart). private bool _isStoppedByDeath; // If we lift the grips, we set it to false again to re-enable sounds later. private bool _isSwimDiveForceLeftJustStarted; @@ -107,6 +107,9 @@ private void Start() { Shader.SetGlobalInt(Constants.ShaderPropertyWaterEffectToggle, 0); + GlobalEventDispatcher.HeroDied.AddListener(OnHeroDied); + GlobalEventDispatcher.LoadGameStart.AddListener(OnLoadGameStart); + GlobalEventDispatcher.ZenKitBootstrapped.AddListener(() => { // G2's Humans.mds has the same swim animations and sounds as G1's. @@ -178,9 +181,15 @@ SfxModel FindSwimSfx(string animName) _initialFallSpeed = _rig.MaxFallSpeed; } + private void OnDestroy() + { + GlobalEventDispatcher.HeroDied.RemoveListener(OnHeroDied); + GlobalEventDispatcher.LoadGameStart.RemoveListener(OnLoadGameStart); + } + private void Update() { - if (_playerAi == null || IsStoppedByDeath()) + if (_playerAi == null || _isStoppedByDeath) return; if (_mode == VmGothicEnums.WalkMode.Swim) @@ -197,7 +206,7 @@ private void FixedUpdate() * 3. Check if we need to swim as w are chest deep in water. */ - if (_playerVob == null || IsStoppedByDeath()) + if (_playerVob == null || _isStoppedByDeath) return; // FIXME - As we have different sizes of people in VR, we should use the size based on real heights. @@ -545,24 +554,40 @@ private void HandleSwim() /// /// A dead hero doesn't swim: no strokes (the hands moving for the death menu pushed the corpse and the menu - /// with it), no dive, no switch of the water controls. Loading a game makes him alive again. + /// with it), no bobbing, no dive (its dark fade ends), no switch of the water controls. The mode stays as it + /// was - loading a game starts over (LoadGameStart, then WorldSceneLoaded leaves the water if needed). /// - private bool IsStoppedByDeath() + private void OnHeroDied(NpcContainer hero) { - if (_gameStateService.IsHeroAlive) + if (_isStoppedByDeath) + return; + + _isStoppedByDeath = true; + _currentVelocity = Vector3.zero; + if (_waterBobbingCoroutine != null) { - _isStoppedByDeath = false; - return false; + StopCoroutine(_waterBobbingCoroutine); + _waterBobbingCoroutine = null; } - - if (!_isStoppedByDeath) + if (_mode == VmGothicEnums.WalkMode.Dive) { - _isStoppedByDeath = true; - _currentVelocity = Vector3.zero; - Logger.Log($"[VRSwimDive] The hero is dead - swimming stops (was {_mode}).", LogCat.VR); + _playerService.StopDiving(); + _rig.Fade(0, float.MaxValue); } - return true; + Logger.Log($"[VRSwimDive] The hero died ({_mode}) - swimming stops until a game is loaded.", LogCat.VR); + } + + /// + /// A game is loaded: swimming works again, and the old world's hero isn't read while the new one loads + /// (WorldSceneLoaded sets him again). + /// + private void OnLoadGameStart() + { + _isStoppedByDeath = false; + _heroContainer = null; + _playerVob = null; + _playerAi = null; } private bool IsHandBelowWater(Transform handTransform)