Physics error checks & logging
This commit is contained in:
@@ -480,9 +480,7 @@ namespace Barotrauma
|
|||||||
Vector2 avgContactNormal = Vector2.Zero;
|
Vector2 avgContactNormal = Vector2.Zero;
|
||||||
foreach (Contact levelContact in levelContacts)
|
foreach (Contact levelContact in levelContacts)
|
||||||
{
|
{
|
||||||
Vector2 contactNormal;
|
levelContact.GetWorldManifold(out Vector2 contactNormal, out FixedArray2<Vector2> temp);
|
||||||
FixedArray2<Vector2> temp;
|
|
||||||
levelContact.GetWorldManifold(out contactNormal, out temp);
|
|
||||||
|
|
||||||
//if the contact normal is pointing from the limb towards the level cell it's touching, flip the normal
|
//if the contact normal is pointing from the limb towards the level cell it's touching, flip the normal
|
||||||
VoronoiCell cell = levelContact.FixtureB.UserData is VoronoiCell ?
|
VoronoiCell cell = levelContact.FixtureB.UserData is VoronoiCell ?
|
||||||
@@ -504,7 +502,21 @@ namespace Barotrauma
|
|||||||
float contactDot = Vector2.Dot(Body.LinearVelocity, -avgContactNormal);
|
float contactDot = Vector2.Dot(Body.LinearVelocity, -avgContactNormal);
|
||||||
if (contactDot > 0.0f)
|
if (contactDot > 0.0f)
|
||||||
{
|
{
|
||||||
Body.LinearVelocity -= Vector2.Normalize(Body.LinearVelocity) * contactDot;
|
Vector2 velChange = Vector2.Normalize(Body.LinearVelocity) * contactDot;
|
||||||
|
if (!MathUtils.IsValid(velChange))
|
||||||
|
{
|
||||||
|
GameAnalyticsManager.AddErrorEventOnce(
|
||||||
|
"SubmarineBody.HandleLimbCollision:" + submarine.ID,
|
||||||
|
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
|
||||||
|
"Invalid velocity change in SubmarineBody.HandleLimbCollision (submarine velocity: " + Body.LinearVelocity
|
||||||
|
+ ", avgContactNormal: " + avgContactNormal
|
||||||
|
+ ", contactDot: " + contactDot
|
||||||
|
+ ", velChange: " + velChange + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Body.LinearVelocity -= velChange;
|
||||||
|
|
||||||
float damageAmount = contactDot * Body.Mass / limb.character.Mass;
|
float damageAmount = contactDot * Body.Mass / limb.character.Mass;
|
||||||
|
|
||||||
|
|||||||
@@ -184,11 +184,16 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Exception in PhysicsBody.Enabled = "+value+" ("+isPhysEnabled+")",e);
|
DebugConsole.ThrowError("Exception in PhysicsBody.Enabled = " + value + " (" + isPhysEnabled + ")", e);
|
||||||
if (UserData!=null) DebugConsole.NewMessage("PhysicsBody UserData: "+UserData.GetType().ToString(), Color.Red);
|
if (UserData != null) DebugConsole.NewMessage("PhysicsBody UserData: " + UserData.GetType().ToString(), Color.Red);
|
||||||
if (GameMain.World.ContactManager == null) DebugConsole.NewMessage("ContactManager is null!", Color.Red);
|
if (GameMain.World.ContactManager == null) DebugConsole.NewMessage("ContactManager is null!", Color.Red);
|
||||||
else if (GameMain.World.ContactManager.BroadPhase == null) DebugConsole.NewMessage("Broadphase is null!", Color.Red);
|
else if (GameMain.World.ContactManager.BroadPhase == null) DebugConsole.NewMessage("Broadphase is null!", Color.Red);
|
||||||
if (body.FixtureList == null) DebugConsole.NewMessage("FixtureList is null!", Color.Red);
|
if (body.FixtureList == null) DebugConsole.NewMessage("FixtureList is null!", Color.Red);
|
||||||
|
|
||||||
|
if (UserData is Entity entity)
|
||||||
|
{
|
||||||
|
DebugConsole.NewMessage("Entity \"" + entity.ToString() + "\" removed!", Color.Red);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user