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

View File

@@ -171,7 +171,8 @@ namespace Barotrauma
}
}
for (int i = 0; i < waveY.Length; i++)
if (waterVolume < 1.0f) return;
for (int i = 1; i < waveY.Length - 1; i++)
{
float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i]));
if (maxDelta > Rand.Range(1.0f, 10.0f))

View File

@@ -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);

View File

@@ -370,6 +370,27 @@ namespace Barotrauma
body.ApplyLinearImpulse(impulse);
}
/// <summary>
/// Apply an impulse to the body without increasing it's velocity above a specific limit.
/// </summary>
public void ApplyLinearImpulse(Vector2 impulse, float maxVelocity)
{
float currSpeed = body.LinearVelocity.Length();
if (currSpeed > 100.0f)
{
int sdfgsdfg = 1;
}
Vector2 velocityAddition = impulse / Mass;
Vector2 newVelocity = body.LinearVelocity + velocityAddition;
newVelocity = newVelocity.ClampLength(Math.Max(currSpeed, maxVelocity));
body.ApplyLinearImpulse((newVelocity - body.LinearVelocity) * Mass);
}
public void ApplyLinearImpulse(Vector2 impulse, Vector2 point)
{
body.ApplyLinearImpulse(impulse, point);

View File

@@ -28,6 +28,16 @@ namespace Barotrauma
MathHelper.SmoothStep(v1.Y, v2.Y, amount));
}
public static Vector2 ClampLength(this Vector2 v, float length)
{
float currLength = v.Length();
if (v.Length() > length)
{
return v / currLength * length;
}
return v;
}
public static float Round(float value, float div)
{
return (value < 0.0f) ?