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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user