Posted 05/10/2014 19:23:56 in Blendering for Unity
Updated 08/20/2017 17:46:08
We're ready to add some animations to our character! Like with previous steps, we'll want to set up the Blender UI to make animating our little guy much easier.
First, close the left 3D viewport by dragging the bottom left corner icon of the right 3D viewport.
Now, raise up a thin frame from the bottom using the same icon. Next, re-open a left frame, once again using the same icon.
Set the big left viewport's type to "Dope Sheet" with the Type Selector. The dope sheet is basically Blender's animation editor.
Change its editing mode to "Action Editor". This is the mode that allows you to work with a particular "action," and in the context of what we're doing, each "action" represents a separate animation clip in Unity.
Finally, change the type of the narrow bottom frame to "Timeline." The Timeline shows what frame you're on in the animation, and it provides a few playback controls. However, you'll want to keep in mind that it's mostly a read-only kind of tool, and you'll be doing the actual editing in the dope sheet.
I'll make a quick note here about a really useful, simple technique I use to plan out animations. I visualize the animation in my head while looking at a clock with a second hand. I play it over and over in my mind's eye, and try to come to a close approximation of how long it takes. We'll be starting by making an idle animation, so try to visualize it. The way I picture it, it takes about two seconds.
Click the "+ New" button to add a new action. Name it "Idle" by clicking on the word "Action" that popped up ("Action" is the default name, and I neglected to change it in the screenshot :/). Now, click on the F button directly to the right of where you typed in "Idle" and you'll see a 2 appear. Make sure you do this for every action you create!! Clicking on F forces Blender to attach the action to your model. If you don't do it and you have more than one action, Unity will only import one of them.
I'm going to take a minute to explain how keyframing works when it comes to animation. If you already have a good understanding of the concept, feel free to skip this paragraph. An animation basically consists of a collection of frames, which are stepped through by whatever is using the data. We'll be animating at 30 frames per second, so each frame will represent 1/30th of a second. Each bone will have a position, rotation, and scale for each frame, and when either Blender or Unity steps through the frames, the animator will place each bone where it should be. You could technically use a paper flipbook style of animating and manually set everything where you want for each individual frame, but it's much easier (and more efficient for Unity) to use keyframes. A keyframe is a set pose on a particular frame. When you set multiple keyframes, the animator will interpolate between them automatically, saving you a lot of work and the animator a lot of excess data.
There are also a few keyboard shortcuts that can really help out when you're animating:
Left Arrow: Navigate one frame backwards. Right Arrow: Navigate one frame forwards. Shift-Ctrl-Down Arrow: Navigate to the first frame in your action. Shift-Ctrl-Up Arrow: Navigate to the last frame in your action. Alt-A: Play and stop a preview of your animation. I (with mouse over the 3D viewport): Insert keyframe.
We're ready to start animating! When I visualized the idle animation, it took about two seconds. We're animating at 30 frames per second, so set the End value in the Timeline to 60. We want the animation to loop seamlessly, so we're going to want to add a keyframe at the beginning and a matching keyframe at the end. We'll just use the pose that we modeled our character in (well, you will... I forgot to undo the changes in my project after testing the rig so mine will look a bit different).
Make sure that you are navigated to the first frame (Shift-Ctrl-Down Arrow). Also, make sure that you have Pose Mode activated in your 3D viewport. Hit A to select all of your bones, then hit I to bring up the insert keyframe context menu. There is a smorgasbord of different options, most of which can be useful when creating more complex animations, but our actions are pretty simple so we'll only need one: LocRotScale. This will save the location, rotation, and scale of all your selected bones into a keyframe. Click that to add your first keyframe! Next, navigate to your last frame (make sure that you set the End field to 60, and hit Shift-Ctrl-Up Arrow), hit I again, and click LocRotScale once more.
When you add the keyframe, Blender will actually add a keyframe for each bone that you have selected. This is why you see a big list in the Dope Sheet.
We're just going to add one more keyframe for this animation, and we'll squish our character down to emulate breathing. Navigate to frame 30, either by using the __Left __and Right Arrow Keys or by clicking near it in the Timeline or Dope Sheet. Translate the Root bone down a bit using the grab tool, rotate each hip outwards enough to place the tips of the feet back on the ground, and play around with the arm rotations a bit to add some pizazz. Once you're happy with the pose, hit A to select all the bones, and hit I to insert another keyframe.
We're done with this animation! It's pretty simple, but with Blender interpolating between our keyframes it actually looks pretty nice! Hit Alt-A to see your work in action!
Let's add one more animation to this model. It'll be a jump, with a happy little arm flail at the apex. Click the + next to your Idle action to add a new action, name it "Jump", and click F__!!__ I can't stress this enough; it's a little thing that's easy to forget, but it's really annoying when you load your .blend into Unity and animations are missing.
When I visualized this animation, it was about a second long so set the length to 30 in the End field of the Timeline. You'll notice that your keyframes from the previous action are still there. Just like in the UV editor, in the Dope Sheet frame many of your transformation and selection tools will work the same way as they do in the 3D viewport. We want to delete everything beyond the first frame, so hit A to deselect all, then use the border select tool (B) to select all of the keyframes after the first one. Hit X to delete them. An alternative way would be to simply select the "keyframes" at the top (in the "Dope Sheet Summary" row), which represent the entire column of keyframes below them.
We want our character to crouch down a bit to prepare for the jump, so navigate to frame 4. Position her (him?) similarly to the lower pose in the Idle animation, but with the arms down. Insert the keyframe.
We'll hold our character at the apex of the jump while she's waving her arms, so we want to get her up there fairly quickly. Navigate to frame 10, and pose your character (translate the root upwards quite a ways, and rotate the arms up. You can also rotate and lock on the Z-axis to tilt the legs back a bit to add some extra cute). Insert the keyframe.
It'll be best to add an end point to the apex before we work on the arm flailing. We'll just copy what we already have to give a nice end to the apex. You should already have all the bones selected, so hit Ctrl-C to copy their positions! Navigate to frame 24 (we have 6 frames of the animation going up, so we should have 6 going down as well), and hit Ctrl-V to paste the pose! Insert a keyframe here.
We have 14 frames to work with during the apex (frame 10 to frame 24). Let's try to fit 3 arm movements in there: down, back up, back down, and then they'll go back up because of the "apex end" keyframe. The three keyframes will be at frames 14, 18, and 22, so each movement (besides the last, moving back to the keyframe we already have) will be 4 frames.
Navigate to frame 14, rotate the arms/shoulders down, and insert a keyframe. We have all the poses we need, so now it's just a matter of copying and pasting to create the arm movements:
Copy frame 10, paste it to frame 18, and insert the keyframe. Copy frame 14, paste it to frame 22, and insert the keyframe.It'd be nice if our character did a little squish on the landing before returning to the neutral pose, so copy frame 4, paste it a few frames before the end (I put it on frame 27), and insert the keyframe.
Hit Alt-A to preview the animation. It's good, but the arm wiggles are slower than I imagined. To fix this, select the middle group of keyframes in the Dope Sheet (starting and ending with the apex keyframes. Remember, A to deselect and B to use border select. Also, it might help to zoom in with the Mouse Wheel). Use the grab tool to move the frames left one or two frames to center the jump a little better. Next, navigate to the center frame of this group, and hit S to activate the scale tool. Scale works relative to the frame that you're currently navigated to, which is also represented by the vertical green line. Scale the keyframes down to quicken the flailing. Hit Alt-A again to see the final version of your work!
As a final note in case you're wondering what the orange bars between keyframes have been indicating, they represent no change between those particular keyframes. This can be useful information in many situations! Here you can use that information to confirm that the hips aren't moving at the apex (you could even delete the middle three keyframes to clean up the dope sheet), and you can identify bones that aren't moving that perhaps should be (e.g. if you wanted to add some movement to the legs during the jump apex).
Congratulations!! You've completely modeled, rigged, textured, and animated a character from scratch! All that's left is to import it into Unity, but that'll be a breeze since we've already taken the issues that Unity has with Blender into consideration!
By the way, I'd love to see the work of anyone who has completed these tutorials! Feel free to post screenshots in the comments!