Full Body IK Solver in a Day

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:

  1. Add an event track to the animation system so the animations can tell the AI when the object should be attached.
  2. Make an animation for picking up the object and have it fire an attachment event.
  3. Add non-character dynamic items as a concept to the code.
  4. Add a simple attachment system to the character AI and rendering code.
  5. Write a quick full body IK system so the character doesn’t have to align with the item exactly.
  6. 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 place1.

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.

  1. When you’re making a video game, you really do have to create the basic laws of the universe, and then implement them; it’s kind of mind boggling that anything actually works. :) []


  1. jordy says:

    !!! Magic, thank you.

    • checker says:

      I was in the middle of writing this when I saw your other comment come in. Happy 3 month birthday. :)

  2. TheBigCheese says:

    Interesting IK. I’m definitely looking forward to this game.

    Keep the blog updated!

  3. Martijn Gerkes says:

    Looks awesome !! looking forward to more blogs ^^

    p.s. so what happens if 2 characters would try to pickup the same objects ? (if that where possible)

    • checker says:

      Right now, one character would just “win” based on who evaluated last, but I think the code would be slightly confused. It’s not much of an issue yet, since the AIs check for whether somebody is standing there before trying to pick up the statue, but once I have multiple Spy players in the same room, I’ll have to deal with this. I’ll probably have a “failure” animation where if you start to pick it up and somebody else grabs it first then you look surprised or something. This could be a good social norm violation type thing, where the person gets offended or whatever, and might be a tell depending on how often the AI makes that same mistake.

    • Martijn Gerkes says:

      does this mean you want to make the game more then only 1 vs 1 ?

      I’ll be anticipating a public version to give a try :)
      I’m highly interested in games likes this and Trouble in terrorist town, so i’m looking forward to the next blog post !

    • checker says:

      Yeah, there will be a ton of game modes. One of the other posts has a bunch of comments about some of the, I thing. 1 v 1 is just the first one I’ve prototyped, mostly because it exercises all the subsystems and I can go really deep with it to see where it leads. There will even be single player. :)

  4. jordy says:

    ^^ thx, That was a really nice blog update, very clear explanation, you really need to be a genius octopus to make a game all by yourself it seems, math, programming, art, gameplay, blog writing ^^, you name it.
    I’m looking forward to the half year anniversery, it really seems you’re picking up speed now.

    Keep up the good work!

  5. Josh Tilton says:

    Thanks for taking the time to record/post videos. The development process is so interesting, and gamers rarely get a chance to see it (particularly while it’s happening). It’s also great to be able to leave comments that will actually be read and replied to.

    On that note, I was wondering if you planned to release SpyParty on multiple platforms. I’m guessing PC and X-Box 360 because of your history and the controllers you’re testing with, but it’d kill me to follow the whole development process, only to realize I won’t be playing it on my PS3. I know it’s pretty early for that sort of decision-making, but I’ve just seen so many great games (especially independent titles) get snatched away or withheld indefinitely simply because one company pays for exclusivity.

    • checker says:

      Yeah, it’s too early to say on the platform. Personally, I would love to have it on all the platforms, but yeah, sometimes the platform holders try to use exclusivity to lock things up, which can definitely be a bummer for gamers. But, it’ll be a while before any decisions are made on that front.

      As for the controllers, I actualy tried to get DualShock support in, but Sony doesn’t make any drivers for the PC for the DS3 (the only drivers are these crazy unsigned Chinese ones that people have to post videos to help others get working), and none of my old DS2 -> USB adapters work right on Vista, so I kinda had to use 360 controllers! I have something like 10 DualShock2’s with USB adapters from the old Indie Game Jams that are all worthless now. I wish Sony would get a clue and make robust PC drivers for the DS3, even with bluetooth support, because I think a lot more game developers would develop on that controller if it “just worked”. It’s a drag to try to find and carry around wired 360 controllers. However, Microsoft makes it super easy to use 360 controllers on the PC–you just plug them in and call XInput–which is the same API as on the 360, which is why developers prototype with them.

  6. sascher says:

    Thanks for this! I think I’m beginning to achieve a level of programming fluency where I can grasp more complex procedural techniques and start to apply them, and I’ve been interested in IK since– er, probably since I snuck into your keynote at MIGS ’06, actually.

    I’m definitely going to hit up your SIGGRAPH paper too, though I don’t know how much familiarity with the topic it assumes.

  7. gaber says:

    I’m really excited to buy your game when its finished and I’ve been following since I read an article about you in Kotaku, but I was wondering, do you have to do this IK business on all parts involved in order to get fluid motion? Like I saw the fingers don’t really mold to the object, so do you have to do seperate IK on the fingers or do you just have an animation for that?

    • checker says:

      Well, you can decouple stuff, so no, you don’t really have to solve the fingers at the same time you solve the arms. You can phrase the problem that way, but it’s way more complicated. Most likely, you’d just have a “close” animation on the fingers, but it would be better to have a kind of IK grasping thing, where the amount the hand closes depends on the size of the thing it’s grabbing, like a martini glass stem versus a basket ball.

      But, the hands in the current prototype models don’t have any bones in them, so they can’t close. I’m trying to figure out whether I need fingers or just mittens. The more bones, the more overhead and the harder things are to animate, so I want to hit the knee of the curve of complexity and expressive payoff, and I still need to figure out where that is for this game.

  8. Isaac says:

    Are you doing this game all by yourself? That’s really amazing, but for the sake of the game I’d think it be great if you found other people to help you. I’m really excited for this game (especially it seems like on of the few that my crappy laptop can handle), and I’m also wondering will it just be limited to sniping? What about having two players in a building trying to poison each others martini glass? That might be asking for too much though (which is why I think having other people help you would be a good idea), also what are your thoughts on pricing, and a sequel?

    • checker says:

      Yep, currently it’s all me, all the time! Hardcore indie, man. In all seriousness, though, I’m probably going to get some help at some point. The key for me is to get the gameplay right before I increase the burn rate, and since I can do art that’s “good enough” for prototyping, there’s no particular rush to hire somebody.

      > will it just be limited to sniping?

      No, there will be a bunch of game modes, but the Spy vs. Sniper mode gets to a lot of the core mechanics, so it’s the one I’m starting with. I think there are some comment threads on other posts where I talk about some of the different game modes. I should really collect that stuff.

      “Poison Drink” as a mission is going in this summer, for sure. :)

      > pricing

      No idea yet. We’ll see what the landscape is like in a couple years.

      > sequel

      GAHHH! Let me focus on the first one first. :)

  9. jordy says:

    > couple years

    Ahem, let me correct: 1 year, 7 months, 28 days, 9 hours, 8 minutes and 5 seconds.

    I’m keeping track mind you ;), don’t DISAPPOINT ME!

  10. Tyler says:

    I have to tell you, my buddy and I have been watching you and this project since March. I am so glad the ball is rolling, again. I am so glad you’re doing what you’re doing, and I wish I could support you in ways more than words.

    But just know there’s a way larger following than you even think for this project. I would pray you can finish this strong and soon. Whatever happens, DON’T give up. And not for the fans. For you. Don’t let anything stop you from doing this – it’s your calling and you have something gold, here.

    Even if a big game publisher/developer comes offering anything, don’t let the project get out of your grasp. Video game concepts like this (on the same magnitude of the Portal series) only come along every few years.

    God Bless you, man! Keep the updates coming! :)

    • checker says:

      Thanks for the encouraging words! I definitely do not plan on giving up, and definitely plan on finishing strong. Soon is probably not in the cards, though. :)

    • Ron says:

      I think we all understand that making a game/this game will take some time, and definitely a serious commitment from you. No matter how much we whine that it isn’t coming soon enough, we are all graciously accepting that we truly can wait.

      And know that I’ve seen more that a fair share of crowd sourcing volunteers for different portions. You have something rare, people willing to commit to volunteer on a project just because they like the concept. Keep it up.

      (and happy birthday to me)

    • checker says:

      Thanks! And, I’ll do my part by keeping you guys posted…I’ve got a bunch of stuff to post, but I’ve been waiting until I get a server thing fixed. Hopefully in the next day or so.

  11. joey says:

    Talk about overkill. Just lerp him into exact position before performing the animation. This is what happens when you put a tech guy on game design ;)

    • checker says:

      Hah! And that’s what you get if you put a game design guy on aesthetics! :)

    • Ron says:

      With a game that is all about subtlety, a jumping animation is a dead giveaway. In this instance it’s not overkill whatsoever.

      captcha: kaffiyehs minicams

    • checker says:

      Well, you could have the npcs aim for a random spot and then align with the same code that aligns the Spy so it wouldn’t be a giveaway (I have the npcs adjust randomly occasionally, in fact, just to mess with the Sniper :), but I figured if I’m going to spend time, I might as well spend time on making the whole thing smoother, and the IK is key for a lot of stuff (picking up drinks, planting a bug on somebody, etc.). I’ll write more about it soon.

  12. runner says:

    I came across this website when looking for full-body IK, http://www.ikinema.com
    The demos look impressive on the maya implementation

  13. jordy says:

    That looks quite smooth indeed, do you need to buy such a thing?

I have temporarily disabled blog comments due to spammers, come join us on the SpyParty Discord if you have questions or comments!