]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Use velocity along normal for shuttle impacts (#37667)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Wed, 21 May 2025 13:32:46 +0000 (23:32 +1000)
committerGitHub <noreply@github.com>
Wed, 21 May 2025 13:32:46 +0000 (23:32 +1000)
* Use velocity along normal for shuttle impacts

Scrapes shouldn't have the same level of destruction as full-on ramming anymore. Also detecting scrapes should be a lot easier for future stuff.

* Update Content.Server/Shuttles/Systems/ShuttleSystem.Impact.cs

Content.Server/Shuttles/Systems/ShuttleSystem.Impact.cs

index 771103711a21ab9f6c8af210b9bde1230fa26d81..f165990f1cacc0b0516d80cf271c8b33d5a6ea4c 100644 (file)
@@ -107,6 +107,7 @@ public sealed partial class ShuttleSystem
         var ourXform = Transform(args.OurEntity);
         var otherXform = Transform(args.OtherEntity);
         var worldPoints = args.WorldPoints;
+        var worldNormal = args.WorldNormal;
 
         for (var i = 0; i < worldPoints.Length; i++)
         {
@@ -117,7 +118,14 @@ public sealed partial class ShuttleSystem
 
             var ourVelocity = _physics.GetLinearVelocity(args.OurEntity, ourPoint.Position, ourBody, ourXform);
             var otherVelocity = _physics.GetLinearVelocity(args.OtherEntity, otherPoint.Position, otherBody, otherXform);
-            var jungleDiff = (ourVelocity - otherVelocity).Length();
+            var topDiff = (ourVelocity - otherVelocity);
+            var jungleDiff = topDiff.Length();
+
+            // Get the velocity in relation to the contact normal
+            // If this still causes issues see https://box2d.org/posts/2020/06/ghost-collisions/
+            // This should only be a potential problem on chunk seams.
+            var dotProduct = MathF.Abs(Vector2.Dot(topDiff.Normalized(), worldNormal.Normalized()));
+            jungleDiff *= dotProduct;
 
             // this is cursed but makes it so that collisions of small grid with large grid count the inertia as being approximately the small grid's
             var effectiveInertiaMult = (ourBody.FixturesMass * otherBody.FixturesMass) / (ourBody.FixturesMass + otherBody.FixturesMass);