Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Missing ConnectedMassScale in SpringJoint2D?

Discussion in 'Physics' started by tr0ma, Nov 18, 2022.

  1. tr0ma

    tr0ma

    Joined:
    Dec 4, 2012
    Posts:
    19
    For some reason the SpringJoint class has connectedMassScale, a very handy feature that doesn't seem to be available in SpringJoint2D...

    What would be the best way to replicate this behavior in a 2d context?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,580
    They are completely different physics engines i.e. PhysX (3D) vs Box2D (2D) so there isn't exact feature parity.

    You cannot unless you create your own script-based spring constraint.
     
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,531
    As for what I've tested in 3D physics, the effect of connectedMassScale is no different than just scaling the mass of the connected object. Indeed as for my tests that's what it does.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,580
    Not a 3D physics guy here but yes, I believe it's a temporarily scaling thing only active during the joint solver for that specific joint without having to permanently change the actual mass for other forces such as collisions etc?

    I've personally never used it. Effectively changing the mass of both bodies would achieve the same thing as long as you didn't need some other mass for some other reason.
     
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,531
    That's what I also believed, that it would be something applied to the calculations at some stage only. But the tests show that this option applies a scale to the connected mass equivalent to... just scaling the mass in the connected rigidbody. Even the total weight of the object increases accordingly.
     
    MelvMay likes this.
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,580
    Wow, thanks for the info. That's almost to the point of being weird though!

    I wonder what happens if you use multiple joints. It seems very weird that it's not a "local" effect.

    I learned something today. :)
     
    Edy likes this.
  7. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,531
    Yes, exactly! I might be missing something, but in the past I spent quite a few time researching ways to stabilize joints without increasing the physics rate, and that was the result of testing the connectedMassScale option.

    I haven't tested circular joint connections, but the effect was the same in a chain of joints. connectedMassScale simply increased the mass of the referred body, so that part of the chain becomes more stable (and more heavy).

    So far, the best way I found to stabilize joints without modifying the masses is scaling the inertia of the Rigidbodies when there's a significant difference between the connected masses. Of course, abusing this option also has its consequences (like a "dragged" motion), but it works fine without noticeable effect in most situations.
     
    MelvMay likes this.
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,580
    I asked the 3D physics team about this earlier so on Monday I might have more info. Just curious really. It wouldn't be hard to add this to 2D physics but I'd definatley implement it as a solver-only thing for that joints reaction impulses.
     
    Edy likes this.
  9. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,531
    I'm very curious too, let me know what they say.
     
    MelvMay likes this.
  10. tr0ma

    tr0ma

    Joined:
    Dec 4, 2012
    Posts:
    19
    Thanks for the answers, on my side for my use case, I switched to PhysX entirely and work it without using the 3rd axis. It was easier since I'm still in a context of a prototype.

    Although I'm very curious to hear the result of this investigation.
     
    Last edited: Nov 21, 2022