Search Unity

Mecanim CrossFade: CenterOfMass issue

Discussion in 'Animation' started by dibdab, Oct 13, 2019.

  1. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    you can see it is not happening with the same animation replay
    but happens when another animation is started

    animation settings
    Root Transform Rotation - body orientation
    Root Transform Position (y) - feet
    Root Transform Position (x,z) - center of mass


    5.67
    comproblem5.gif
    2018.4
    comproblem5_2018.gif

    might be related to this?
    Turns out Animator.CrossFade (the method used to make smooth transitions between animations) always starts its blending at the beginning of the first animation. I tried every possible method and work around, but its no use. As soon as the method is triggered the first animation automatically goes to the first frame.
    https://forum.unity.com/threads/released-universal-fighting-engine.218123/page-6

    or somehow
    mecanim doesn't update center of mass correctly at transitions when it has some velocity?
     
  2. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    okay, made a barebones test
    and it looks very much like

    this happens with blend trees (and not with simple states)

    to reproduce:
    anim1.jpg
    if blendtree (for both)
    anim1b.jpg

    and the script
    Code (CSharp):
    1.     public Animator animator;
    2.     public string anim1 = "anim1";
    3.     public string anim2 = "anim2";
    4.  
    5.     public KeyCode switchAnim = KeyCode.Space;
    6.     public string lastAnim = "anim1";
    7.  
    8.     public bool isBlendTree;
    9.     public float randomx;
    10.  
    11.  
    12.     void Update () {
    13.  
    14.         if (Input.GetKeyDown (switchAnim)) {
    15.  
    16.             if (isBlendTree) randomx = Random.Range (0, 1);
    17.             if (isBlendTree) animator.SetFloat ("Blend", randomx);
    18.  
    19.             if (lastAnim == anim1) {
    20.                
    21.                 animator.CrossFade (anim2, 0.1f);
    22.                 lastAnim = anim2;
    23.             } else {
    24.                 animator.CrossFade (anim1, 0.1f);
    25.                 lastAnim = anim1;
    26.             }
    27.         }
    28.     }
     
    Last edited: Oct 14, 2019
  3. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    unfortunately this is not just the issue with CrossFade, but with transitions type of animator.SetTrigger too
    tried simple states with substate machine and the problem still occurs

    the only circumstance where this problem is not there, is if all animations are on the base layer

    @Mecanim-Dev
    could you please take a look at this issue

    looks like animator.bodyPosition / center-of-mass is calculated wrong (frequently) when animation transitions to different animator level (blend-tree / substate machine)
     
    Last edited: Oct 15, 2019