Thursday, March 14, 2013

Rushy Anim Tut for Walk-cycles


Update: most of what is contained in this video is still valid as far as it goes, however I have now moved to Spine for my in-game animations.  I will still be using AS9 for cut-scenes.

Check the post I wrote about Spine character animation for more details on that amazing tech.

---

This is a very quick export of first walk-cycle animations, showing a bit of how I work.  I'm still in the middle of working on this so its rough, but I thought I would take this moment to cover what I have learned for my in-game character animations.

First can I say that AS9 Pro is very good for this job.  Combined with TexturePacker this process gives you a set of sprites in a sprite sheet that you can drop right into your Cocos2D game.

The horizontal lines show my method for getting the walk correct.  I recommend this excellent tutorial on the fundamentals of the walk-cycle at AngryAnimator.com - refer there for the meaning of the pose names and to explain the lines.  That tut is for pencil-and-paper cel animation but its by far the best of any tutorial I have seen yet.  The best insight it has that you need to base your cycle around the contact pose, which is when the legs are at their farthest apart.

There are some differences taking Angry Animator's method to the 2d-bone animation technique, but most of it is the same.  In the computer-animation your big bug-bear is skating/sliding.  To fix this I do the animation with a translation (so the character moves across the room as well as pumping his/her legs) and this allows me to mark the foot-falls and retro fit the feet to the marks.  This seems to fix skating quite nicely.

To get my sprites the right size I use one of my game rooms as a background and then I can position the character at the largest size it will need to be against that room.  Then when I do the export the Anime Studio camera is set at the same size as the background, so the PNG's that are exported have the character sprites at the correct size.  Because I use TexturePacker I don't have to worry about the vast amounts of transparent pixels all around each PNG frame exported: TP will remove that and pack the actual sprite into the sheet.  (Note, I have made a terrible job of this part in the sample files shown here -   but they are just for illustration only).

Having the game background also allows me to do the sprite sheets for other animations such as sitting down on the bed, reaching for the window and so on.  Here I'm just talking about the walk animation.

Here is my process:  I do my animations as a walk with translation by:
  • Set the animation marker to frame 0
  • Draw and rig the character
  • Draw the guide lines on a seperate layer based off your character
  • Pose the bones to the contact pose; left-leg in front
    • This counts as your first step/foot-fall
    • Mark its position on the guide line layer
  • Measure out 3 more strides to find the foot-fall points on the guide lines
    • Temporarily translate the character in its contact pose
      • Using legs & feet like a pair of dividers
      • Mark each foot-fall positioning the back foot at a mark
      • Then do mark a new foot-fall at the front foot
    • To mark I use Anime Studio's "note" feature
  • Translate the whole character so that the 4 strides take 48 frames by
    • Move the animation marker to frame 48
    • Translate to the final marked position at 4 strides completed (4 steps/foot-falls)
    • Don't use bone translate for this - use whole-character-layer translate
  • Go back to frame 0 (contact pose; left-leg in front)
  • Copy the contact pose at frame 0 to 24 and 48
  • Create the opposite contact poses at frames 12 and copy to frame 36
    • See Angry Animator's tutorial
    • Use the Z move bone tool to switch the legs over
    • Keep the character at the same height
  • Now add the recoil poses at 2 and copy to 26
    • Use the translate bone  on the root bone (not the whole character) tool
    • move the character down to the lower guide mark for the head
    • The recoil is the lowest pose so head-height  should be checked carefully
    • Adjust the feet to the foot-fall marks so they don't skate or slide
    • Adjust the legs to the "sink" pose so the feet are still on the lines despite the lowering
  • Copy the recoil pose to 14 (and dup to 38)
    • Copying key frames makes sure you get the height & attitude right
    • Switch the legs front-for-back to get the correct opposite pose
    • Make sure you don't change the height of the recoil when doing this
  • Do the high-point at 8 (and copy to 32)
    • As for the recoil use translate bone on the root bone to move character up
    • Copy these forward as for the recoil and switch to get the opposites at 20 & 44
  • Do the passing pose at 6 (and copy to 30)
    • Do the opposite passing poses at 18 & 42
  • Add in hand-arm swing, bending the elbows
  • Add in some head bob, and other movements
    • I did ponytail up in the recoil and down in the highpoint
Once complete, run the animation through on loop mode over and over, looking for timing issues, mistakes and unevenness.  Tweak as necessary.

I find its impossible to do this without the translation in the animation (as above) especially with respect to removing/reducing skating, where the characters feet slide or "moon-walk" across the ground.  Also, even though technically you could do all the above in 24 frames instead of 48 I find it much easier to have the extra framing so I can see what I'm doing.

Once everything is golden, you're ready to create game art.

Choose the key frame channel for whole-of-character translation (not bone translation) and delete it.  This will remove the character animation that does the travel across the room, and leave all of the bone translations and rotations done for the walk-cycle itself.  If this somehow removes your height adjustments done for the recoil or high-point poses (because you used whole of character translate instead of bone translate) then undo the delete, and go back - carefully remove the bad keys and replace with bone translate keys.  See the above.

At this point playing the animation should show your character doing a 48 frame in place walk-cycle, with nothing else on the screen.  Now to export game ready art, hide the guide lines, any background images used for scale and go ahead and choose "Export Animation".

Select the PNG exporter from the drop-down.

You only need to select 25 frames of the above animation.  I do a full 48 frames so I can select the part that looks good, and because I find its easier to check the animation for errors.

If you go with the passing pose as your start frame then it works well with a standing character moving into a walk because the feet are together, and then one picks up and starts walking.  To do that, in the export dialog choose 18 as the start frame and 42 as the end frame.

At this point you also have the choice to export at half-frame rate by checking "Render at half frame-rate" on the export dialog.  This will give you 13 frames when exporting frames 18 to 42, and 12 frames per-second is probably OK for most games.  If you need 24 frames a second leave this box unchecked and you'll get 25 frames.

Run the export, choosing a folder (use create folder if needed) to put the frames into.  Don't worry about background colour - PNG export by default will alpha out all the background for you.

Now you can use Texture Packer to put the frames into a sprite sheet, by dragging and dropping the folder you exported the PNG files to.  Follow Ray Wenderlich's excellent tutorial for this - I won't repeat the details here.

The sort of result you get is as here (although this is a PNG sheet).  

Note that I have done a power-of-two sheet with my crazily large sprites.  This sheet is 2048x2048 (fine for desktop but bloated for mobile).  You can (and should) do a non-power-of-two (NPOT) sheet if you know that your platform supports it.  Most new platforms do.  Also using the pvr.ccz compressed PVR format will give a good result in sprite sheet size with fast loading times as well on mobile - check the Wenderlich tutorial for more details.

No comments:

Post a Comment