When a submarine collides with something, impacts are also applied to docked subs
This commit is contained in:
@@ -378,9 +378,13 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
Vector2 normal = Vector2.Normalize(Body.SimPosition - limb.SimPosition);
|
Vector2 normal = Vector2.Normalize(Body.SimPosition - limb.SimPosition);
|
||||||
|
|
||||||
float impact = Math.Min(Vector2.Dot(Velocity - limb.LinearVelocity, -normal), 50.0f) / 5.0f;
|
float impact = Math.Min(Vector2.Dot(Velocity - limb.LinearVelocity, -normal), 50.0f) / 5.0f * Math.Min(limb.Mass / 200.0f, 1);
|
||||||
|
|
||||||
ApplyImpact(impact * Math.Min(limb.Mass / 200.0f, 1), -normal, contact);
|
ApplyImpact(impact, -normal, contact);
|
||||||
|
foreach (Submarine dockedSub in submarine.DockedTo)
|
||||||
|
{
|
||||||
|
dockedSub.SubBody.ApplyImpact(impact, -normal, contact);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return collision;
|
return collision;
|
||||||
@@ -394,6 +398,10 @@ namespace Barotrauma
|
|||||||
float wallImpact = Vector2.Dot(Velocity, -collisionNormal);
|
float wallImpact = Vector2.Dot(Velocity, -collisionNormal);
|
||||||
|
|
||||||
ApplyImpact(wallImpact, -collisionNormal, contact);
|
ApplyImpact(wallImpact, -collisionNormal, contact);
|
||||||
|
foreach (Submarine dockedSub in submarine.DockedTo)
|
||||||
|
{
|
||||||
|
dockedSub.SubBody.ApplyImpact(wallImpact, -collisionNormal, contact);
|
||||||
|
}
|
||||||
|
|
||||||
Vector2 n;
|
Vector2 n;
|
||||||
FixedArray2<Vector2> particlePos;
|
FixedArray2<Vector2> particlePos;
|
||||||
@@ -412,22 +420,31 @@ namespace Barotrauma
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Submarine sub = f2.Body.UserData as Submarine;
|
Submarine otherSub = f2.Body.UserData as Submarine;
|
||||||
if (sub != null)
|
if (otherSub != null)
|
||||||
{
|
{
|
||||||
Debug.Assert(sub != submarine);
|
Debug.Assert(otherSub != submarine);
|
||||||
|
|
||||||
Vector2 normal;
|
Vector2 normal;
|
||||||
FixedArray2<Vector2> points;
|
FixedArray2<Vector2> points;
|
||||||
contact.GetWorldManifold(out normal, out points);
|
contact.GetWorldManifold(out normal, out points);
|
||||||
if (contact.FixtureA.Body == sub.SubBody.Body.FarseerBody)
|
if (contact.FixtureA.Body == otherSub.SubBody.Body.FarseerBody)
|
||||||
{
|
{
|
||||||
normal = -normal;
|
normal = -normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
float massRatio = sub.SubBody.Body.Mass / (sub.SubBody.Body.Mass + Body.Mass);
|
float thisMass = Body.Mass + submarine.DockedTo.Sum(s => s.PhysicsBody.Mass);
|
||||||
|
float otherMass = otherSub.PhysicsBody.Mass + otherSub.DockedTo.Sum(s => s.PhysicsBody.Mass);
|
||||||
|
|
||||||
ApplyImpact((Vector2.Dot(Velocity - sub.Velocity, normal) / 2.0f)*massRatio, normal, contact);
|
float massRatio = otherMass / (thisMass + otherMass);
|
||||||
|
|
||||||
|
float impact = (Vector2.Dot(Velocity - otherSub.Velocity, normal) / 2.0f) * massRatio;
|
||||||
|
|
||||||
|
ApplyImpact(impact, normal, contact);
|
||||||
|
foreach (Submarine dockedSub in submarine.DockedTo)
|
||||||
|
{
|
||||||
|
dockedSub.SubBody.ApplyImpact(impact, normal, contact);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user