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)

This commit is contained in:
Regalis
2016-09-21 20:14:24 +03:00
parent eaf6e25b0e
commit f21000124b
2 changed files with 24 additions and 4 deletions
@@ -21,6 +21,9 @@ namespace Barotrauma
private float cprAnimState; private float cprAnimState;
private float inWaterTimer;
private bool swimming;
protected override float HeadPosition protected override float HeadPosition
{ {
get get
@@ -221,10 +224,27 @@ namespace Barotrauma
if (character.SelectedCharacter != null) DragCharacter(character.SelectedCharacter); 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) if (inWater)
UpdateSwimming(); {
inWaterTimer = Math.Max(inWaterTimer+deltaTime, 0.5f);
if (inWaterTimer >= 1.0f) swimming = true;
}
else else
{
inWaterTimer = Math.Min(inWaterTimer - deltaTime, 0.5f);
if (inWaterTimer <= 0.0f) swimming = false;
}
if (swimming)
{
UpdateSwimming();
}
else
{
UpdateStanding(); UpdateStanding();
}
break; break;
} }
@@ -747,7 +747,7 @@ namespace Barotrauma
} }
} }
//the limb has gone through the surface of the water //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 //create a splash particle