Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

How do you capture the "internal" state of a joint, so that it can be restored?

Discussion in 'Physics' started by Lipoly, Mar 28, 2019.

  1. Lipoly

    Lipoly

    Joined:
    Feb 11, 2014
    Posts:
    42
    I'd like to capture the current state of a joint, so that I can later restore the joint to the same state. It sounds pretty straight-forward, but the issue is that when I capture data to save a joint while it is "bent", re-creating those bodies/joints will result in the joint's "neutral" position being the bent orientation and they won't try to go back to the original neutral state before it was saved.

    See this video for more info:


    What I'd like to do is initially restore the pistons to their bent state (which is happening...good) but also have the joints try to go back to their original linear orientation, which I don't know how to make happen.

    It seems that whatever configuration bodies are in when a joint is created, that will be the "neutral" position that they always try to go back to, and I cannot find a way to alter it after the joint is created.

    Any thoughts on how to achieve this would be appreciated, thanks!
     
    Last edited: Mar 29, 2019
    Andrew-Garrison likes this.
  2. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,558
    The orientation of a joint is recalculated every time it’s gameobject is activated (for what reason, I can’t even guess, it is a big problem with ragdolls too). The only way to reset correctly would be to store the position and rotation of the joint object relative to it’s connected body at Start, then before you re-activate, move & rotate the objects back to default relative to each other, so the orientation would be calculated the same.
     
    Lipoly likes this.
  3. Lipoly

    Lipoly

    Joined:
    Feb 11, 2014
    Posts:
    42

    I didn't realize it was reset every time it is (re)activated, so that is good to know. I followed your advice and made sure the bodies were in "neutral" positions/orientations relative to each-other before creating the joint, and then moved them to proper positions after the joint was added, and it appears to work well...the joints behave as desired. It is a bit unfortunate that there isn't a more direct way to accomplish it, but it does work w/o too much trouble, so I'm ok with it. Thanks a lot!