From 089b0dbcee2990f44b535f6af7f780dba5cf3cb3 Mon Sep 17 00:00:00 2001 From: Regalis Date: Thu, 17 Nov 2016 19:16:30 +0200 Subject: [PATCH] Water slows down players based on the depth of the water relative to the bottom of the collider --- .../Characters/Animation/HumanoidAnimController.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs index a2c04379f..4da8aa2e3 100644 --- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs @@ -256,17 +256,15 @@ namespace Barotrauma Vector2 colliderPos = GetColliderBottom(); if (Math.Abs(TargetMovement.X) > 1.0f) { - int limbsInWater = 0; - foreach (Limb limb in Limbs) + float slowdownAmount = 0.0f; + if (currentHull != null) { - if (limb.inWater) limbsInWater++; + //full slowdown (1.0f) when water is up to the torso + surfaceY = ConvertUnits.ToSimUnits(currentHull.Surface); + slowdownAmount = MathHelper.Clamp((surfaceY - colliderPos.Y) / torsoPosition, 0.0f, 1.0f); } - float slowdownFactor = (float)limbsInWater / (float)Limbs.Length; - - float maxSpeed = Math.Max(TargetMovement.Length() - slowdownFactor, 1.0f); - // if (character.SelectedCharacter!=null) maxSpeed = Math.Min(maxSpeed, 1.0f); - + float maxSpeed = Math.Max(TargetMovement.Length() - slowdownAmount, 1.0f); TargetMovement = Vector2.Normalize(TargetMovement) * maxSpeed; }