Long rope / chain with Joints 2D (Impossible?)

I have setup a chain with 100 individual link elements connected with HingeJoint2D. Due to the way joints work in Unity the chain becomes very elastic. And if I put a weight at the end the chain just breaks. I tried many things to try make the joints more stable. But nothings seams to work for a long chain.

Things I tried:

  • Adding an additional DistanceJoint2D between each link. This does help a lot but still not enough.
  • Pumping up the position iteration in Physics2D settings. at a value of 100 it does actually kind of work. But performance is way out of control.
  • Getting the reaction force for each joint and multiplying by a number in FixedUpdate(link.addForce). turns out to be even more heavy on performance then position iteration.
  • increasing the mass of the links. (gives unwanted behaviour on the weight at the end.)

I’m out of ideas of how to solve this…

You need to add a DistanceJoint2D between the start and end point with its MaxDistanceOnly set to true. This provides a maximum distance the whole rope/chain can stretch to.

If you look at my GitHub project here: GitHub - Unity-Technologies/PhysicsExamples2D: Examples of various Unity 2D Physics components and features. , specifically the following scene then it’ll give you an idea how it works: PhysicsExamples2D/Assets/Scenes/Joints/DistanceJoint2D_MaxDistanceOnly_Chain.unity at master · Unity-Technologies/PhysicsExamples2D · GitHub

Thank you for your reply. Actually I also tried to set a distanceJoint between start and end but forgot to mention it. This does give an additional problem in my specific case.

In my game the chain isn’t always hanging straight down from start to end. many times it will be bent over an ledge. Imagen a cliff with a tree. the tree would be the start point, the first links would be laid out horizontally until the cliff edge is reached. Then the links bend over the ledge and start hanging down vertically along the cliffside. The distance between start and end in this case would be much smaller then the actual length of the chain.

But I will give this solution a bit more thought. maybe there is a workaround for that problem.

For that situation you could use a DistanceJoint2D with MaxDistanceOnly set to true that connects the root of the chain to each segment. That way, each segment cannot move further away from the root than what you specify. This would give you a per-segment distance constraint.

yeah thats an idea. but how would it work for the vertical part of the chain? A vertical position change would give very minor change in distance to the root. And setting up the distance would require a different method then just defining the chain length and number of links. otherwise it would be the same problem as for only connecting the start to end?
or am I missing something?

hi MelvMay,
thanks for your link that your share in github,It was very useful.Actually I’m creating a rope with hingeJiont2D. It works fine, but I want to move it by acceleration when you tilt the phone. I’ve write some code but and It’s working, but I’m not sure it’s the best way for moving rope or not.Could you please check it out.

void Update()
        {
            number = chainGeneratorRef.getQuantity();
            chainGeneratorRef.getLastSegment(ref lastSegment);
           
            rb_lastSeg = lastSegment.GetComponent<Rigidbody2D>();
            lastSegment.GetComponent<Rigidbody2D>().AddForce(transform.right * Input.acceleration.x * sensitivity);
            transform.parent = chains.Last().transform;
           
            LimitMovement();
            flipPlayer();
           
            // CircularMotion();
        }