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:
@@ -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]));
|
float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i]));
|
||||||
if (maxDelta > Rand.Range(1.0f, 10.0f))
|
if (maxDelta > Rand.Range(1.0f, 10.0f))
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ namespace Barotrauma
|
|||||||
GameMain.GameScreen.Cam.Position += moveAmount;
|
GameMain.GameScreen.Cam.Position += moveAmount;
|
||||||
if (GameMain.GameScreen.Cam.TargetPos != Vector2.Zero) GameMain.GameScreen.Cam.TargetPos += moveAmount;
|
if (GameMain.GameScreen.Cam.TargetPos != Vector2.Zero) GameMain.GameScreen.Cam.TargetPos += moveAmount;
|
||||||
|
|
||||||
if (Character.Controlled!=null) Character.Controlled.CursorPosition += moveAmount;
|
if (Character.Controlled != null) Character.Controlled.CursorPosition += moveAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -650,22 +650,17 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector2 impulse = direction * impact * 0.5f;
|
Vector2 impulse = direction * impact * 0.5f;
|
||||||
|
impulse = impulse.ClampLength(5.0f);
|
||||||
float length = impulse.Length();
|
|
||||||
if (length > 5.0f) impulse = (impulse / length) * 5.0f;
|
|
||||||
|
|
||||||
foreach (Character c in Character.CharacterList)
|
foreach (Character c in Character.CharacterList)
|
||||||
{
|
{
|
||||||
if (c.Submarine != submarine) continue;
|
if (c.Submarine != submarine) continue;
|
||||||
|
|
||||||
if (impact > 2.0f) c.SetStun((impact - 2.0f) * 0.1f);
|
if (impact > 2.0f) c.SetStun((impact - 2.0f) * 0.1f);
|
||||||
|
|
||||||
foreach (Limb limb in c.AnimController.Limbs)
|
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, 20.0f);
|
||||||
c.AnimController.Collider.ApplyLinearImpulse(c.AnimController.Collider.Mass * impulse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Item item in Item.ItemList)
|
foreach (Item item in Item.ItemList)
|
||||||
@@ -673,7 +668,7 @@ namespace Barotrauma
|
|||||||
if (item.Submarine != submarine || item.CurrentHull == null ||
|
if (item.Submarine != submarine || item.CurrentHull == null ||
|
||||||
item.body == null || !item.body.Enabled) continue;
|
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);
|
var damagedStructures = Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits(lastContactPoint), impact * 50.0f, impact * ImpactDamageMultiplier);
|
||||||
|
|||||||
@@ -370,6 +370,27 @@ namespace Barotrauma
|
|||||||
body.ApplyLinearImpulse(impulse);
|
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)
|
public void ApplyLinearImpulse(Vector2 impulse, Vector2 point)
|
||||||
{
|
{
|
||||||
body.ApplyLinearImpulse(impulse, point);
|
body.ApplyLinearImpulse(impulse, point);
|
||||||
|
|||||||
@@ -28,6 +28,16 @@ namespace Barotrauma
|
|||||||
MathHelper.SmoothStep(v1.Y, v2.Y, amount));
|
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)
|
public static float Round(float value, float div)
|
||||||
{
|
{
|
||||||
return (value < 0.0f) ?
|
return (value < 0.0f) ?
|
||||||
|
|||||||
Reference in New Issue
Block a user