Animating Arms and Legs

As a programmer, it's usually good practice to look for generalizations. For instance, an algorithm that could only sort names of vegetables is probably less useful than an algorithm that can sort any set of strings.

The typical approach to an animation system in games is to define a skeleton, a collection of bones together with joints, and then associate mesh data with this. The skeleton itself can then simply be animated, e.g., to walk like a human, and the mesh will follow. This animated skeleton can be reused by any humanoid-shaped object in the game.

This is an example of a useful generalization.

Specificity

There is a catch to how we think about general solutions, however. The human brain looks for patterns and lumps things together when it finds them. A skeletal animation system is a way of lumping together all humans' possible movements into a "box" (collection of animations of that skeleton.)

Nature, however, tends to be annoying with specificity. The periodic table of the elements is a great example of this. On the one hand, elements can be understood according to their atomic number, and many chemical reactions can be predicted based on this together with an understanding of valence shells.

However: the very specifics of these valence shells, together with the relative strengths of the forces involved, means that surprising things happen. And the valence shells themselves are explained in terms of the specifics of group theory (I think.)

So while our "box" or model works in this case quite well, it is not the whole story. Nature cares a lot about specifics.

There is always a tradeoff, when we implement general systems. These tradeoffs are usually less-obvious to us than the benefit of the general system, because our brain hates to break up a perfectly-satisfying or understood pattern.

Take the above seemingly silly analogy about an algorithm that can sort only the names of vegetables. By limiting it in this way, for instance, we could fairly simply enumerate the names of all known vegetables and have that imbedded into the algorithm. There are many implications to this, which could affect the behaviour or performance of the algorithm versus one that sorts strings generally.

In fact, we could quite feasibly use a bucket sort in this case, since there are only a small number of names of vegetables, which is O(n). What seems like a sort-of silly specification at first glance actually involves a real tradeoff.

Animating Arms and Legs

So what happens if we want to animate just arms and legs, rather than a full and arbitrary skeleton. What are the implications of this?

I puzzled over this recently and came to a certain realization: an arm or leg is not just a small collection of bones connected by joints-- it is a very specific kind of system evolved by nature for very specific reasons.

Let's just talk about arms for now.

You shoulder is like an anchor point, and has a relatively high degree of freedom. It can move along two axes, generally speaking.

Forgetting the elbow for a second, and lets consider your hand as a single point. The purpose of your hand is to manipulate things.

Now, what you want is to be able to move you hand around to touch things, to do things. Your shoulder is going to be attached to your body. It's relatively expensive to move your body. So your arm's purpose in some sense is to let your hand move independant of your body. Compare it to the fin of a porpoise, which is more or less attached directly.

Circles and Spheres of Influence

It is far, far more useful to you if your hand can be any distance r from your body, rather than a fixed distance.

If r is fixed, you get a situation like this:

A human arm is say about 1m long. Imagine only being able to use your hands on objects that were exactly 1m from your body.

But now imagine r can change, somehow (perhaps we have a telescopic arm):

How Does Biology Accomplish This

The 150 million year question:

By now you can probably guess the answer:

Looking at this diagram, r can change, but s and t (your forearm and upper arm, respectively) don't need to change. So there can be a big ol' bone there.

The real purpose of your elbows is of course the elbow-smash, but secondary to that it's to let your hands' distance to your shoulders' vary freely. Either hand can then access any point in a roughly sphere-shaped area centered at it's shoulder. If you're lucky, YOU EVEN HAVE TWO OF THEM! Crazy.

Some Math Notes

One further specification. If you work out the math you'll soon discover that it's much, much simpler if s = t, above. And in fact, if one is much different than the other, you end up not with a sphere of influence but a spherical shell. Not quite a spherical surface but also not nearly as useful.

So if you notice your arms, the forearm and upper arm are about the same length. The same is true four your upper and lower leg part (thigh and calf.)

So in fact in the diagram above you could just label everything that is now labeled s or t with only one variable. Nature seems to have decided this is the appropriate optimization.

What This Gets Us

What this gets us, in practical terms, is a kind-of system that allows us to create the proper bone-shape for animation purposes, depending on only two variables.

Variable one is the orientation and position of the shoulder (i.e., which was is front, side and up, and what point in physical space.) Variable two is the position of the hand.

Thinking in terms of gameplay, this is fairly easy to specify. If means if we want to show the hand moving towards a button, we can do it.

It won't look as natural as a keyframe skeletal animation, since your brain makes many further specific choices as to the unique physiology of the arm (e.g., where are the muscles, actually, and what is the actual range of motion of your shoulder.)

This type of system is sometimes called inverse kinematics. I.e., the calculation of an animated skeletal motion based on the desired position of part of it. Games have largely abandoned this (except ragdolls, if you consider that to be IK) because of the further specifics mentioned. Basically, it doesn't look quite right.

But for the purposes of the specific problem I had at hand, it was the right solution. For myself, all I needed was some insight into the specifics of why elbows and knees are the way they are.

2012-07-26

◀ Back