Working around the cycling bug

Have you come up with a good Moho trick? Need help solving an animation problem? Come on in.

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
torncanvas
Posts: 34
Joined: Wed Oct 31, 2007 12:22 am
Location: Des Moines, IA
Contact:

Working around the cycling bug

Post by torncanvas »

Going through my second walk cycle, I've noticed that the cycling feature of ASPro doesn't really work like it should. I think I've found a way to work around it, though.

First of all, I can't seem to get a symmetrical sin wave going. The interpolation for keyframes should be able to cycle when cycling is on, but I guess it doesn't. Here's an image of a "bad curve" where I tried to make it symmetrical in a 40-frame animation.

Image

To fix it, I create a keyframe one frame before the cycling one (frame 39) and play around with the values to smooth it out. The result is not something symmetrical, but at least it's not really noticeable in practice.

Image

Next is really the meat of the problem. Once I get the curve looking smooth in the timeline, there's a weird "catching" look to the animation right when it loops. It drives me crazy. I found out that the frame after the cycling frame that appears smooth on the curve actually has a different value than frame 1. So to fix the "catching," I copy the value from the frame after the cycling frame (for me, frame 41) to frame 1. Here is a before-and-after of the two curves multiplied on top of each other.

Image

As you can see, the bottom of the curve after the animation ends is a full frame off from the original. That's why I got the catching look, which can look really bad when you have a chain of bones and the catching is going on in 3 bones in a row.

Why does this happen? Well the root of the bug is this: the curve at the frame after the cycling keyframe is matched up to frame 2, instead of frame 1 like it should be. The following two images have frame 41 shown with frame 1 and frame 2 previewed, respectively.

Image
Image

The second one matches up, which is frame 2. So the fix for the bug would be to make my frame 41 match up with frame 1. This might even fix the first problem I'm showing.

But until then, make the curve look smooth, then copy the value from the frame after the cycling keyframe and paste that into frame 1.
////////////////////
http://www.intuitiongames.com
http://blog.intuitiongames.com
////////////////////
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

There is no bug from my experience. I think you may need a key on frame 1.

Your animation "starts" with frame 0 but generally that frame isn't included in the "loop" but still influences the motion. This means frame 1 is "moving" already due to the key frame after it.

Frame 1 is generally where the animation "starts". If there is no key on frame 1 then there is a "missing" frame in the cycle.

Maybe I don't understand what you are attempting to do, but the cycle key frame interpolation works fine for me... smooth and continuous looping.

-vern
User avatar
torncanvas
Posts: 34
Joined: Wed Oct 31, 2007 12:22 am
Location: Des Moines, IA
Contact:

Post by torncanvas »

I definitely had a keyframe on frame 1. Otherwise the animation would be all messed up.

I think you might be misunderstanding what is happening.

I'm trying to create a smoothly-curved animation. I have 2 problems:

1. I can't easily create a smooth, symmetrically-curved, n-framed animation. To fix that, I have to do more than just create a keyframe and the beginning, middle, and end. I have to put a keyframe one before the end (n-1) and then play with the values at frame 1, frame n, and frame n-1 to force the curve to be smooth where it cycles. The end result is acceptable until...

2. I played the looped animation and notice a "catching" effect. Like this:

Image

Right at the beginning of the animation, the neck swoops down at a velocity faster than any other time. That's because of a curve drawing bug, where the curve that is cycled skips a frame and starts on frame 2, instead of frame 1. Here's another image of what I'm talking about:

Image

You can see the curve is fairly smooth. Notice how I'm on the frame that should correspond to frame 1. And I am previewing the actual frame 1. They don't match up. If you draw a horizontal line over, the value of frame 1 is actually quite a bit higher than the rest of the curve that repeats. That's because the frame that I'm on - frame 41 - actually has the value that corresponds to frame 2. This is the bug. The value of frame 41 should correspond to frame 1 - that's what cycling should do.
////////////////////
http://www.intuitiongames.com
http://blog.intuitiongames.com
////////////////////
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

A very simple fix would be to just to change the starting frame. Move the starting frame of the animation to frame 2 or whatever. Then the cycling "glitch" doesn't become an issue.

I still can't reproduce the problem:

Image

This is a bone that is rotated as a cycle using 3 keys; frame 1 frame 18 and frame 40. Frame 40 is the same as frame 1. The last key frame (40) is set to cycle going back to frame 1. There is no "hitch". The bone rotates smoothly forever. I didn't have to add extra keys to smooth it out.

I must be missing something.

-vern
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I think I see the problem.

The cycle has to start and stop on the same position which in your screen captures it isn't:

Image

Frame 1 is not lined up. It will NEVER cycle properly. The key on frame 1 must be the same as the last frame of the cycle. This isn't a problem with cycled interpolation, I just checked and it works... as long as the first and last frames MATCH. This is the rule for all "cycling" animations. I do the same thing with walk cycles in Animation Master. You always copy the first key frame to the last key frame.

-vern
User avatar
slowtiger
Posts: 6243
Joined: Thu Feb 16, 2006 6:53 pm
Location: Berlin, Germany
Contact:

Post by slowtiger »

Hm, I never would spend that much time with adjusting curves - I just put in another keyframe and adjust so it looks good enough.

I had noticed that sometimes it wasn't possible to get a nice cycle starting at #1, so I just duplicated the keys and started somewhere else. This gets necessary also when I can't start the cycle anywhere but only at a certain position.

Very nice dinosaur btw.
User avatar
torncanvas
Posts: 34
Joined: Wed Oct 31, 2007 12:22 am
Location: Des Moines, IA
Contact:

Post by torncanvas »

heyvern wrote:I think I see the problem.

The cycle has to start and stop on the same position which in your screen captures it isn't:

Image

Frame 1 is not lined up. It will NEVER cycle properly. The key on frame 1 must be the same as the last frame of the cycle. This isn't a problem with cycled interpolation, I just checked and it works... as long as the first and last frames MATCH. This is the rule for all "cycling" animations. I do the same thing with walk cycles in Animation Master. You always copy the first key frame to the last key frame.

-vern
Thanks for your help, guys. I appreciate you trying to help me with this.

I realize that frame 1 doesn't match up. That's part of the problem I was trying to explain. If frame 1 doesn't line up at the beginning, it should be very obvious when you look at the curve for frame 41, too. This is because frame 41 should correspond with frame 1, since the animation is suppose to cycle.

I guess what I'm trying to do is to get a cycle going where there are NO copied frames. For instance, I want to get a swinging leg that goes through angles like:

1,1.2,1.5,2,3,4,4.5,4.8,5,4.8,4.5,4,3,2,1.5,1.2,1,1.2,1.5,2...

But if I copy the last frame to match the first, when I go to preview the cycle, wouldn't this happen?

1,1.2,1.5,2,3,4,4.5,4.8,5,4.8,4.5,4,3,2,1.5,1.2,1,1,1.2,1.5...

Because I had to make sure the first and last values are the same, I'd get those twice in a row. So one frame would be the same twice, which means I'd get the "hitch" effect or whatever. Right?

I guess I thought the whole point of cycling was to avoid having 2 of the same frames in a row while previewing an animation. This works similar to every other cycle that exists - like the moon phases for instance. There are no two days that are copied. Maybe I'm just used to animating in 3D though. All the 3d packages I've used work this way.

Am I missing something?

Thanks, tiger. :) Oh, I guess I can mention this now. Our game is Dinowaurs; we're one of the first devs part of Kongregate's Premium Development Program.
////////////////////
http://www.intuitiongames.com
http://blog.intuitiongames.com
////////////////////
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Okay I see the problem. You are correct, the loop doesn't pick up the curve from frame 1 because frame 0 is not the same as frame "40".

This however is not actually... a bug... unless a "pre-roll" or adjustable animatiion curve handles are added to AS.

The frame later in the loop that corresponds to frame 0 will never have the same curve. Frame 0 is the starting point and effects the curve of frame 1. All those adjustments you made to "smooth" the cycle was to account for frame 0.

Just start the cycle later in the animation. Get the beginning of the cycle (frame "1") away from the key on frame 0. Set the starting point of the animation to begin at a spot in the cycle where the curve is the same as the last key. You may need to copy and paste some keys to fill it in but the end result will be a perfectly smooth cycle:

Image

I went a bit further than necessary. You might be able to go back a "half" or "quarter" cycle.

EDIT:
The cycle interpolation doesn't seem to duplicate that beginning frame. I believe this is how it was designed. I can't see it in my tests but it may be too subtle to notice.

-vern
User avatar
torncanvas
Posts: 34
Joined: Wed Oct 31, 2007 12:22 am
Location: Des Moines, IA
Contact:

Post by torncanvas »

Yep, you're totally right. The cycling doesn't duplicate the last frame when it repeats. So I need to copy from frame 1 to the cycling keyframe, but just set the project settings to end one before that frame.

I guess I thought that the timeline moved according to the cycling keys themselves. I didn't realize that it's based on the project settings instead. So that's how you do it.

Thank you for figuring this out! Yeah!

By the way, is Auto Zoom supposed to be broken on the Mac? Mine never works, and it totally sucks...

EDIT: Nevermind, only works in edit mode. Got it.
////////////////////
http://www.intuitiongames.com
http://blog.intuitiongames.com
////////////////////
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Thank you for figuring this out! Yeah!
Thanks for bringing it up! I learned a lot in the process. I thought I knew what was going on with that frame 0/frame 1 looping thing but I never sat down and really documented what caused that "bump" in the cycle.

In Animation Master the 3D program I use, it has adjustable bias handles for the animation channels. It is a piece of cake to "match" curves for cycles like this.

While not exactly a bug in AS (it works the way it should) it is problematic that the curves can't be adjusted "by hand". For instance you could "tweak" the curve on frame 1 so it matched the other end of the curve at the end of the loop without being influenced by the key on frame 0.

That would be the perfect solution... but as always with me... I try to find the workaround. ;)

-vern
User avatar
torncanvas
Posts: 34
Joined: Wed Oct 31, 2007 12:22 am
Location: Des Moines, IA
Contact:

Post by torncanvas »

heyvern wrote: In Animation Master the 3D program I use, it has adjustable bias handles for the animation channels. It is a piece of cake to "match" curves for cycles like this.

While not exactly a bug in AS (it works the way it should) it is problematic that the curves can't be adjusted "by hand". For instance you could "tweak" the curve on frame 1 so it matched the other end of the curve at the end of the loop without being influenced by the key on frame 0.
Yeah, that's my #1 request. I saw the top 10 thread; I think for me, the first 3 would be that. And the next 3 would be an interface overhaul. :P

Overall though, I'm pretty impressed with this software. Now that I've figured this stuff out, I'm zooming right along here.
////////////////////
http://www.intuitiongames.com
http://blog.intuitiongames.com
////////////////////
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

DAGNABBIT!

Here's a simpler solution, doesn't require so many "extra" frames and a large offset.

Place the start of the cycle on frame 2 instead of frame 1. Copy the key on frame 2 to frame 1. Set the cycle to repeat from frame 2 and you get a perfect smooth cycle.

Works like a charm. You might still want to start the animation on frame 2 if that "extra" start frame is a problem. At least it isn't like... 20 frames from frame 1.

-vern
User avatar
slowtiger
Posts: 6243
Joined: Thu Feb 16, 2006 6:53 pm
Location: Berlin, Germany
Contact:

Post by slowtiger »

I just took a second look at all the examples, but didn't found what I was looking for. My question is: how long was your cycle?

If I want to do a 12 frame cycle, I put the first key on #1 and copy it to #13. This key #13 is set to cycle mode, relative, 12 frames. All cycles need one more frame than their length!
User avatar
torncanvas
Posts: 34
Joined: Wed Oct 31, 2007 12:22 am
Location: Des Moines, IA
Contact:

Post by torncanvas »

My cycle was 40 frames. Yeah, on my second walk cycle I've been putting the cycle keyframe on 41, and setting the project to end at frame 40. Everything is going well. :wink:
////////////////////
http://www.intuitiongames.com
http://blog.intuitiongames.com
////////////////////
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

slowtiger wrote:I just took a second look at all the examples, but didn't found what I was looking for. My question is: how long was your cycle?

If I want to do a 12 frame cycle, I put the first key on #1 and copy it to #13. This key #13 is set to cycle mode, relative, 12 frames. All cycles need one more frame than their length!
You have two choices for a cycle key frame: go back to a specific frame or go back exactly a certain number of frames. A 12 frame cycle would be frame 1 to frame 13. Technically that is 12 frames since 1 and 13 are the same. If you are on frame 13 and go back 12 frames you are on frame 1 again. The cycle key frame is designed for "looping" so one of the frames at the end or beginning is "dropped" to make the loop.

I like going to a specific frame because it is more flexible. You can extend the cycle key frame and it still goes back to the same frame. I don't think you need to add an extra frame for the cycle... it depends on how the cycle is set up. Basically the first and last frames of a cycle must be the same for a smooth repeating cycle. It is a "loop" within the animation.
I've been putting the cycle keyframe on 41, and setting the project to end at frame 40. Everything is going well.
I've been curious about what you are using these animations for. Are you just exporting a single cycle and repeating it elsewhere? Or is the animation going to be looping inside a larger animation within AS?

The reason I ask is that you don't need to use the cycle key frame interpolation if you just want to render a cycle. Just set the start and end frames at the right spot and render.

-vern
Post Reply