Mob pull spin fix (#37256)

Angular Friction applied to Kinematic Controllers
This commit is contained in:
Princess Cheeseballs
2025-05-09 21:18:33 -07:00
committed by GitHub
parent 6d65039f3c
commit 5dbd40c9dd
2 changed files with 14 additions and 0 deletions

View File

@@ -118,8 +118,11 @@ namespace Content.Shared.Friction
// You may think you can just pass the body.LinearVelocity to the Friction function and edit it there! // You may think you can just pass the body.LinearVelocity to the Friction function and edit it there!
// But doing so is unpredicted! And you will doom yourself to 1000 years of rubber banding! // But doing so is unpredicted! And you will doom yourself to 1000 years of rubber banding!
var velocity = body.LinearVelocity; var velocity = body.LinearVelocity;
var angVelocity = body.AngularVelocity;
_mover.Friction(0f, frameTime, friction, ref velocity); _mover.Friction(0f, frameTime, friction, ref velocity);
_mover.Friction(0f, frameTime, friction, ref angVelocity);
PhysicsSystem.SetLinearVelocity(uid, velocity, body: body); PhysicsSystem.SetLinearVelocity(uid, velocity, body: body);
PhysicsSystem.SetAngularVelocity(uid, angVelocity, body: body);
} }
} }

View File

@@ -412,6 +412,17 @@ public abstract partial class SharedMoverController : VirtualController
} }
public void Friction(float minimumFrictionSpeed, float frameTime, float friction, ref float velocity)
{
if (velocity < minimumFrictionSpeed)
return;
// This equation is lifted from the Physics Island solver.
// We re-use it here because Kinematic Controllers can't/shouldn't use the Physics Friction
velocity *= Math.Clamp(1.0f - frameTime * friction, 0.0f, 1.0f);
}
/// <summary> /// <summary>
/// Adjusts the current velocity to the target velocity based on the specified acceleration. /// Adjusts the current velocity to the target velocity based on the specified acceleration.
/// </summary> /// </summary>