WIP fixes to ragdoll simple physics mode (see #895). When simple physics is enabled, only the collider of the character moves and all the limbs and joints are disabled. This caused "attempted to move pulljoint anchor extremely far" errors, because the game still attempted to move the limbs to the collider via pull joints. TODO: do more testing to make sure simple physics doesn't cause other physics errors, fix dragging in simple physics mode.
This commit is contained in:
@@ -59,8 +59,11 @@ namespace Barotrauma
|
||||
|
||||
if (character.IsRemotePlayer)
|
||||
{
|
||||
MainLimb.PullJointWorldAnchorB = Collider.SimPosition;
|
||||
MainLimb.PullJointEnabled = true;
|
||||
if (!SimplePhysicsEnabled)
|
||||
{
|
||||
MainLimb.PullJointWorldAnchorB = Collider.SimPosition;
|
||||
MainLimb.PullJointEnabled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -127,6 +130,9 @@ namespace Barotrauma
|
||||
|
||||
UpdateWalkAnim(deltaTime);
|
||||
}
|
||||
|
||||
//don't flip or drag when simply physics is enabled
|
||||
if (SimplePhysicsEnabled) { return; }
|
||||
|
||||
if (!character.IsRemotePlayer)
|
||||
{
|
||||
@@ -254,13 +260,19 @@ namespace Barotrauma
|
||||
|
||||
void UpdateSineAnim(float deltaTime)
|
||||
{
|
||||
movement = TargetMovement*swimSpeed;
|
||||
|
||||
movement = TargetMovement * swimSpeed;
|
||||
|
||||
Collider.LinearVelocity = Vector2.Lerp(Collider.LinearVelocity, movement, 0.5f);
|
||||
|
||||
//limbs are disabled when simple physics is enabled, no need to move them
|
||||
if (SimplePhysicsEnabled) { return; }
|
||||
|
||||
MainLimb.PullJointEnabled = true;
|
||||
MainLimb.PullJointWorldAnchorB = Collider.SimPosition;
|
||||
|
||||
if (movement.LengthSquared() < 0.00001f) return;
|
||||
|
||||
|
||||
float movementAngle = MathUtils.VectorToAngle(movement) - MathHelper.PiOver2;
|
||||
|
||||
if (rotateTowardsMovement)
|
||||
@@ -292,16 +304,21 @@ namespace Barotrauma
|
||||
Vector2 pullPos = Limbs[i].PullJointWorldAnchorA;
|
||||
Limbs[i].body.ApplyForce(movement * Limbs[i].SteerForce * Limbs[i].Mass, pullPos);
|
||||
}
|
||||
|
||||
Collider.LinearVelocity = Vector2.Lerp(Collider.LinearVelocity, movement, 0.5f);
|
||||
|
||||
|
||||
floorY = Limbs[0].SimPosition.Y;
|
||||
}
|
||||
|
||||
void UpdateWalkAnim(float deltaTime)
|
||||
{
|
||||
movement = MathUtils.SmoothStep(movement, TargetMovement * walkSpeed, 0.2f);
|
||||
|
||||
|
||||
Collider.LinearVelocity = new Vector2(
|
||||
movement.X,
|
||||
Collider.LinearVelocity.Y > 0.0f ? Collider.LinearVelocity.Y * 0.5f : Collider.LinearVelocity.Y);
|
||||
|
||||
//limbs are disabled when simple physics is enabled, no need to move them
|
||||
if (SimplePhysicsEnabled) { return; }
|
||||
|
||||
float mainLimbHeight, mainLimbAngle;
|
||||
if (MainLimb.type == LimbType.Torso)
|
||||
{
|
||||
@@ -314,11 +331,7 @@ namespace Barotrauma
|
||||
mainLimbAngle = headAngle;
|
||||
}
|
||||
|
||||
MainLimb.body.SmoothRotate(mainLimbAngle * Dir, 50.0f);
|
||||
|
||||
Collider.LinearVelocity = new Vector2(
|
||||
movement.X,
|
||||
Collider.LinearVelocity.Y > 0.0f ? Collider.LinearVelocity.Y * 0.5f : Collider.LinearVelocity.Y);
|
||||
MainLimb.body.SmoothRotate(mainLimbAngle * Dir, 50.0f);
|
||||
|
||||
MainLimb.MoveToPos(GetColliderBottom() + Vector2.UnitY * mainLimbHeight, 10.0f);
|
||||
|
||||
|
||||
@@ -516,17 +516,30 @@ namespace Barotrauma
|
||||
|
||||
void UpdateStandingSimple()
|
||||
{
|
||||
movement = MathUtils.SmoothStep(movement, TargetMovement, movementLerp);
|
||||
|
||||
if (inWater && movement.LengthSquared() > 0.00001f)
|
||||
{
|
||||
movement = Vector2.Normalize(movement);
|
||||
}
|
||||
|
||||
if (Math.Abs(movement.X)<0.005f)
|
||||
if (Math.Abs(movement.X) < 0.005f)
|
||||
{
|
||||
movement.X = 0.0f;
|
||||
}
|
||||
|
||||
if (InWater)
|
||||
{
|
||||
if (inWater && movement.LengthSquared() > 0.00001f)
|
||||
{
|
||||
movement = Vector2.Normalize(movement);
|
||||
}
|
||||
movement = MathUtils.SmoothStep(movement, TargetMovement, movementLerp);
|
||||
Collider.LinearVelocity = Vector2.Lerp(Collider.LinearVelocity, movement * swimSpeed, movementLerp);
|
||||
}
|
||||
else
|
||||
{
|
||||
movement = MathUtils.SmoothStep(movement, TargetMovement * walkSpeed, movementLerp);
|
||||
if (onGround && (!character.IsRemotePlayer || GameMain.Server != null))
|
||||
{
|
||||
Collider.LinearVelocity = new Vector2(
|
||||
movement.X,
|
||||
Collider.LinearVelocity.Y > 0.0f ? Collider.LinearVelocity.Y * 0.5f : Collider.LinearVelocity.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClimbOverObstacles()
|
||||
|
||||
@@ -715,7 +715,7 @@ namespace Barotrauma
|
||||
float totalMass = 0.0f;
|
||||
foreach (Limb limb in Limbs)
|
||||
{
|
||||
if (limb.IsSevered) continue;
|
||||
if (limb.IsSevered || !limb.body.Enabled) continue;
|
||||
centerOfMass += limb.Mass * limb.SimPosition;
|
||||
totalMass += limb.Mass;
|
||||
}
|
||||
|
||||
@@ -176,9 +176,14 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (Vector2.DistanceSquared(pullJoint.WorldAnchorA, value) > 50.0f * 50.0f)
|
||||
{
|
||||
string errorMsg = "Attempted to move the anchor of a limb's pull joint extremely far from the limb (" + value + ")\n" + Environment.StackTrace;
|
||||
Vector2 diff = value - pullJoint.WorldAnchorA;
|
||||
string errorMsg = "Attempted to move the anchor of a limb's pull joint extremely far from the limb (diff: " + diff +
|
||||
", limb enabled: " + body.Enabled +
|
||||
", simple physics enabled: " + character.AnimController.SimplePhysicsEnabled + ")\n"
|
||||
+ Environment.StackTrace;
|
||||
DebugConsole.ThrowError(errorMsg);
|
||||
GameAnalyticsManager.AddErrorEventOnce("Limb.SetPullJointAnchor:ExcessiveValue", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user