From a1ef2732c976af951c0001e5e281f43391e41c31 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 26 Mar 2019 17:09:08 +0200 Subject: [PATCH] (0d12b23e4) Fix the crash due to NaN value in torso or head angle (#1349). --- .../Animation/FishAnimController.cs | 27 ++++++++++++++++++- .../Source/Characters/Animation/Ragdoll.cs | 2 -- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs index ce2078c17..9be72b20f 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs @@ -369,7 +369,16 @@ namespace Barotrauma float movementAngle = MathUtils.VectorToAngle(movement) - MathHelper.PiOver2; - float mainLimbAngle = (MainLimb.type == LimbType.Torso ? TorsoAngle.Value : HeadAngle.Value) * Dir; + float mainLimbAngle = 0; + if (MainLimb.type == LimbType.Torso && TorsoAngle.HasValue) + { + mainLimbAngle = TorsoAngle.Value; + } + else if (MainLimb.type == LimbType.Head && HeadAngle.HasValue) + { + mainLimbAngle = HeadAngle.Value; + } + mainLimbAngle *= Dir; while (MainLimb.Rotation - (movementAngle + mainLimbAngle) > MathHelper.Pi) { movementAngle += MathHelper.TwoPi; @@ -701,6 +710,22 @@ namespace Barotrauma limb?.body.SmoothRotate(angle, torque, wrapAngle: false); } + private void SmoothRotateWithoutWrapping(Limb limb, float angle, Limb referenceLimb, float torque) + { + //make sure the angle "has the same number of revolutions" as the reference limb + //(e.g. we don't want to rotate the legs to 0 if the torso is at 360, because that'd blow up the hip joints) + while (referenceLimb.Rotation - angle > MathHelper.TwoPi) + { + angle += MathHelper.TwoPi; + } + while (referenceLimb.Rotation - angle < -MathHelper.TwoPi) + { + angle -= MathHelper.TwoPi; + } + + limb?.body.SmoothRotate(angle, torque, wrapAngle: false); + } + public override void Flip() { base.Flip(); diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs index 669cce537..82467a761 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs @@ -1035,8 +1035,6 @@ namespace Barotrauma CheckValidity(); - CheckValidity(); - UpdateNetPlayerPosition(deltaTime); CheckDistFromCollider(); UpdateCollisionCategories();