mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Add optional minimumDistance parameter to SharedJointSystem.CreateDistanceJoint (#5682)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user