Use velocity along normal for shuttle impacts (#37667)

* 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
This commit is contained in:
metalgearsloth 2025-05-21 23:32:46 +10:00 committed by deltanedas
parent 4bcd2c1f95
commit 8501c94855
1 changed files with 9 additions and 1 deletions

View 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);