2010/06/08, 19:49 by checker

I am finally nearing the end of the list I made almost two months ago to get picking up and interacting with objects working in SpyParty. Here is is again:

Add an event track to the animation system so the animations can tell the AI when the object should be attached. Make an animation for picking up the object and have it fire an attachment event. Add non-character dynamic items as a concept to the code. Add a simple attachment system to the character AI and rendering code. Write a quick full body IK system so the character doesn’t have to align with the item exactly. Hook it all up.

Steps 3 and 4 were discussed in this post.

In the original post, Step 5 had this footnote:

“This is a step that might give some people pause, but I’ve written so many IK solvers over the years that I figure I can whip this out in a day or so. Famous last words.”

Well, I managed to get a full body IK solver mostly working on Sunday. Admittedly, it was a 12 hour day, but still, not bad if I do say so myself.

Briefly, IK stands for Inverse Kinematics. Kinematics is the study of how things move through time and space. Taking the simple example of your arm, Forward Kinematics is about how your hand moves when you change the joint angles at your shoulder and your elbow. You might rotate your elbow by 30 degrees, and figuring out where your hand ends up is a Forward Kinematics problem. As you might imagine, it’s somewhat difficult to pick up objects if you have to manually specify the shoulder and elbow angles to move the hand towards the object. Worse, if you change the shoulder angle, obviously the elbow angle has to change to keep the hand in the same place, since your arm is hierarchical.

Inverse Kinematics is the solution to this problem. Where FK says, “given the joint angles, where is the hand?”, IK inverts that and says, “given the desired hand position and orientation, what are the joint angles to get there?” There is some more math involved in solving IK problems compared to FK problems, but it allows you to control the arm from the hand and the shoulder and elbow joints figure themselves out.

One interesting point is that the FK problem always has a solution: for any joint angles at your shoulder and elbow, your hand will end up somewhere. By contrast, the IK problem doesn’t always have a solution: if I ask the IK solver what joint angles will put your hand on the moon, it had better give back either “none” or something reasonable like angles that point your hand towards the moon.

So, that’s the Kinematics lesson for today, let’s get to the examples. Remember, all of this art is temporary prototype placeholder artwork!

First, here’s a video of a character interacting with a statue in SpyParty, where the character is aligned with the statue in the same way the animation was created, so it all lines up nicely:

Now, since there’s no IK in the game yet, here’s what happens if you don’t align exactly right:

The statue still attaches to the character’s hand, due to Step 4 above, it’s just that the hand isn’t aligned with the statue correctly. So, when the attachment event fires in the animation, the code detaches the statue from the pedestal and attaches it to the hand in the wrong place .

And finally, after Sunday, here’s a video of the IK working in the SpyParty contentviewer, which is a simple little application for testing animations and models and whatnot. It’s way easier to make changes in the contentviewer and then move the code into the game than it is to make changes in the game with AI running and all that other stuff.

As you can see, the new IK system still needs a ton of tuning, but that was the result after the 12 hours and it felt pretty good. I think I’ll spend another day on the core math to tune it a bit, and then I need to put the IK code into the game and do Step 6 to hook it all up.

I’m doing IK a little differently than most games do, using learning from my work on Spore. Most games use IK to simply pull the hand towards the object when the animation says to use IK, but what we did on Spore was a little different, and I think, better. Instead of IKing the hand to the object, I warp the whole animation as the IK blends in, so the torso bends and all the little stylistic tangential movements still show up, only now they’re aimed towards the object rather than just straight ahead. I’m going to post more detail about this technique once I get it cleaned up, but you can read the super-detailed technical description of the Spore IK solver in the SIGGRAPH paper we wrote about the technology if you want to know more now.

Edit: You can actually see the results of the animation warping in that video, because the left hand is not being IK’d directly to its hardpoint at all, the only thing changing its position is the space warping, and you can see it’s in the neighborhood of the other hardpoint even without an IK fixup. This is one of the huge advantages of this method, it preserves the animator’s source poses as much as possible, so the IK itself is only used to polish up the pose for the new configuration. This is the blend of sampling and synthesis I’ve talked about before in lectures, where you want to augment the animator’s work with the computer’s work, not replace one with the other.