teaching machines

CS 491 Lecture 20 – Armature Animations

April 14, 2016 by . Filed under gamedev3, lectures, spring 2016.

TODO

Lab

Today we’re going to animate a model that has been parented to or rigged with an armature. Our once inflexible models will at last be able to bend and contort!

If you finished your alien model, feel free to use it. Otherwise, I have made mine available.

Create a Unity project and drop your alien file (perhaps a copy) in its Assets directory. Double-click on it in Unity to open it in Blender. We want to make sure we’re editing the file that Unity is reading.

Goal

Creating step-by-step walkthroughs with images is a someday goal for this class. Before I can do that, I need more time and experience. In the meantime, here’s a snapshot of my armature:

Screen Shot 2016-04-14 at 9.07.46 AM

I’m not an experienced animator, so I probably have done a lot of terrible things from a professional’s viewpoint. But it gets the job done!

Pelvis

In Object Mode, hit Shift-A to add an Armature / Single Bone. As the first bone, it becomes the “root” bone that will be a parent to all others. If this bone moves, so do all the others. Typically the root bone is placed somewhere near a figure’s pelvis. We’ll move it in a second.

First, the bone is a little hard to see when its inside a model. Let’s turn on our x-ray vision. In the Properties panel, click on the figure in a T-pose to see the armature properties. Under Display, click X-Ray. The armature will no longer appear behind other geometry.

Now, click tab to go into Edit Mode. Click on the octahedron (called the body) between the endpoints to select the entire bone and translate it so that the wider end (the head) just appears outside the alien’s tail end. Select the narrow tip (the tail) and rotate it around the x-axis so that the bone is horizontal.

Name this bone Pelvis. You can do this in the bone properties. Get there by clicking on the button in the Properties panel with a bone icon.

Body

The rest of the armature will be an extrusion of the pelvis. In a side view, click on the narrow tail end of the pelvis. Hit E to extrude and drag the new bone’s head to right behind the mouth. Our goal when designing an armature is to span bones between joints of our model. If we want the mouth to open and close, we’ll need a joint just behind it with two bones branching at the joint for the upper and lower jaw.

Rename this bone Body.

Select the narrow tail of the Body bone. Extrude once to form the lower jaw. Name the bone Lower Jaw. Select the tail of Body again. Extrude for the upper jaw. Name the bone Upper Jaw.

View the armature from above. All these bones should be exactly centered on the x-axis. Fix any that aren’t.

Eyes

Now let’s add some bones for the limbs of our alien. This particular alien is symmetric (not all are), so we will save ourselves some effort by only creating bones on one side. I’m going to arbitrarily assume all work is done on the left side.

We’ll start by adding two bones to the eye “limb.” Click on the Body’s tail end. Extrude to the sharp bend in the eye stalk. Name the bone Stalk.L. If you’re working on the right side, name it Stalk.R. The L or R at the end is important for the mirroring that we will do later.

Extrude from the stalk to the eyeball. Name the bone Eye.L.

With the way the stalk is parented to the body, when the stalk bends, some of the body will bend with it. But we’d really like just the stalk to move. We need to “loosen” up the connection of the stalk bone to the body bone. Select the stalk bone and in the bone properties panel, uncheck Connected. Translate the stalk’s head on all three axes to where the stalk joins the alien’s body. Check its placement from all views.

Legs

In a side view, select the pelvis’ tail. Extrude to the alien’s knee. Name the bone Thigh.L. Extrude to the ankle. Name the bone Shin.L. Extrude to the toes. Name the bone Foot.L. (You may want two bones, one for each toe.)

Disconnect the thigh from the the pelvis and move the thigh head to where the thigh joins the alien’s body.

Mirroring

Now it’s time to generate the bones on the opposing side of the model. We will duplicate the left bones and mirror them. This isn’t nearly as automatic as the mirror modifier for geometry, probably because we usually want the bones to operate independently when we pose them.

First, we must establish the mirroring pivot point. Center the 3D cursor with Shift-S. In the 3D editor’s toolbar, change the pivot point to 3D cursor.

Select all the *.L bones, but none of the centered bones. Duplicate them with Shift-D. Move the mouse to affirm that you do indeed have duplicates, but hit Escape to restore their location so that they exactly overlap the source bones. Before doing anything else and losing your selection, select Mirror / X Global in the Armature menu.

With the right bones still selected, select Armature / Flip Names. This will rename all bones ending in .L so that they end in .R.

Let’s establish a link between the left and right bones. In the tools panel on the left, click on the Options tab. Check X-Axis Mirror. If you modify a .L bone in Edit Mode, it will automatically adjust the corresponding .R bone, and vice versa.

Parent

Switch to Object Mode. Select the alien model first. Then select the armature. Hit Control-P to parent the armature to the model with Automatic Weights. Now when you move a bone in Pose Mode, the surrounding geometry will move with it!

Idle

Let’s make an idle animation now. We’ll use the three-key sandwich approach.

With only the armature selected, head into Pose Mode. On the timeline, set the end frame to something like 96. (Most animations run at 24 frames per second by default. This means one cycle of our idle animation will take 4 seconds. Feel free to alter the speed if this feels too slow.)

Switch the timeline to the dope sheet. Switch the toolbar to show the Action Editor tools. Add a new animation and name it Idle. Click F to add a fake reference so that Blender doesn’t garbage collect it. Scrub to frame 1.

Grab the pelvis bone and translate it so that the alien’s feet rest on the origin. The rest of the alien should follow along with it given the way the bones are parented.

Set the pivot point to from 3D Cursor to Median Point. Now rotate various bones to make the alien feel like its shifting around in boredom. Maybe move an eye. Twist the body. Lift the tail. Close the mouth. Take creative license.

To confine the rotation to be around a particular axis, operate in a view along one of the cardinal axes, use the rotation transform manipulator, or use sequences like rx or rz.

Once you’re satisfied with the alien’s idleness at this frame, select all the bones with A. (Don’t forget this step.) Hit I to insert a Visual LocRot keyframe.

Scrub to frame 97 and insert an identical keyframe.

Scrub to frame 48. Manually invert the rotations that you applied in the surrounding keyframes. Once you’re satisfied, select all the bones and insert another keyframe.

Hit Alt-A or Option-A in the 3D editor to check your animation. Adjust and re-record as needed. Make sure you’re still in the Idle animation clip.

Importing into Unity

Save and head back to Unity. Does the Idle animation appear in the model’s import settings in the Inspector? Hopefully. Make sure it’s set to loop. Drag the alien into the scene.

Create an Alien Animator Controller asset and drop it onto the alien game object. Double-click on the animator controller and drop the Idle animation clip into the state machine.

Playtest. Does the alien play it’s idle animation?

Death

Back in Blender create another animation clip of the alien dying. You can reset the bone poses by selecting all in Pose Mode and hitting Alt-R or Option-R to reset the rotations. (Alt-G or Opt-G will reset their locations, which you don’t want to do to the pelvis. We intentionally moved it so that the feet were at the origin.) What body theatrics might you employ? Record keyframes to portray an agonizing demise.

Test it back in Unity. Add the clip to the state machine and create a trigger parameter that transitions to it.

Playtest. When you invoke the trigger through the state machine, does the alien die?