Search Unity

Animation 'Use Root Motion' Pushing Z-Axis Back A Certain Amount Each Time Played

Discussion in 'Animation' started by GladGoblinGames, Aug 29, 2016.

  1. GladGoblinGames

    GladGoblinGames

    Joined:
    Dec 14, 2011
    Posts:
    118
    Hi All,

    Got a problem with an animation of mine. I have a set of draws that use the same animation. I applied the 'Use Root Motion' to get it to play at the transformations root location. However, the problem is, I will play the animation, draw opens, press the draw again, the draw closes, but if I keep opening and closing it, the close animations pushes back an extra 0.5 on the Z-Axis each time the animation is played. I can't find the reason why!

    Here's the code I am using:

    Code (CSharp):
    1.     /// <summary>
    2.     /// Woohoo! Shorter code! Instead of using an if after if for each object. In this function,
    3.     /// we will react to each object that has a tag of "AnimatedObject" and we also grab the current
    4.     /// animator attatched to the object we are looking at. We set up a temporary bool that handles the on and off state.
    5.     ///
    6.     /// </summary>
    7.     /// <param name="objectBoolsName"></param>
    8.     /// <param name="objectAnimator"></param>
    9.     void InteractWithAnimatedObject(string objectBoolsName, Animator objectAnimator)
    10.     {
    11.         bool objectBoolValue;
    12.  
    13.         objectBoolValue = objectAnimator.GetBool(objectBoolsName);
    14.  
    15.         if(objectAnimator == null)
    16.         {
    17.             Debug.Log("Error: " + objectAnimator.transform.gameObject.name + " is missing an animator component");
    18.         } else
    19.         {
    20.             objectBoolValue = !objectBoolValue;
    21.             objectAnimator.SetBool(objectBoolsName, objectBoolValue);
    22.         }
    23.     }






     
  2. GladGoblinGames

    GladGoblinGames

    Joined:
    Dec 14, 2011
    Posts:
    118
    Just a little update, I noticed that some of the settings in this screenshot are wrong as I was testing out different ways of fixing it. 'Root Motion' is ON, and the draw animation close has an animation attached to it

    UPDATE: NEVER MIND. FOUND OUT HOW TO FIX IT. SETTING -1 ON THE CLOSE ANIMATION. PLEASE CLOSE/DELETE, WHATEVER NEEDS DOING XD
     
  3. FariAnderson

    FariAnderson

    Joined:
    Jan 20, 2020
    Posts:
    37
    hi, what did you exactly mean by this? i didn't really get it.