Search Unity

Animator.Play() messes with position.

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

  1. holistic1

    holistic1

    Joined:
    Jul 29, 2018
    Posts:
    8
    Hello, a few days ago i posted a problem that i encountered in hopes of finding a solution which can be found here. It was never solved but i kinda were able downgrade the problem into single variable. When i trigger
    anim.Play()
    character moves to another spot in XZ plane which is not far from the original position.


    Code (CSharp):
    1. Animator anim;
    2.  
    3.     void Start()
    4.     {
    5.         anim = GetComponent<Animator>();
    6.     }
    7.  
    8.     void Update()
    9.     {
    10.         if(Input.GetKey(KeyCode.P))
    11.         {
    12.             anim.Play("Stand Up",0,0);
    13.         }
    14.     }
    As you can see code is very simple. Animator controller is composed of only "Entry" being connected to a state named "Stand Up". I can't figure out why this "shift" happens. Disabling root motion fixes this problem but it is not an option for me.
     
    Last edited: Mar 7, 2019
  2. McC1oud

    McC1oud

    Joined:
    Mar 14, 2015
    Posts:
    96
    I'm having a similar problem but sorta in reverse.

    My problem is that when I built my animation frames in Maya, I created it at zero'd out. I then placed it with an adjusted position and rotation as a child of another object within Unity. So new position, and a new rotation in front of the camera and childed to the camera.

    When I run my animation, the sword will snap to the zero'd out local transform of the parent which is my camera. The result being that the sword would skip frame up into my characters head, play the animation, then return to it's placement once the animation finished. I found a solution to the problem by applying the root motion... but further on in my original post you can see the root motion was causing me other issues.

    https://forum.unity.com/threads/sword-swing-animation-problems.640615/
     
  3. holistic1

    holistic1

    Joined:
    Jul 29, 2018
    Posts:
    8
    Sound like that may be solved by parenting your character to the sword and then animating it.
     
  4. McC1oud

    McC1oud

    Joined:
    Mar 14, 2015
    Posts:
    96
    Can't do that, then the character would animated with the sword =p

    For now with root motion applied , I'm force resetting the transform values of the sword once the animation time finishes.
     
  5. tiredamage42

    tiredamage42

    Joined:
    Oct 26, 2016
    Posts:
    19
    Try changing the import settings on the animation asset. Uncheck "bake into pose" on the XZ motion option.
    Also change it to "Use Original"
     
  6. holistic1

    holistic1

    Joined:
    Jul 29, 2018
    Posts:
    8
    Thanks for your answer. I "kinda" solved the problem by fixing the character's position for a few frames after initiating the "get up" process. Again the problem with this is even though i fix the position in
    LateUpdate()
    , character teleports back to a random position for a single frame and then gets back. And i solved that by doing a linear interpolation between ragdoll position and animation position. It annoys me to use such complex solutions for such a ridiculous problem but thats it.