Attempt to fix characters occasionally getting launched out of the sub at lightspeed when the sub crashes into something (even if the impact doesn't appear to be that hard): impacts don't increase the velocity of the characters above 20 units/s.

This commit is contained in:
Joonas Rikkonen
2018-04-18 17:24:10 +03:00
parent eed7b72b4e
commit c6f3d0c1b8
4 changed files with 43 additions and 16 deletions
@@ -218,12 +218,12 @@ namespace Barotrauma
if (displace) sub.SubBody.DisplaceCharacters(moveAmount);
}
if (closestSub != null && subsToMove.Contains(closestSub))
if (closestSub != null && subsToMove.Contains(closestSub))
{
GameMain.GameScreen.Cam.Position += moveAmount;
if (GameMain.GameScreen.Cam.TargetPos != Vector2.Zero) GameMain.GameScreen.Cam.TargetPos += moveAmount;
if (Character.Controlled!=null) Character.Controlled.CursorPosition += moveAmount;
if (GameMain.GameScreen.Cam.TargetPos != Vector2.Zero) GameMain.GameScreen.Cam.TargetPos += moveAmount;
if (Character.Controlled != null) Character.Controlled.CursorPosition += moveAmount;
}
return;
@@ -649,23 +649,18 @@ namespace Barotrauma
GameMain.GameScreen.Cam.Shake = impact * 2.0f;
}
Vector2 impulse = direction * impact * 0.5f;
float length = impulse.Length();
if (length > 5.0f) impulse = (impulse / length) * 5.0f;
Vector2 impulse = direction * impact * 0.5f;
impulse = impulse.ClampLength(5.0f);
foreach (Character c in Character.CharacterList)
{
if (c.Submarine != submarine) continue;
if (impact > 2.0f) c.SetStun((impact - 2.0f) * 0.1f);
foreach (Limb limb in c.AnimController.Limbs)
{
limb.body.ApplyLinearImpulse(limb.Mass * impulse);
limb.body.ApplyLinearImpulse(limb.Mass * impulse, 20.0f);
}
c.AnimController.Collider.ApplyLinearImpulse(c.AnimController.Collider.Mass * impulse);
c.AnimController.Collider.ApplyLinearImpulse(c.AnimController.Collider.Mass * impulse, 20.0f);
}
foreach (Item item in Item.ItemList)
@@ -673,7 +668,7 @@ namespace Barotrauma
if (item.Submarine != submarine || item.CurrentHull == null ||
item.body == null || !item.body.Enabled) continue;
item.body.ApplyLinearImpulse(item.body.Mass * impulse);
item.body.ApplyLinearImpulse(item.body.Mass * impulse, 20.0f);
}
var damagedStructures = Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits(lastContactPoint), impact * 50.0f, impact * ImpactDamageMultiplier);