From e3cd479c29fdd8187d86c71a30ebe0440d69e90e 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 1/2] 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 1dac897cf7..8ddc9ff90b 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); From dad9d8e565713617421df4718fdaa0c761b8bc23 Mon Sep 17 00:00:00 2001 From: mygamingaccount <68995233+mygamingaccount@users.noreply.github.com> Date: Thu, 17 Oct 2024 00:13:47 +0200 Subject: [PATCH 2/2] Backwards compatible engine thrust for new drag formula A sub 10 times smaller used to need 10 times less thrust force to achieve the same speed. The new drag formula needs about 4.6 times more than that. This change in the thust-to-weight ratio means faster acceleration for drones and shuttles. Calculate this factor to prevent the top speed from changing in existing submarine designs. --- .../SharedSource/Items/Components/Machines/Engine.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Engine.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Engine.cs index e30cf5aed8..20b9138e3f 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Engine.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Engine.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Xml.Linq; using Barotrauma.Networking; +using FarseerPhysics.Dynamics; namespace Barotrauma.Items.Components { @@ -144,6 +145,12 @@ public override void Update(float deltaTime, Camera cam) UpdateAITargets(noise); //arbitrary multiplier that was added to changes in submarine mass without having to readjust all engines float forceMultiplier = 0.1f; + if (item.Submarine.SubBody.Body != null) + { + float mass = item.Submarine.SubBody.Body.Mass; + float newDragCorrectionFactor = MathF.Pow(mass / SubmarineBody.InertiaReferenceMass, SubmarineBody.MassToAreaExponent) * SubmarineBody.InertiaReferenceMass / mass; + forceMultiplier *= newDragCorrectionFactor; + } if (User != null) { forceMultiplier *= MathHelper.Lerp(0.5f, 2.0f, (float)Math.Sqrt(User.GetSkillLevel(Tags.HelmSkill) / 100));