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:
@@ -107,6 +107,7 @@ public sealed partial class ShuttleSystem
|
|||||||
var ourXform = Transform(args.OurEntity);
|
var ourXform = Transform(args.OurEntity);
|
||||||
var otherXform = Transform(args.OtherEntity);
|
var otherXform = Transform(args.OtherEntity);
|
||||||
var worldPoints = args.WorldPoints;
|
var worldPoints = args.WorldPoints;
|
||||||
|
var worldNormal = args.WorldNormal;
|
||||||
|
|
||||||
for (var i = 0; i < worldPoints.Length; i++)
|
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 ourVelocity = _physics.GetLinearVelocity(args.OurEntity, ourPoint.Position, ourBody, ourXform);
|
||||||
var otherVelocity = _physics.GetLinearVelocity(args.OtherEntity, otherPoint.Position, otherBody, otherXform);
|
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
|
// 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);
|
var effectiveInertiaMult = (ourBody.FixturesMass * otherBody.FixturesMass) / (ourBody.FixturesMass + otherBody.FixturesMass);
|
||||||
|
|||||||
Reference in New Issue
Block a user