Automatic character pose transition

Started by
12 comments, last by JoeJ 3 years ago

Does anyone know if there exists any code to automatically transition one character pose to another. For instance, between a fighting stance (with feet widely braced apart) to a neutral pose (with feet close together)?

The code would have to make the character take two steps to move the feet between one pose and the other. I guess it would use IK to do that.

Advertisement

@Ed Welch Hi Ed, I used animation blending to do this with skeletal animation. One important thing: you need to store your bone orientations as quaternions (not matrices). You can easily interpolate from one orientation to another using DirectX XMQuaternionSlerp(vQuaternion1, vQuaternion2,fPercent);

The quaternions in the above function represent the orientation of each bone, and fPercent is a float (0 to 1.0) representing the blending weights. I have my routines set up so I can blend from one animation (or pose) to another over the course of given number of seconds.

You'll also want to transition other variables, like position and scaling, but those are easy.

In addition to transitioning form different poses, you can blend totally different animations - like walking and waving for example.

Example:

Unfortunately interpolation doesn't always work well. For instance, if you use interpolation to transition between a wide-feet-apart pose, to a pose with the feet close together, the interpolation will make both feet will slide across the ground, which looks weird. The character needs to take two steps to transition between poses properly.

@Ed Welch I see, that would be a problem! If you have a Neutral to Stance1 animation, could you do something like play the animation in reverse (returning to the neutral stance) then play a Neural to Stance2 afterward? Another option would be to play a jump animation, while blending between stances. Then the sliding affect may not be too noticeable.

What I was thinking about is a method to automatically generate the transition animation using inverse kinetics. You need to fix the first foot in the location of pose 1, while moving second foot into location of pose 2. Then fix foot2, while moving foot one.

Ed Welch said:
You need to fix the first foot in the location of pose 1, while moving second foot into location of pose 2. Then fix foot2, while moving foot one.

Additionally, to look right you would need to move the center of mass over the single foot on ground before you can lift the other one up. Or to be more specific, plan the motion so the character maintains at least unstable balance while minimizing necessary joint torques. This is already beyond to what IK alone can do.

I did this with an inverted pendulum model matching character ragdoll, then using IK to map the pendulum back to character. It's a physics control problem very hard to solve.

Maybe you can get acceptable results by generating 2 poses where character COM is placed over left and right foot, and then use proposed blending methods using those poses as a midpoint.

@JoeJ Thanks for the answer. Seems like it's a difficult problem to solve alright

Ed Welch said:
Seems like it's a difficult problem to solve alright

For me yes, because i simulated a self balancing walking robot basically, using no animation at all. Took me quite some years to make it walking, and would take one or two more to use it for games.

But i would not say IK is that hard. Things like keeping a foot in place while playing animation isn't, and surely useful to have. Knee angle can be calculated from distance of pelvis to floor and Pythagoras. That's simple, the rest then only requires some experience with 3D rotations to align foot with floor normal, etc. A complex IK solver is necessary if the problem involves the whole body, but if we focus on individual limbs only, problem keeps small and it's no rocket science. And you have no need for true balancing either.

Unfortunately i don't know any IK lib or related papers, but per-limb-IK took me only a week or two to make, IIRC.

I don't think it's so easy. You have to fix the left foot to the ground, while moving the right foot to the target position. That seemly simple movement is changing the rotation of 5 joints: right knee, right thigh, pelvis, left thigh, left knee and left foot.

Not easy, but the problems are more of the tedious than the hard kind.

Likely you can assume pelvis and foot is ‘fixed’ (either by animation or from ground contact - drawn red).

The leg in air is irrelevant for the other leg, so we can ignore it completely.

Thus we focus only on upper and lower leg bones, with the knee angle being the unknown.
We can calc the knee angle from 3 given lengths: bone lengths (blue and green), and distance ankle - pelvis joints, which we assume to be fixed. Calculating the hinge angle of knee joint is no problem.

There is another another angle which is not constrained by given problem and remains free: Imagine the whole leg rotating around the red line. We can do this, while still solving the problem. This angle is often called ‘swivel angle’. Usually you just minimize the rotation it allows to keep it looking natural.
Drawn a circle to show where the knee could be:

It could be anywhere on this circle, within what other joint limits (hip and ankle joint) allow. So you just try to move the knee as little as possible from where it currently is to get a good swivel angle (It should not be necessary to calculate it at all).

To specify a solution in order, we could do like so:

  1. Calculate red circle from red line and target knee angle.
  2. find closest point from current knee to circle.
  3. rotate upper leg bone so knee reaches target.
  4. Set lower leg bone to reach target knee angle
  5. Ankle may be out of place, because knee is a hinge. Compensate this error with hip joint which is ball and socket so can do this.
  6. Finally rotate the foot so it's at target orientation.

Similar practice also works for arms. It's more complicated because the shoulder is free. So i move the shoulder towards the hand target if it's far away, or move it away if the target is too close. My argument is again: IK is that simple as long as we divide the body into those short chains involving only two or three major bones (legs, spine, arms). If we have a problem where this does not seem to suffice, we can just model those chains at a higher level for a coarse solution and go from there.
Ofc. it's still some work, especially if we need to consider joint limits, but i found out my work on including joint limits was never needed, because natural human motion rarely tends to violate joint limits. (Ofc. we don't want to bend a knee the wrong way around.)

Here's an old video where i've used this approach in a situation similar to your example problem:

This topic is closed to new replies.

Advertisement