I’m attempting to produce a two dimensional elastic rope in Unity using a series of SpringJoint2D joints between my anchor and my target rigidbodies.
Unfortunately, the rope is unable to compress to zero length (in my example, i want the target to be able to pass undisturbed in front of the anchor) due to the way a spring joint also tries to expand to the target length.
If I use a DistanceJoint2D, with maxDistanceOnly set to true, the rope behaves correctly, but unfortunately doesn’t stretch when it hits full length.
Is there any way to implement a maxDistanceOnly with the spring joint?
Might be better if you posted some image and annotate it to show exactly what you want.
Seems like you’ve got a hierarchy of SpringJoint2D chained together then a DistanceJoint2D with maxDistanceOnly set to true which I presume is connected from the anchor (start) to the end of the rope?
Typically in this siutation you’d have ‘autoConfigureDistance’ on for the joints connecting the rope/chain together, in this case the SpringJoint2D and for the DistanceJoint2D with maxDistanceOnly set, have ‘autoConfigureDistance’ off and set its distance to be slightly larger (or just set the connectedAnchor to be further away). Having the DistanceJoint2D longer allows the rope to stretch (in this case using a spring damper).
With regards to minimum distance, yeah you cannot have zero but the minimum distance is tiny (0.005m or 5mm)! If that’s visually significant then maybe your scale is too small?
Again, maybe some clarification with an image might help if I’m off here on my assumptions.
Here’s a gif that shows the basic problem I’m having, using just one joint. You can see how the falling body is initially held up by the spring joint, as it’s resisting the compression, before it falls around and behaves as expected.
I’d prefer the object to be able to fall directly through the anchor without the joint resisting the compression, effectively a spring joint with ‘max distance only’