Blendering for Unity (Seven)

Animating

;

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.

The pose from last time.
The pose from last time.

First, close the left 3D viewport by dragging the bottom left corner icon of the right 3D viewport.

Closing the left viewport.
Closing the left 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.

Opening a panel on the bottom.
Opening a panel on the bottom.

Set the big left viewport's type to "Dope Sheet" with the Type Selector. The dope sheet is basically Blender's animation editor.

Setting the LEFT panel to the Dope Sheet.
Setting the LEFT panel to the Dope Sheet.

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.

Dope Sheet > Action Editor
Dope Sheet > Action Editor

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.

Setting the BOTTOM panel to the Timeline.
Setting the BOTTOM panel to the Timeline.

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.

Add a new Action, and activate Force.
Add a new Action, and activate Force.

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.

Adding a LocRotScale keyframe.
Adding a LocRotScale keyframe.
Adding a LocRotScale keyframe.
Adding a LocRotScale keyframe.

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.

Deleting keyframes.
Deleting keyframes.

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.

Inserting a keyframe.
Inserting a keyframe.
Moving keyframes.
Moving keyframes.

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.

Pasting the pose.
Pasting the pose.

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.

After a bunch of keyframing work.
After a bunch of keyframing work.

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!

Inserting keyframes.
Inserting keyframes.
Inserting keyframes.
Inserting keyframes.
Inserting keyframes.
Inserting keyframes.

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!

Continue to Part 8: Importing!

Comments

matcha

easiest tutorial I have ever seen in my entire life not just on blender but for any softwares ever bless and thank you so much

10/03/2018 17:27:45

Brian

What have I created.... <a href="http://imgur.com/pT41pdZ" rel="nofollow">

05/30/2014 22:05:57

Tim S.

I had lots of fun and learned a lot! Thanks for the tutorials! https://www.dropbox.com/s/hdkf7zn8v0thn1d/Screenshot%202014-06-13%2023.00.49.png https://www.dropbox.com/s/hdkf7zn8v0thn1d/Screenshot%202014-06-13%2023.00.49.png

06/14/2014 17:12:06

Tim S.

Whoopse https://www.dropbox.com/s/k0vr25z25brbgsm/Screenshot%202014-06-13%2022.58.36.png

06/14/2014 17:13:12

Marco

Something about mines scares me http://i.imgur.com/aq14Vmv.gif

06/15/2014 13:35:06

Zak

Hahaha that is FANTASTIC!

06/15/2014 19:38:22

Marco

lol, thanks

06/18/2014 09:18:49

Travis Stewart

I am trying to translate the root bone, but I cannot get it to move at all. I am in pose mode, I have selected the root bone, tried to use the grab tool by pressing G but nothing happens. I am able to rotate all of the other ones, but nothing seems to affect the root bone. Any idea what is going on?

10/19/2014 16:53:57

Zak

Hmm, my first thought is that maybe the transform location was locked somehow? When you have the root bone selected do you see the blue, green, and red arrows representing the three axes? If not, try opening the numbers panel with N and seeing if there are activated locks next to X, Y, and Z under location (they should all be 'unlocked', and <a href="http://zakjr.com/blog/?p=398" target="_blank" rel="nofollow">this image</a> shows what I'm talking about. Hopefully that's what the problem is, but if not let me know!

10/27/2014 13:35:34

Ted

You may want to add a note that you have to press <b>I</b> over the 3D view port. It doesn't show the same menu if you try it over anywhere else. This threw me off for a sec.

11/24/2014 19:23:38

Zak

Good point! I'll add a note.

11/25/2014 10:55:39

UnfoldedGleamingHarrier

Superb tutorial! Many thanks! Here's what I did with it http://gfycat.com/UnfoldedGleamingHarrier

02/26/2015 06:42:09

Aaron

WOo thanks for the tutorial!!!! very fun :D Here's my guy's animations http://imgur.com/a/oNFvS

10/17/2015 06:31:09

Zak

Nice job! Glad you enjoyed the tutorial!

10/19/2015 08:51:34

AnExoticLlama

Any suggestion on how to make the pause in the animation less noticeable? Bumped framerate up to 60, keyframes at {1, 30, 60, 90}. However, when it reaches the end of the animation and restarts, the animation appears to really slow down and "pause" for a moment. https://gfycat.com/MintyObedientBaiji

05/04/2016 01:10:49

Zak

I do have a way to work around that issue (it's especially apparent when you get into walk cycles!)-- it's not perfect, but it's easy and makes for a big improvement over doing nothing-- There are two things that I see happening here: The first is the little jitter when the loop repeats, which looks like an off-by-one kind of error either in the recording or the frame preview number (for example, if my last keyframe is on frame 50, I'll preview frames 0-49). The second and bigger issue is that the across-the-board keyframes at the beginning and end of the animation are being interpreted by Blender as full stops with no extrapolation, and that combines with the default easing keyframe interpolation to create a really slow-feeling pause, since it both eases in to the stop and eases out of it. A quick way to improve this is to set the extrapolation mode for the offending bones to linear, which will "swing" them through the break a little more smoothly. In the Dope Sheet, left click on the channel for your bone (there will be a slight horizontal highlight), open up the Channel menu in the Dope Sheet window's toolbar, then hit Extrapolation Mode -&gt; Linear Extrapolation. Here's a visual that'll hopefully help clarify a bit: <img src="http://zakjr.com/blog/wp-content/uploads/2016/05/b-u-w-extrapolation.png" alt="Blender Extrapolation" /> And to be honest with you, I haven't delved very deeply into animation beyond what I cover in this tutorial. If you're interested, I'd say a good starting point is to learn about F-Curves, which are basically the things that decide what happens between your keyframes. There's a good page on <a href="https://www.blender.org/manual/editors/graph_editor/fcurves.html" target="_blank" rel="nofollow">F-Curves in the Blender manual</a> that can give you a good basic understanding of how they work :) I hope this helped!

05/10/2016 21:27:49
Today