Search Unity

Root Motion Animation finishes then slides character back to origin of movement

Discussion in 'Animation' started by Auticus, Jun 10, 2022.

  1. Auticus

    Auticus

    Joined:
    Jul 18, 2013
    Posts:
    99
    I have googled this up for the past couple of hours and cannot find a satisfactory answer to resolve this issue.

    (refer to attached Slide.gif for visual)

    Rolling Animation
    upload_2022-6-9_22-53-20.png


    Animator Control on Character
    upload_2022-6-9_22-54-34.png

    This is a rigid body character that moves via physics.

    In the script when the animation is applied, the applyrootMotion flag is set to true:


    Code (CSharp):
    1.  public void PlayTargetAnimation(string animation, bool isInteractingAnimation)
    2.         {
    3.             _animator.applyRootMotion = isInteractingAnimation;
    4.             _animator.SetBool(_isInteractingHash, isInteractingAnimation);
    5.             _animator.CrossFade(animation, ANIMATION_CROSSFADE_DAMPING);
    6.         }
    (verified that the flag coming in is true, and it logs to the debug console as true)

    Setting animator Update Mode dropdown to Animate Physics does not solve the issue. It lessens it somewhat but the slide to origin still occurs.

    I note that during the rolling animation, the players Transform coordinates do not move at all. So character rolls... then slides back to origin, and Transform does not move at all.

    I note that if I do not bake the xz position into pose that the slide does not happen, but the model also does not move at all (it rolls in place) inferring I would need to write code to move its transform if I went that route.

    There are three possible outcomes that I can see fixing this but I cannot find an example:

    1) the animation rolls the character and that updates the transform location of the player. This is what I would expect to happen, but is not. Its not updating the transform location at all, causing the character to slide back to original position once complete.

    2) I have to write code to update the player transform position at animation completion. This seems dirtier but if thats what I have to do then thats what I have to do. I cant seem to find any good examples of this however.

    3) I uncheck bake xz position into pose, the model will then roll in place and I have to manually update the position. This seems dirty as I'm using physics movement and want to let the physics system move the character, not me writing code to update positions.

    I have gone over the root motion docs and cannot find a satisfactory answer.

    For what its worth, the camera I am using is a Cinemachine Freelook Camera looking at the player.

    What am I missing?
     

    Attached Files:

  2. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    672
    you should not bake the xz position. check if setting the root node to something else than default would work (if this is a .anim, you won't be able to do)

    also you can 4) redo the animation. (adding root-motion and recording that)

    I see you have animator.applyRootMotion true, but might check if there is animator.ApplyBuildInRootMotion() code in OnAnimatorMove.
    tip: try with another roll animation and if that works, the problem is this animation clip.
     
    Mouledoux likes this.
  3. Auticus

    Auticus

    Joined:
    Jul 18, 2013
    Posts:
    99
    I brought in a Mixamo animation for rolling and it does the same thing. Rolls fine then snaps back to the origin point.

    Digging around a bit I noticed in other examples the XZ Bake is also disabled. So I 'm thinking this is my issue (as when I disable that, it does stop it from snapping back... but the model barely moves...)

    So... now its trying to understand why if I disable XZ bake the model barely moves. When I say barely moves I mean it does the roll animation but the horizontal distance it travels is tiny, whereas if I bake xz it travels the horizontal distance I expect but snaps back.
     
    Last edited: Jun 10, 2022
  4. Auticus

    Auticus

    Joined:
    Jul 18, 2013
    Posts:
    99
    Attaching gif of the animator window. The XZ bake is off... but the model is rolling in place. In tutorials and other places I see the model NOT being stuck in place with this flag turned off. This also seems to be a root issue. This is like this with my animation and mixamo animations.

    If I enable Root Transform Position Bake into Pose... the model rolls as I would expect off of the spot (but then in the game will snap back as my original post)
     

    Attached Files:

  5. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    672
    might be a unity version bug.

    "but the model barely moves" this sounds like onanimatormove update bug.
    you are applying the root motion manually, animator note: 'handled by script'.

    this is .anim, right? not the original fbx? you should set the rig to humanoid if, but I think you already did, so not that...
    might check the animation import settings.
     
  6. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    672
    just had a similar issue with a model I was working with
    (it had two armatures and base stack+animation, but that's irrelevant, removed that in blender and used as humanoid in unity)

    it happened on generic, but it was alright in humanoid
     
  7. Auticus

    Auticus

    Joined:
    Jul 18, 2013
    Posts:
    99
    Per the screenshot above my controller is humanoid.
     
  8. Auticus

    Auticus

    Joined:
    Jul 18, 2013
    Posts:
    99
    What I believe to be the solution.

    #1 - do not bake XZ animation. While the animator window will show the animation moving correctly, it will slide the model back to the original location.

    #2 - I had my physics code in LateUpdate but my animation and rolling in Update. This caused the issue where my model would appear stuck even though everything seemed rigged properly.

    Moving all of my movement code for the moment into my Update method for movement has totally resolved the issue.