- Home /
Unable to play animation continuously?
Alright, I have posted to Stackoverflow and watched tutorials but I am unable to make my walk animation work code wise. I have a complex problem being that in my game the user taps to move, thus the character is either idling, walking just one step at a time or walking continuously. So far I transition from idle to walking (in just individual steps, meaning the user isn't tapping repeatedly) with this setup and this code, and it works well -
I have an idle state and the walking clip, and the transition between the 2 is a bool "isWalking" that is either true or false.
I cannot merely trigger the walk animation without an offset because I have to alternate between left and right steps, so I use an increasing offset that (I think I did it right) should move through the whole animation, depending on if the object is moving:
if (animOffset >= 1f) { //was full clip
animOffset = 0.0f;
}
//anim help
currentPos = transform.position;
if (currentPos != lastPos) {
//print ("moving now");
animator.SetBool ("isWalking", true);
if (InputManager.stepCount % 2 != 0) {
print ("moving right");
animator.SetFloat ("walkOffset",animOffset);
} else {
print ("moving left");
animator.SetFloat ("walkOffset",animOffset);
}
animOffset += 0.1f;
} else {
animator.SetBool ("isWalking", false);
}
lastPos = currentPos;
When the user taps repeatedly however, the animation SHOULD not start over again from its offset in individual steps - it should just play the animation for the duration of its movement. Problem is using this if I watch the blue bar on the animation states, it ALWAYS starts from the beginning if I keep a consecutive step count and set the offset to 0.0.
With just this, the walking is very glitchy if its not in individual steps as its starting again and again. Im new to animation - how can I do this?
How can I make sure an animation plays CONTINUOUSLY if the object is moving without stopping for too long? I have no idea how to do this
Can you post a screen shot of your Animator View? There's an option for transitions from "Any State" not to transition to self, it may help you, not sure.
Answer by Thomas-Hawk · Dec 20, 2016 at 05:09 PM
Is the animation marked as "Loop Time" in the models import settings?
Your answer
Follow this Question
Related Questions
Unity 5 Broken Animations? 3 Answers
How to control bones with code? 0 Answers
Hello! I have some issues with animations. 1 Answer
Slow down an animation from Script - C# 0 Answers
How do i use the animator avatar mask to combine two animations ? 0 Answers