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

View File

@@ -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;
}

View File

@@ -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