From b7cdd42736b590ad05b9ea8a1402d28bb98bbe17 Mon Sep 17 00:00:00 2001 From: mygamingaccount <68995233+mygamingaccount@users.noreply.github.com> Date: Thu, 17 Oct 2024 00:08:51 +0200 Subject: [PATCH] Modify drag to allow for better shuttle handling Calculate drag using mass^(2/3), thereby increasing drag for small vessels, and reducing drag for larger ones. With a matching increase or decrease in engine thrust to keep the same top speed, this will result in more maneuverable shuttles, and more sluggish capital ships. --- .../SharedSource/Map/SubmarineBody.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Map/SubmarineBody.cs b/Barotrauma/BarotraumaShared/SharedSource/Map/SubmarineBody.cs index 030941e517..8866256a82 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Map/SubmarineBody.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Map/SubmarineBody.cs @@ -61,6 +61,10 @@ public List HullVertices private float forceUpwardsTimer; private const float ForceUpwardsDelay = 30.0f; + // submarines greater than "InertialReferenceMass" will accelerate slower, and vica versa. 30000 is about the size of the Humpback. + public const float InertiaReferenceMass = 30000f; + public const float MassToAreaExponent = 2f/3f; + struct Impact { public Fixture Target; @@ -449,12 +453,13 @@ contactEdge.Other.UserData is Submarine otherSubmarine && jointEdge = jointEdge.Next; } - + float surfaceArea = MathF.Pow(Body.Mass / InertiaReferenceMass, MassToAreaExponent) * InertiaReferenceMass; + float horizontalDragCoefficient = MathHelper.Clamp(HorizontalDrag + attachedMass / 5000.0f, 0.0f, MaxDrag); - totalForce.X -= Math.Sign(Body.LinearVelocity.X) * Body.LinearVelocity.X * Body.LinearVelocity.X * horizontalDragCoefficient * Body.Mass; - + totalForce.X -= Math.Sign(Body.LinearVelocity.X) * Body.LinearVelocity.X * Body.LinearVelocity.X * horizontalDragCoefficient * surfaceArea; + float verticalDragCoefficient = MathHelper.Clamp(VerticalDrag + attachedMass / 5000.0f, 0.0f, MaxDrag); - totalForce.Y -= Math.Sign(Body.LinearVelocity.Y) * Body.LinearVelocity.Y * Body.LinearVelocity.Y * verticalDragCoefficient * Body.Mass; + totalForce.Y -= Math.Sign(Body.LinearVelocity.Y) * Body.LinearVelocity.Y * Body.LinearVelocity.Y * verticalDragCoefficient * surfaceArea; } ApplyForce(totalForce);