Search Unity

Meaningless Displacement During Transition from Ragdoll to Mecanim

Discussion in 'Animation' started by holistic1, Mar 2, 2019.

  1. holistic1

    holistic1

    Joined:
    Jul 29, 2018
    Posts:
    8
    Hello, i am trying to create transitions from animation to ragdoll and vice versa. During this process, i encountered a strange problem that insists on not going away. I want to disable the Animator component of a character manually and get the ragdoll. Then i want to enable animator and get the animation. When i disable the animator through Unity interface, everything is fine and i get to the animation smoothly. But if i try to disable the Animator through for example
    Update()
    with some controller, the animation starts but for some reason the character shift in some direction and in some amount.

    Code (CSharp):
    1. [SerializeField]
    2.     bool ragdollToMecanimBool;
    3.     private Animator anim;
    4.  
    5.     void Start()
    6.     {
    7.  
    8.  
    9.         anim = GetComponent<Animator>();
    10.  
    11.  
    12.         anim.enabled = true;
    13.  
    14.     }
    15.  
    16.     void Update()
    17.     {
    18.         if (Input.GetKey(KeyCode.H))
    19.         {
    20.             anim.enabled = false;
    21.         }
    22.         if (ragdollToMecanimBool)
    23.         {
    24.             anim.enabled = true;
    25.  
    26.             anim.Play("standing_up_from_back", 0, 0);
    27.            
    28.            
    29.             ragdollToMecanimBool = false;
    30.  
    31.         }
    32.      
    33.     }
    In this script for example, i press "H" and character gets into ragdoll. When i try to get back to animation through enabling the "ragdollToMecanimBool", character shifts in XZ plane which doesn't make any sense. If i try to disable the Animator manually, everything is fine. It feels like this problem has a very simple solution but i've been trying to fix it for about a day now and nothing seems to work! Help me please.
     
  2. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    it probably has to do with the center-of-mass difference between the two animations (get-up - idle)

    check the transition in mecanim
     
  3. holistic1

    holistic1

    Joined:
    Jul 29, 2018
    Posts:
    8
    Hello, thanks for the answer. This happens in the first or second frame after i trigger the event. So naturally there aren't any transitions present at that time. What is even stranger is that even though i fix the position of the character in the
    FixedUpdate()
    , it still jumps to random point for a single frame and then gets back the fixed point. It is very wierd.
     
  4. Tario

    Tario

    Joined:
    Jul 31, 2013
    Posts:
    5
    This thread turns up in the top 10 google results so it's worth resolving, even if it is out of date:

    Does your ragdoll use rigidbodies? It'd be weird if it didn't...

    Rigidbodies store up any forces applied to them while the animator is controlling them. When the animator turns off, the forces are all applied at once, hence the jump. Set your rigidbodies to Kinematic while you're driving their movement with animations.

    Info from:
    https://answers.unity.com/questions/884827/smoothly-transition-between-animation-and-ragdoll.html
     
  5. holistic1

    holistic1

    Joined:
    Jul 29, 2018
    Posts:
    8
    It's not exactly out of date because i still couldn't figure it out.

    Unfortunately Rigidbodies and Kinematics aren't the problem, the jump you are talking about happens when character goes from Mecanim to Ragdoll. However my case is different, character's root position shifts if i use the anim.Play() method regardless of the kinematics. It is something related to the root motion of the animation but i just can't figure it out...

    I'll post some gifs later to represent the problem better when i get the chance.