]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Mob pull spin fix (#37256)
authorPrincess Cheeseballs <66055347+Pronana@users.noreply.github.com>
Sat, 10 May 2025 04:18:33 +0000 (21:18 -0700)
committerGitHub <noreply@github.com>
Sat, 10 May 2025 04:18:33 +0000 (14:18 +1000)
Angular Friction applied to Kinematic Controllers

Content.Shared/Friction/TileFrictionController.cs
Content.Shared/Movement/Systems/SharedMoverController.cs

index cf9241bf2a489dfe2a2095947020397f4b16ee5b..159637a9e0c610137afcb522de3a988b572940c2 100644 (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!
                 // 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);
             }
         }
 
index d800234a6d126b56dfa6be355cf791d3f079ac75..cb0c776cfacb02317b596b8d122767ff8d0d88aa 100644 (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>
     /// Adjusts the current velocity to the target velocity based on the specified acceleration.
     /// </summary>