From f259f3fba4d33fba010f261e7322da3bbc468684 Mon Sep 17 00:00:00 2001 From: Regalis Date: Mon, 7 Nov 2016 18:52:36 +0200 Subject: [PATCH] Limiting character movement when collider isn't upright (can't run at full speed if lodged in some tight space), hack-ish way of moving the collider of a character that's being dragged --- .../Characters/Animation/FishAnimController.cs | 4 ++-- .../Animation/HumanoidAnimController.cs | 18 ++++++++++++++---- Subsurface/Source/Program.cs | 4 +--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Subsurface/Source/Characters/Animation/FishAnimController.cs b/Subsurface/Source/Characters/Animation/FishAnimController.cs index d5c0f1033..cb6a1c7ed 100644 --- a/Subsurface/Source/Characters/Animation/FishAnimController.cs +++ b/Subsurface/Source/Characters/Animation/FishAnimController.cs @@ -60,8 +60,8 @@ namespace Barotrauma } else { - collider.LinearVelocity = (GetLimb(LimbType.Torso).SimPosition - collider.SimPosition) * 60.0f; - collider.SmoothRotate(GetLimb(LimbType.Torso).Rotation); + collider.LinearVelocity = (MainLimb.SimPosition - collider.SimPosition) * 60.0f; + collider.SmoothRotate(MainLimb.Rotation); } if (stunTimer > 0) diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs index 86535f0b4..838c86aec 100644 --- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs @@ -66,7 +66,7 @@ namespace Barotrauma } else { - collider.LinearVelocity = (GetLimb(LimbType.Torso).SimPosition - collider.SimPosition) * 60.0f; + collider.LinearVelocity = (GetLimb(LimbType.Waist).SimPosition - collider.SimPosition) * 20.0f; collider.SmoothRotate(GetLimb(LimbType.Torso).Rotation); } @@ -307,8 +307,11 @@ namespace Barotrauma if (onGround && (!character.IsRemotePlayer || GameMain.Server != null)) { + //move slower if collider isn't upright + float rotationFactor = (float)Math.Abs(Math.Cos(collider.Rotation)); + collider.LinearVelocity = new Vector2( - movement.X, + movement.X * rotationFactor, collider.LinearVelocity.Y > 0.0f ? collider.LinearVelocity.Y * 0.5f : collider.LinearVelocity.Y); } @@ -899,15 +902,22 @@ namespace Barotrauma targetLimb.pullJoint.Enabled = true; targetLimb.pullJoint.WorldAnchorB = targetLimb.SimPosition - diff; targetLimb.pullJoint.MaxForce = 10000.0f; + + target.AnimController.movement -= diff; } } float dist = Vector2.Distance(target.SimPosition, collider.SimPosition); - targetMovement *= MathHelper.Clamp(1.5f - dist, 0.0f, 1.0f); + //limit movement if moving away from the target + if (Vector2.Dot(target.SimPosition - collider.SimPosition, targetMovement)<0) + { + targetMovement *= MathHelper.Clamp(2.0f - dist, 0.0f, 1.0f); + } + target.AnimController.IgnorePlatforms = IgnorePlatforms; - if (target.Stun > 0.0f || target.IsDead) + if (target.Stun > 0.0f || target.IsUnconscious || target.IsDead) { target.AnimController.TargetMovement = TargetMovement; } diff --git a/Subsurface/Source/Program.cs b/Subsurface/Source/Program.cs index 09448f029..ebda383c2 100644 --- a/Subsurface/Source/Program.cs +++ b/Subsurface/Source/Program.cs @@ -116,9 +116,7 @@ namespace Barotrauma { #if WINDOWS MessageBox.Show(message, "Oops! Barotrauma just crashed.", MessageBoxButtons.OK, MessageBoxIcon.Error); -#endif - - Sounds.SoundManager.Dispose(); +#endif } static void CrashDump(GameMain game, string filePath, Exception exception)