Idle animation stalls on loop

I’m using Unity 5, and I have the idle animation for the trophy set up almost identical to that in the video (five keyframes, Z rotation of 0, -9, 0, 9, and 0 respectively). However, when the animation loops you can see the trophy top come to a stop before it starts moving right, instead of smoothly rocking from left to right. Anyone know why this is and how to ensure that the loop is smooth?

EDIT: I think Unity 5’s animator considers acceleration when it’s interpolating transforms, rather than just changing the transform linearly. I don’t know of a way to change this, but I think a workaround could be starting the animation with the trophy tilted to the side. Then you could use the cycle offset option to make it so that it starts from the neutral position in-game. I haven’t gotten a chance to try it myself yet though

EDIT2: Screw that I found a better way to do it

6 Likes

I’ve been having the same problem on my loops.

2 Likes

I figured it out. With the keyframes for the rotation selected, right-click on the corresponding row in the timeline and you’ll get a menu in which “Clamped auto” is selected. Change this to “Auto”. Let me know if that works for you as well

EDIT: After reading about it a bit, turns out that the Auto option is a legacy option that you’re not really supposed to use anymore. I think the more correct way to do it is to set the first keyframe to Right Tangent > Linear, and the last keyframe to Left Tangent > Linear

5 Likes

Thanks! I’ll give that a try this weekend.

1 Like

Thanks Zach, I had given up then thought to check the forum here. Your fix works for me too :slight_smile:

As for the “correct way” to do it with Right/Left Tangent Linear, I would prefer they keep “auto” and make that the default and keep the maths out of it. The whole idea of a games engine is that you should be not be distracted too much with the maths and physics. However, I may have misunderstood why the “correct way” is the correct way and perhaps this reinforces my point i.e. please make it as simple as possible (even though doing that can be complicated). Just my opinion. Thanks again.

1 Like

You’re probably going to find yourself limited down the road if you avoid math and physics entirely. While it’s great that Unity can handle most of it for you, things will often need to be adjusted to make them fit your game design. You shouldn’t be too afraid of going beyond the engine’s default behavior.

That said, the tangent in this example actually isn’t all that mathy. The tangent just refers to the way in which the variable changes over time. Take a look at the Curve tab in the animator to get a visual of this. When you tell that tangent to be linear, you’re just saying “Don’t worry about overshoot, just go straight to the keyframe”. The section of the graph becomes a straight line (hence, linear). Unity is still doing the calculations for you, you’re just telling it to do a specific way.

The difference between Clamped Auto and Auto and why it’s more proper to avoid using Auto is because Clamped Auto is meant to replace Auto, but Auto is included for backwards compatibility. Clamped Auto tries to avoid “overshoot”, while Auto does not. I don’t have a solid understanding of the benefits of clamped auto, but I think Clamped Auto is generally superior except in specific cases like this one, so it’s better to use it for most of your animation then just make the necessary curves linear. A deprecated feature like Auto was probably deprecated for a reason, and it may not still be available in future versions of Unity.

2 Likes

@Zach_Williams Thanks Zach for the insightful response to my concern.

I don’t want to labor a point as I am way out of my depth here, and I have yet to try the left/right linear settings to see if it solves the “stall” problem, but as I am using unity 5…5.1 this is an issue for me as the default setting (clamped auto) is a problem because as you say it does not handle overshoot whereas auto does.

I can only hope the default behavior of “clamp auto” in future releases handles this otherwise, if it wasn’t for this thread one could spend days trying to tweak it to get rid of the stalls, and it isn’t obvious where and how to fix something like this.

1 Like

The reason that clamp auto causes a stall is because it doesn’t know that you’re trying to split a single motion across different loops of the animation. In a different type of animation its default behavior would be desirable. For example, if this idle animation wasn’t meant to loop you’d want the trophy top to slowly come to a stop rather than stopping instantly. Thus, I doubt that the behavior of Clamped Auto is going to change because there’s not really anything wrong with it; the behavior just didn’t fit our purpose this time.

It’s true that someone could spend a lot of time figuring out why their animation isn’t doing what they want, but that’s naturally going to happen when they don’t fully understand what the engine is doing. But figuring out the issue leads to a better understanding of the engine, and conversely, gaining a better understanding of the engine helps to fix issues you’ll come across.

Also, what I was saying about overshoot is that Clamped Auto works to prevent overshoot, while Auto will allow things to overshoot. I don’t know for sure what happens when you overshoot, but my best guess is that, depending on how the object works, it either moves in a very abrupt, unnatural way, or, if it’s a physics object, it will continue to move past the value in the keyframe. So if our trophy head had a non-kinematic rigidbody, it would continue rotating after the animation ended because it hadn’t slowed to a stop.

1 Like

Yep, thanks Zach, I think I will quit will I am behind.

I get it thanks to your insights, I obviously need more practice, it’s a lot of fun though and learning to be proficient with the physics engine seems like it will save a lot of coding, I would imagine.

Thanks for taking the time and sharing your knowledge, much appreciated, and until the next one :slight_smile:

1 Like

Thanks, I’d likely not have found that on my own. :slight_smile:

1 Like

I tried smoothing it out with certain key frames but it still looked jerky. I decided to grab all of the key frames by shift clicking and setting them all to ‘both tangent’s-linear’.