- Home /
Prevent animation from moving character
As stated in the question I've this problem: when playing an animation my character moves from point A to point B without my consent. Here's the code:
public class Walk : MonoBehaviour {
private Animator humanAnimator;
private iInputProvider input;
private void Start()
{
input = new KeyBoardInput();
humanAnimator = GetComponent<Animator>();
walkMe = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
walk();
}
private void walk()
{
InputWrapper inputWrp = input.GetInputValues();
animateWalk(inputWrp.verticalMove);
}
private void animateWalk(float verticalMove)
{
if (-0.1 <= verticalMove && verticalMove <= 0.1) //stand still
{
humanAnimator.SetBool("Walk", false);
Debug.Log(humanAnimator.GetBool("Walk"));
}
else if (verticalMove > 0.1) // animate walk forward if the player is walking forward
{
humanAnimator.SetBool("Walk", true);
Debug.Log(humanAnimator.GetBool("Walk"));
}
else if (verticalMove < -0.1)
{
// walk backward animation needed
}
}
}
Note that nowhere in the code I change the object position, i just start the animation. Here's the result:
note that it's not the effect of the gif, the character actually resets its position after the animation is terminated. I was expecting the character to "run on the place". Anybody has some idea how can I fix this?
Answer by Legend_Bacon · Aug 07, 2018 at 05:37 PM
Hello there,
On your animator, did you leave the "Apply Root motion" box checked?
hi, thanks! If I uncheck the "Apply root motion" check box I've this result: https://imgur.com/4FdeC$$anonymous$$H . $$anonymous$$aybe it could be useful to know that I can't click on "Generate root motion curve" in my animation inspector because it's all uneditable: https://imgur.com/9q3h1cd
Its un-editable becuase you need to click edit.
Your answer
Follow this Question
Related Questions
Strange Character Movement (Mecanim) 0 Answers
Mecanim blend moves character? 1 Answer
Learning to move 1 Answer
Controlling a rigged models muscle groups via script (C#) 0 Answers