Search Unity

Configurable Joint Follow

Discussion in 'Physics' started by psteng, Jan 9, 2020.

  1. psteng

    psteng

    Joined:
    Mar 27, 2017
    Posts:
    6
    I am attempted to create a physics based character with some animation control via a puppet-like system where an invisible animated character object controls some of the movement of the physics based character. To do this I am using configurable joints. I set the "puppet" joints' target rotations to the follow the rotations of the animated character.

    The issue I'm running into is that while for some joints this is working perfectly, for others, it is inverted. For example, when I move the animated character's arm up in the positive x direction, the puppet version moves in the negative x direction. The code I am using to make the puppet joints follow the animated character is here (this code is on each puppet joint with the target being a corresponding bone in the animated character):

    private void Awake()
    {
    startingRotation = Quaternion.Inverse(joint.transform.localRotation);
    }

    private void LateUpdate(){
    thisJoint.targetRotation = target.localRotation*startingRotation;
    }

    This image below should show a little more clearly what I'm talking about. The animated character is close to the camera on the left and the physics based character is further off on the right. As you can see the leg rotation is correct, but the arm rotation is inverted.

    ktmwtb_unity_forum_post.png
     
  2. SUUNE

    SUUNE

    Joined:
    Mar 10, 2019
    Posts:
    65
    Ow... We are working on a same thing. Here you have a complex explanation:
    http://www.diva-portal.se/smash/get/diva2:1324164/FULLTEXT01.pdf

    and answer to your question:
    Code (CSharp):
    1.  void LateUpdate()
    2. {
    3. if (invert)
    4. joint.targetRotation = Quaternion.Inverse(targetLimb.localRotation *
    5. startingRotation);
    6. else
    7. joint.targetRotation = targetLimb.localRotation * startingRotation;
    8. }
    Good luck.
    PS.
    What is your approuch on balance?
     
  3. psteng

    psteng

    Joined:
    Mar 27, 2017
    Posts:
    6
    Thanks! Easy workaround it seems. How is the invert variable set? Do you manually set it for each joint or is there a way to automatically detect when it should be inverted? I'm curious to know the root cause of why it's inverted for some and not for others.

    For balance, I actually have it based somewhat off that article that you linked. I have a parent object to the hip joint which is kind of a 'control' object. It has a capsule collider going up the spine of the character. It also has a config joint with target rotation for x and z set to 0 (y changes based on movement so that the character faces the direction of movement). This doesn't keep the upper body up however as it is too heavy, so I also have 3 hinge joints on this control object. They are connected to the head, chest and hip rigidbodies with spring values. It's working pretty well actually right now, but I haven't tested thoroughly.
     
    laurent_quark likes this.
  4. SUUNE

    SUUNE

    Joined:
    Mar 10, 2019
    Posts:
    65
    Make a public bool and manually invert where its needed. I dont really know how config joints apply rotation... but from my research I think nobody knows how its works :).
    About balance... Your approuch is fine but ragdoll then act like a doll on strings. I didn't like that so I make it differently... far more complex. That's the biggest chalange here if you want to have realistic movement.
    Good luck.