Search Unity

Question Joint Separating Weirdly

Discussion in 'Physics' started by C88D, Dec 25, 2023.

  1. C88D

    C88D

    Joined:
    Jun 16, 2022
    Posts:
    12
    I have a chain of objects all connected to eachother with distance joints. The distance joints' distances are mostly set to 0.005 except the first one, which is connected to a moving frog. the end of the chain has forces being applied on it in FixedUpdate. However when the forces are applied to the end of the chain the chain separates in weird ways, like so:
    Screenshot 2023-12-25 172452.png Screenshot 2023-12-25 172432.png Screenshot 2023-12-25 172419.png
    Screenshot 2023-12-25 173750.png

    I've tried lowering the FixedTimestep to as low as 0.0001 (it didn't work, just lagged a lot). Help please?

    The joints are on each segment, connected to the segment closer to the frog.

    Is there something I'm missing?
     
    Last edited: Dec 26, 2023
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,487
    In the end, chains of joints are only stable if you're careful and are not applying crazy forces which is often the case. The solver can only use the number of solver interations that are specified in the physics settings so I guess you've not increased those.

    Changing the time-step to try to run physics 10,000/sec shows you're wildly guessing. I would highly suggest you get to grips with a smaller experiment first as you cannot just brute-force chains of joints and expect them to be stable.

    If you want to maintain a "chain" of joints but ensure they don't stretch beyond a certain distance then you can add another DistanceJoint2D from the anchor to the end of the "chain" and select "Max Distance Only".

    You can see this exact example in my GitHub repo that shows examples for most of 2D Physics.

     
    Edy likes this.
  3. C88D

    C88D

    Joined:
    Jun 16, 2022
    Posts:
    12
    Hey thanks for your answer! And your clever use of the distance joint was really clever! In your video, are the individual chain segments linked together with distance joints or hinge joints? Does that make any difference?

    Edit: nevermind, I got your repo
     
    Last edited: Dec 27, 2023
    MelvMay likes this.
  4. C88D

    C88D

    Joined:
    Jun 16, 2022
    Posts:
    12
    And also even when I am simply holding the chain at a fixed point it still breaks apart. Screenshot 2023-12-26 091830.png
     
  5. C88D

    C88D

    Joined:
    Jun 16, 2022
    Posts:
    12
    It appears the distance joints are less stable than hinge joints at small distances...

    Screenshot 2023-12-26 095344.png
     
    Last edited: Dec 27, 2023
  6. C88D

    C88D

    Joined:
    Jun 16, 2022
    Posts:
    12
    Thanks for yer help