Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why Do Physics Joints Always Stretch!?

Discussion in 'iOS and tvOS' started by se7en, Sep 8, 2009.

  1. se7en

    se7en

    Joined:
    Dec 3, 2008
    Posts:
    232
    I have been messing around with Physics and specifically joints for a while now and there is one thing that I cannot seam to fix... stretching joints. You can put two objects with rigidbodies and colliders together in space at identical coordinates and when they hit something the joints stretch apart and spring back together.

    I know I could set a low break point but these are not big impacts in the grand scheme of things. The completely separated joint in the last image below is from a drop of maybe 6 meters at very slow speed.

    In the example of a hinge joint they say its for a door but why would a door stretch off of it's hinges? I have tried every joint type and every setting. Same results. I have tried very small and very large numbers for mass. Using gravity and not. Again, same result.

    Any help would be greatly appreciated.

    shay

    Sample layout and reactions attached:
     

    Attached Files:

  2. jmunozar

    jmunozar

    Joined:
    Jun 23, 2008
    Posts:
    1,091
    Hello!

    Increase the spring value so you don't have those problems. ;)

    its getting stretched because the force is really high.
     
  3. se7en

    se7en

    Joined:
    Dec 3, 2008
    Posts:
    232
    hey naruse - I tried everything from 999 to infinity on most joints and they still stretch. Fixed joints don't even have a setting and they stretch too.
     
    CloudyVR likes this.
  4. jmunozar

    jmunozar

    Joined:
    Jun 23, 2008
    Posts:
    1,091
    Did you tried playing with the min/max limits?

    before I start playing with that so I can help you out.
     
  5. se7en

    se7en

    Joined:
    Dec 3, 2008
    Posts:
    232
    Thx again naruse. Yeah I have messed with every single setting and every single joint type. Again, try this test with a fixed joint and you will see it stretch.

    I am basically hoping someone from the Unity team will step up and say "Yes, it does stretch and there is nothing that you can do about it" or "No, here's how to fix it..."
     
    CloudyVR likes this.
  6. ezone

    ezone

    Joined:
    Mar 28, 2008
    Posts:
    331
    You can reduce the stretching effect by reducing 'Fixed Timestep' in Edit > Project Settings > Time > Fixed Timestep. The bad news is that this increases the load on the physics calcs, so your FPS will take a hit.
     
    NomanAliUnity likes this.
  7. se7en

    se7en

    Joined:
    Dec 3, 2008
    Posts:
    232
    Cool thx Simon. I think I am at .02 already but I will mess with it a bit more. Maybe increasing solver iteration count will help too. Beyond the basic uses of physics in Unity it all seams very mysterious. A lot of numbers to change and sometime you don't see any visual result.

    Its a hell of a lot of fun when it does work right though!
     
  8. cheezorg

    cheezorg

    Joined:
    Jun 5, 2008
    Posts:
    392
    I'd also love to find a way to "lock" joints together. Looked into it a while back but never found a great solution.
     
    CloudyVR likes this.
  9. ivanmoen

    ivanmoen

    Joined:
    Dec 26, 2008
    Posts:
    102
    I also had great difficulties with the stretching joints. I ended up adding a coroutine that repositioned the local position at a fixed interval. But a ‘lock’ parameter would be great.
     
    CloudyVR likes this.
  10. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Yes, I would also like this. I also requested, a long while back, to be able to measure the "tension" on a joint. That what I can determine whether the joint is stretching and by how much.
     
    CloudyVR likes this.
  11. Mactivist

    Mactivist

    Joined:
    Jun 25, 2009
    Posts:
    6
    Not sure if this will help, but I had the same problem trying to do 2D car physics. When I accelerated or hit the brakes, the wheels would get pushed or pulled forward and back instead of staying locked to the Y axis. I ended up using a workaround, which was to do the physics on invisible wheels, with the visible wheels using their position as a reference, but with restrictions, such as locking them to the Y axis and keeping the wheel within the suspension's limits. It didn't solve the real problem, but it hides it pretty well.
     
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Two questions:

    1. Any chance to see the physical materials applied to ground and wheels?

    2. Did you try it with realistic values?
    Infinite break force and break torque for example are are very unrealistic, as thats an infinite force against the cycles body from the joint which causes the massive torque your see on the screen with the body beeing rotated by about 60°.
    Normally it would be around 20-40° or if the spring is completely stiff, a "salto" over the front wheel or pure slide (depending on the setup of the physical materials of wheel and ground) would be the consequence. What it never will do is not compress the spring while going into instant standstill.
    Thats physically completely impossible.

    Such "game physics" would be something you either have to develop yourself or need to be achieved through coded physics changes, which means that the moment you break your script must basically kill the whole inertia in the system.
     
  13. LaurynasLubys

    LaurynasLubys

    Joined:
    Mar 7, 2012
    Posts:
    80
    Same issues still exists, weird that there is no easy way to go around this yet.
     
    CloudyVR and zero_null like this.
  14. EETechnology

    EETechnology

    Joined:
    Aug 15, 2015
    Posts:
    185
    I have the same problem!!!
     
    CloudyVR and zero_null like this.
  15. allenjamesllc

    allenjamesllc

    Joined:
    Dec 26, 2017
    Posts:
    1
  16. backwheelbates

    backwheelbates

    Joined:
    Jan 14, 2014
    Posts:
    225
    Why not just put your collider as a child of the rigidbody. Make sure to NOT put a rigidbody or joint on the collider, this way Unity will group it directly with the parent Rigidbody.

    I'm not aware of any downsides to doing this.
     
  17. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,253
    I spent a lot of time trying to figure this out, and eventually realized there's no such thing as a non-stretchable joint. I tried every type of joint, every possible setting, tried every suggestion I could find, and the joints always stretch. If you need a fixed joint that never stretches, don't waste your time trying to do it with the physics engine.
     
    CloudyVR likes this.
  18. backwheelbates

    backwheelbates

    Joined:
    Jan 14, 2014
    Posts:
    225
    @John-B , that's my conclusion as well. Although I only recently learned that unity's mass is totally arbitrary and not based on kg. I find I get much better joint behavior if I keep mass in the 5-10 units range. I get much less stretching if I stick to this.
     
  19. tiddles451

    tiddles451

    Joined:
    Apr 11, 2019
    Posts:
    2
    Im not sure how feasible this is in most cases, but increasing the Rigibody2d.mass on each side of the hinge much reduced the stretching for me.

    Rigibody2d.mass = 0.1f; // had massive amounts of stretch
    Rigibody2d.mass = 1.0f; // had minimal amount of stretch so as to almost not be noticeable
     
  20. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,009
    Enabling projection on joint might help.
     
  21. Travlynn02

    Travlynn02

    Joined:
    Feb 7, 2017
    Posts:
    4
    So far the best I can do has the following settings: Mass 1 - 10, timestep .002 gives me no stretch (visible on 15 linked treads). Now to try splitting my colliders from my rigid body as suggested to get rid of the tangle problem with fast movements.
     
  22. IvanWeeskey

    IvanWeeskey

    Joined:
    Jan 8, 2017
    Posts:
    12
    Hello guys, I just figure it out.
    Try moving ur rigidbodies by adding a force towards target location in FixedUpdate.

    e.g.

    Vector3 force = (targetPosition - rigidBody.position).normalized;
    force *= 3000f;
    rigidBody.AddForce(force);