diff --git a/Barotrauma/BarotraumaClient/Source/Map/Hull.cs b/Barotrauma/BarotraumaClient/Source/Map/Hull.cs index 2ac04fce4..332adb1a3 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Hull.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Hull.cs @@ -171,7 +171,8 @@ namespace Barotrauma } } - for (int i = 0; i < waveY.Length; i++) + if (waterVolume < 1.0f) return; + for (int i = 1; i < waveY.Length - 1; i++) { float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i])); if (maxDelta > Rand.Range(1.0f, 10.0f)) diff --git a/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs b/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs index 5b8aa1f5d..6d623c73c 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs @@ -218,12 +218,12 @@ namespace Barotrauma if (displace) sub.SubBody.DisplaceCharacters(moveAmount); } - if (closestSub != null && subsToMove.Contains(closestSub)) + if (closestSub != null && subsToMove.Contains(closestSub)) { GameMain.GameScreen.Cam.Position += moveAmount; - if (GameMain.GameScreen.Cam.TargetPos != Vector2.Zero) GameMain.GameScreen.Cam.TargetPos += moveAmount; - - if (Character.Controlled!=null) Character.Controlled.CursorPosition += moveAmount; + if (GameMain.GameScreen.Cam.TargetPos != Vector2.Zero) GameMain.GameScreen.Cam.TargetPos += moveAmount; + + if (Character.Controlled != null) Character.Controlled.CursorPosition += moveAmount; } return; @@ -649,23 +649,18 @@ namespace Barotrauma GameMain.GameScreen.Cam.Shake = impact * 2.0f; } - Vector2 impulse = direction * impact * 0.5f; - - float length = impulse.Length(); - if (length > 5.0f) impulse = (impulse / length) * 5.0f; - + Vector2 impulse = direction * impact * 0.5f; + impulse = impulse.ClampLength(5.0f); foreach (Character c in Character.CharacterList) { if (c.Submarine != submarine) continue; - if (impact > 2.0f) c.SetStun((impact - 2.0f) * 0.1f); - + foreach (Limb limb in c.AnimController.Limbs) { - limb.body.ApplyLinearImpulse(limb.Mass * impulse); + limb.body.ApplyLinearImpulse(limb.Mass * impulse, 20.0f); } - - c.AnimController.Collider.ApplyLinearImpulse(c.AnimController.Collider.Mass * impulse); + c.AnimController.Collider.ApplyLinearImpulse(c.AnimController.Collider.Mass * impulse, 20.0f); } foreach (Item item in Item.ItemList) @@ -673,7 +668,7 @@ namespace Barotrauma if (item.Submarine != submarine || item.CurrentHull == null || item.body == null || !item.body.Enabled) continue; - item.body.ApplyLinearImpulse(item.body.Mass * impulse); + item.body.ApplyLinearImpulse(item.body.Mass * impulse, 20.0f); } var damagedStructures = Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits(lastContactPoint), impact * 50.0f, impact * ImpactDamageMultiplier); diff --git a/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs b/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs index 4d8994300..57668ac85 100644 --- a/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs +++ b/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs @@ -370,6 +370,27 @@ namespace Barotrauma body.ApplyLinearImpulse(impulse); } + /// + /// Apply an impulse to the body without increasing it's velocity above a specific limit. + /// + public void ApplyLinearImpulse(Vector2 impulse, float maxVelocity) + { + + float currSpeed = body.LinearVelocity.Length(); + if (currSpeed > 100.0f) + { + int sdfgsdfg = 1; + } + + + Vector2 velocityAddition = impulse / Mass; + + Vector2 newVelocity = body.LinearVelocity + velocityAddition; + newVelocity = newVelocity.ClampLength(Math.Max(currSpeed, maxVelocity)); + + body.ApplyLinearImpulse((newVelocity - body.LinearVelocity) * Mass); + } + public void ApplyLinearImpulse(Vector2 impulse, Vector2 point) { body.ApplyLinearImpulse(impulse, point); diff --git a/Barotrauma/BarotraumaShared/Source/Utils/MathUtils.cs b/Barotrauma/BarotraumaShared/Source/Utils/MathUtils.cs index 1a3e4c308..d754fdfea 100644 --- a/Barotrauma/BarotraumaShared/Source/Utils/MathUtils.cs +++ b/Barotrauma/BarotraumaShared/Source/Utils/MathUtils.cs @@ -28,6 +28,16 @@ namespace Barotrauma MathHelper.SmoothStep(v1.Y, v2.Y, amount)); } + public static Vector2 ClampLength(this Vector2 v, float length) + { + float currLength = v.Length(); + if (v.Length() > length) + { + return v / currLength * length; + } + return v; + } + public static float Round(float value, float div) { return (value < 0.0f) ?