Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions Assets/Gothic-VR/Scripts/Adapters/Player/VRSwimDive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class VRSwimDive : MonoBehaviour, IMarvinPropertyCollector

// Swim + Dive properties
private Vector3 _currentVelocity;
// 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;
private bool _isSwimDiveForceRightJustStarted;
Expand Down Expand Up @@ -105,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.
Expand Down Expand Up @@ -176,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)
if (_playerAi == null || _isStoppedByDeath)
return;

if (_mode == VmGothicEnums.WalkMode.Swim)
Expand All @@ -195,7 +206,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.
Expand Down Expand Up @@ -541,6 +552,44 @@ private void HandleSwim()
}
}

/// <summary>
/// A dead hero doesn't swim: no strokes (the hands moving for the death menu pushed the corpse and the menu
/// 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).
/// </summary>
private void OnHeroDied(NpcContainer hero)
{
if (_isStoppedByDeath)
return;

_isStoppedByDeath = true;
_currentVelocity = Vector3.zero;
if (_waterBobbingCoroutine != null)
{
StopCoroutine(_waterBobbingCoroutine);
_waterBobbingCoroutine = null;
}
if (_mode == VmGothicEnums.WalkMode.Dive)
{
_playerService.StopDiving();
_rig.Fade(0, float.MaxValue);
}

Logger.Log($"[VRSwimDive] The hero died ({_mode}) - swimming stops until a game is loaded.", LogCat.VR);
}

/// <summary>
/// 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).
/// </summary>
private void OnLoadGameStart()
{
_isStoppedByDeath = false;
_heroContainer = null;
_playerVob = null;
_playerAi = null;
}

private bool IsHandBelowWater(Transform handTransform)
{
RaycastHit hit;
Expand Down