Wednesday, February 11, 2015

Animation Tips From a Programmer: How to Avoid Sliding Walk Cycles

Richard Williams Animator's Survival Kit walk cycle reference
This is for Flash animators, but the concepts should apply to other animation tools as well.

How do you avoid sliding walk cycles? Short answer: figure out your cycle's walk speed, and apply that to the tween.

What is a walk cycle? I'm sure you know it's an animation loop of a character walking in place. In Flash it's likely to be in a movie clip or graphic symbol. There are two ways to make it look like the character is actually walking rather than just walking in place.

1. The whole walk cycle symbol can be moved gradually to a new location, perhaps by having its coordinates "tweened."
2. The background can be scrolled while the walk cycle symbol stays in place.

Both methods can be used simultaneously, although that's slightly more complicated. Again, this shouldn't be anything new to any animators who are reading this.

So what is sliding? Sliding is when the character's feet (or foot substitutes in the case of some characters, perhaps non-humans) appear to slip forward or back instead of staying planted during each step, because the speed of the walk cycle isn't aligned with the speed of the character (or the background). If the symbol moves slower than the walk cycle, the feet will be sliding backwards. If the symbol moves too fast, the feet will slide forwards. It looks like they're doing the moonwalk.

How do you avoid sliding? In my experience, animators often just experiment by adjusting how fast they tween the symbol from one place to another until they have something that looks pretty good. But I have a more accurate way of ensuring your characters don't slide. First, you must calculate your walk speed.


Artwork by Sarah Duffield-Harding
Go to a frame in your walk cycle where one foot has just become planted on the ground. Perhaps in a guide layer, place a shape or symbol at that foot. It's probably best if you put it at the toe or the heel (the very front or the very back of the foot). Make a note of the shape's x and/or y coordinates, depending on which direction the walk cycle is moving. Then go to a later frame, just before the same foot starts to lift off the ground, and put a duplicate of the shape in the same place relative to the foot's new location (so at the toe if it was at the toe before, or the heel if it was the heel before). Now calculate the difference between the old and new x and/or y coordinates, and divide that difference by the difference in the frame numbers (the later frame minus the earlier frame, i.e. the amount of frames in that section of your animation). You may recognize this as the formula for finding an average, and that is what you're doing. That calculation will give you the average distance traveled per frame, i.e. your walk speed.



Note: You technically can pick any two frames where the same foot is on the ground, even two frames right next to each other, but you'll get the most accurate speed if you make the frames farther apart because you'll account for more frames that way. There might be variation in how far the foot moves in each frame, although a good animation should minimize that variation. It's a good idea to animate your walk cycle taking into account how many pixels you want your character to move per frame. Keep the speed in mind when you animate to begin with.
Artwork by Sarah Duffield-Harding

Don't worry if your answer is negative. Just use the absolute value (which means ignore the minus sign if there is one). Now that you know how fast the walk cycle is, you know how fast the walk cycle symbol or background should move across the stage.

If the background is scrolling for a set amount of time, you can figure out how many pixels to scroll your background by multiplying the amount of frames in the scrolling tween by your walk speed. If the background is scrolling for a set distance, you can match up your background's speed to your walk speed by dividing the distance by your walk speed and have the background scroll for that many frames.

Note: When calculating the amount of frames in a tween, you shouldn't count the first keyframe. That is to say you can calculate the amount of frames by subtracting the first keyframe of the tween from the last keyframe.

If the background is scrolling diagonally, you'll have two walk speeds: one for the x direction and one for the y direction. Just do the calculations for the x coordinates and the y coordinates separately. If the background is scrolling in a potentially infinite loop, just use the length of the loop as your set distance or time.

If the background is stationary and the character is moving, make a note of how far the character moves in the x or y directions. Just like with the background scrolling, divide that distance by your walk speed to determine how many frames your tween should be.

That's all for now! I hope I could help make your walk cycles look better, and please ask me any and all questions you might have.

4 comments:

  1. Replies
    1. Pixels are the tiny dots that pictures are made of on your computer screen.

      https://en.wikipedia.org/wiki/Pixel

      Delete
    2. Should probably site the author from whome your took your reference from.

      Delete

A Fond Farewell to Flash: Followup

Since there's only one month left in the year, I decided I should make a followup to my list of favorite Flash games . There are definit...