From 5dbd40c9dd6ce1fb9323d7ab6720e83ee2a08a90 Mon Sep 17 00:00:00 2001 From: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com> Date: Fri, 9 May 2025 21:18:33 -0700 Subject: [PATCH] Mob pull spin fix (#37256) Angular Friction applied to Kinematic Controllers --- Content.Shared/Friction/TileFrictionController.cs | 3 +++ .../Movement/Systems/SharedMoverController.cs | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/Content.Shared/Friction/TileFrictionController.cs b/Content.Shared/Friction/TileFrictionController.cs index cf9241bf2a..159637a9e0 100644 --- a/Content.Shared/Friction/TileFrictionController.cs +++ b/Content.Shared/Friction/TileFrictionController.cs @@ -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! // But doing so is unpredicted! And you will doom yourself to 1000 years of rubber banding! var velocity = body.LinearVelocity; + var angVelocity = body.AngularVelocity; _mover.Friction(0f, frameTime, friction, ref velocity); + _mover.Friction(0f, frameTime, friction, ref angVelocity); PhysicsSystem.SetLinearVelocity(uid, velocity, body: body); + PhysicsSystem.SetAngularVelocity(uid, angVelocity, body: body); } } diff --git a/Content.Shared/Movement/Systems/SharedMoverController.cs b/Content.Shared/Movement/Systems/SharedMoverController.cs index d800234a6d..cb0c776cfa 100644 --- a/Content.Shared/Movement/Systems/SharedMoverController.cs +++ b/Content.Shared/Movement/Systems/SharedMoverController.cs @@ -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); + + } + /// /// Adjusts the current velocity to the target velocity based on the specified acceleration. ///