Having recently ticked some big boxes with my ProxyMan tool, I'm now attempting to put in one more key bit of functionality - a simple inverse kinematics solver.
Now, I'm not a computer scientist. Far from it. But the things I want to do are fairly well-known in places like the gaming industry. If you're a game programmer, you probably do these things fairly routinely. And if you're a character animator, you'd use tools to do this fairly routinely. I'm attempting to program like one, so that I can use it like the other.
I've decided to split this functionality into two parts. I figured my kinematic solver generally needs to do two things:
- firstly: if the target goal is out of reach, point the chain towards the goal and control the overall chain rotation with a pole vector
- second: if the goal is within reach, bend all the chain joints so that the end of the chain meets the goal, while controlling the overall bend with a pole vector.
Funnily enough, the first one sounds like a 'look at' function. For those not familiar with this term, it's often used in 3D graphics programming to get some object (for example, a camera!) to look at a particular location. The idea I'm going with in the first point sounds not too dissimilar to this.
Below is an animated example of how an IK chain bends when a target goal is moved. A pole vector is not shown here, more on that further below. The link under the image goes to the original source.

So, inverse kinematics is like your arm. You do these things everyday. Put your hand on a table top. If you move your body while keeping your hand where it is, your elbow and shoulder will adjust and bend to keep the hand on the table. If you move your body away too far, your hand comes away from the table. Your body is capable of IK in a number of places. It's in your arms, legs, spine, neck, fingers, among others. Your whole body can act like an IK chain - it's not just in your limbs!
I mentioned I was splitting this task into two phases. The first bit I'm tackling is to work out how to point things in the right direction, and bend them towards a pole. This would be a good first box to tick, as it'll flow into the second part. To test my code, I'm using an experimental object I made. It's a simpler object that's quicker to build, and is smaller and easier to work with.
Within this first step, we need to achieve two things: pointing the chain towards a target goal, and controlling the chain's overall rotation using a pole vector. Using the elbow or knee as an example, simply put, a pole lets you kind of rotate your bend towards a certain direction. Think of it likes this. If you sit in a chair with your foot on the floor, your knee can point forward, or off to the side. A pole vector helps you 'point your knee' forward or to the side. It's an important part of the IK system, if you didn't have a pole vector, your knee might bend backwards - ouch! If you want to see a IK leg rig in action, check out the video at the end of this post. It's more of a 'how to' for another 3D program, but you'll get the idea.
And - I've so far managed to successfully get the first part working. It took me some time to figure out. But I was able to borrow some code from my ProxyMan tool to help myself out. Below is a series of rendered images that show the result. It also shows the pole rotation.
Just to briefly explain the images below - the white rectangle on the left side is our target object (what we want to point at), the joints in the middle are our simple arm joint structure, and the black triangle on the right-hand side is our pole vector. There's also a flat rectangle polygon object sitting at the elbow. I added this just to check that the chain rotates using the triangle pole as it moves.




Use the image comparison below to see how the pole vector helps control the rotation of the chain.


The pole vector is used to keep the elbow or knee pointing towards something, otherwise the program has no idea how to align it all. Another thing I haven't said much on, but which is important, is that I also added the ability to move towards the goal by a certain percent. That is, I can control how much the IK system bends the chain towards the goal. This will be important later, as when I move the code into my ProxyMan tool, I'll be able to use all the clip blending attributes to control how much things are bent by the IK calculations! This will be really neat, I think.
Now that I've figured the first part out, the remaining bit to tackle is the tricky bit. This involves getting the chain to bend so that it can match a target goal that's within reach. This 'seems' fairly easy to do if you just reposition things. However, I'm trying to do this in a rotational way. From what I can tell, this much trickier. But I'll press on, it's the last major thing to figure out now.
Example IK video
Here's the video on a leg IK rig. It's for another animation program (Blender) but the ideas of how and why you use IK are all the same.
