Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Globalization;
using System.Xml.Linq;
using Barotrauma.Networking;
using FarseerPhysics.Dynamics;

namespace Barotrauma.Items.Components
{
Expand Down Expand Up @@ -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));
Expand Down
13 changes: 9 additions & 4 deletions Barotrauma/BarotraumaShared/SharedSource/Map/SubmarineBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public List<Vector2> 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;
Expand Down Expand Up @@ -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);
Expand Down