Skip to content

Commit

Permalink
Modify drag to allow for better shuttle handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mygamingaccount committed Oct 16, 2024
1 parent 0e8fb65 commit b7cdd42
Showing 1 changed file with 9 additions and 4 deletions.
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

0 comments on commit b7cdd42

Please sign in to comment.