From f21000124b524328537bf9ce5ea736ddc8a191f2 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 21 Sep 2016 20:14:24 +0300 Subject: [PATCH] 0.5 sec delay when switching from swimming to walking or vice versa (prevents rapid switches between swimming/walking if the water level is fluctuating around the minimum swimming depth) --- .../Animation/HumanoidAnimController.cs | 26 ++++++++++++++++--- .../Source/Characters/Animation/Ragdoll.cs | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs index 877fe4be4..76ec4a25b 100644 --- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs @@ -21,6 +21,9 @@ namespace Barotrauma private float cprAnimState; + private float inWaterTimer; + private bool swimming; + protected override float HeadPosition { get @@ -44,7 +47,7 @@ namespace Barotrauma return Crouching ? base.TorsoAngle+0.5f : base.TorsoAngle; } } - + public HumanoidAnimController(Character character, XElement element) : base(character, element) { @@ -220,11 +223,28 @@ namespace Barotrauma default: if (character.SelectedCharacter != null) DragCharacter(character.SelectedCharacter); - + + //0.5 second delay for switching between swimming and walking + //prevents rapid switches between swimming/walking if the water level is fluctuating around the minimum swimming depth if (inWater) - UpdateSwimming(); + { + inWaterTimer = Math.Max(inWaterTimer+deltaTime, 0.5f); + if (inWaterTimer >= 1.0f) swimming = true; + } else + { + inWaterTimer = Math.Min(inWaterTimer - deltaTime, 0.5f); + if (inWaterTimer <= 0.0f) swimming = false; + } + + if (swimming) + { + UpdateSwimming(); + } + else + { UpdateStanding(); + } break; } diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 9420c33de..c74734916 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -747,7 +747,7 @@ namespace Barotrauma } } //the limb has gone through the surface of the water - if (Math.Abs(limb.LinearVelocity.Y) > 5.0f && inWater != prevInWater) + if (Math.Abs(limb.LinearVelocity.Y) > 5.0f && limb.inWater != prevInWater) { //create a splash particle