Add optional minimumDistance parameter to SharedJointSystem.CreateDistanceJoint (#5682)

This commit is contained in:
DrSmugleaf
2025-02-17 19:18:15 -08:00
committed by GitHub
parent 7df23e047c
commit af2d01981f

View File

@@ -236,7 +236,8 @@ public abstract partial class SharedJointSystem : EntitySystem
Vector2? anchorB = null,
string? id = null,
TransformComponent? xformA = null,
TransformComponent? xformB = null)
TransformComponent? xformB = null,
int? minimumDistance = null)
{
if (!Resolve(bodyA, ref xformA) || !Resolve(bodyB, ref xformB))
{
@@ -246,9 +247,13 @@ public abstract partial class SharedJointSystem : EntitySystem
anchorA ??= Vector2.Zero;
anchorB ??= Vector2.Zero;
var length = Vector2.Transform(anchorA.Value, xformA.WorldMatrix) - Vector2.Transform(anchorB.Value, xformB.WorldMatrix);
var vecA = Vector2.Transform(anchorA.Value, xformA.WorldMatrix);
var vecB = Vector2.Transform(anchorB.Value, xformB.WorldMatrix);
var length = (vecA - vecB).Length();
if (minimumDistance != null)
length = Math.Max(minimumDistance.Value, length);
var joint = new DistanceJoint(bodyA, bodyB, anchorA.Value, anchorB.Value, length.Length());
var joint = new DistanceJoint(bodyA, bodyB, anchorA.Value, anchorB.Value, length);
id ??= GetJointId(joint);
joint.ID = id;
AddJoint(joint);