Some Basics of IK

Cinema4DXL's IK system is very basic, but it may take some trial and error to get to grips with. There are a few tricks to building a reliable IK chain, and I will explain some of them by setting up in precise detail a very basic leg with you. I will also be using my 'IKtool' plugin, which simplyfies editing IK tags a whole lot. This plugin can be found on the Techniques page of this site, or you can click here to download right now: (5K).

create the bones setup

A good IK chain begins with setting up your chain of objects correctly. As IK works on the rotational values of the objects, it can't come as a surprise that the rotation the objects start out of influences the way that IK gets solved. I'll be using bones for this excersise, because they conveniently show clearly which way the Z axis is pointing, but it's just the same for all other objects. If you keep in mind to point the Z axis of an object always towards the next object in the chain (like bones almost automatically do) you will help IK calculations greatly.

Although this excersise will not explain how to set up a whole character rig, I will use some of my conventions of character rigs just to make the structure we're about to build a lot easier to animate.

First, create a bone, scale it (with the model tool!) to some convenient length, and rotate it so the Z axis point up, with the Y axis points to world Z. Call this bone 'root 00'. This bone will actually not be animated, but simply serves to have the next bone, the pelvis, start out with zero rotation.

Ctrl-drag this bone onto itself in the object manager, effectively making a copy of the bone as a child. Call this bone 'PELVIS". I myself always name objects that I'm going to animate in capitals, to distinguish them easily from other objects.

Now, with PELVIS selected, Ctrl-drag the bone's little orange handle to create a child bone. Point it in the direction that the left leg should be in, and drag it to the left leg's pivot point. Keep it rather small in length, as this is another 'null' bone, only there to influence the rotation of it's child. Name it 'L leg 00'.

Ctrl-drag the bone onto itself in the object manager again, name the resulting child bone 'L LEG U' (for Left leg Up). The rotation of this bone should be 0,0,0, which is an excellent starting point for the IK calculations. This is the first bone that will be in the actual IK chain, and it's parent, L leg 00, will be the anchor of this chain. Having the bones in the chain starting out near a rotation of 0,0,0 is helping IK calculations tremendously.

Scale L LEG U so it's end reaches the point where the knee should be, but be sure to do most of the rotation with it's parent, L leg 00. Once satisfied with the positioning, you're ready to create the lower leg bone.

So, in side view, Ctrl-drag the orange handle of L LEG U and create a bone called 'L leg d'. No caps here, we will probably not be meddling with this bone once the IK chain is working properly. Keep the bone pointing in the same direction as it's parent in the front view, but keep it slightly bent in the direction that it is going to be bent in. Even if your model has completely straigth legs, it is almost essential that you keep the knee slightly bent in the underlying bones structure, else you run the risk of the IK chain 'locking up' much too easy.

Ctrl-drag the heel-bone out of the L leg d bone, call it 'L foot', and drag an extra bone in the direction of the toes out of L foot, call it 'L foot ++'. You won't be animating these two bones directly, they're actually just there to give a bit of shape to the foot. In a real model,. you will probably want to add bones for the toes etc, but since this is an excersise in IK, I will stop here.

If all went correctly, you should have a chain something like this one:

I placed the whole structure somewhat higher, so the foot is resting on the world grid. Just a personal preference I guess.

adding the tags

Now let's add those tags to the objects that need one. First add an Anchor tag to L leg 00. Next, open up the IKtool dialog, select L LEG U, and press 'create tag' in IKtool. The upper leg bone now has an IK tag with the limits set to the current rotation. Turn off all limits for now (uncheck the checkboxes). Do the same for L leg d, but keep the limits checked there. L foot should also get an IK tag like this, though with limits unchecked.

I keep the limits of L LEG U completely free because that seems to greatly help IK calculations, it simply makes it far easier for c4d to come up with a solution. L foot doesn't even really need an IK tag, as we're going to add an IK expression to this one, and animate it's rotation otherwise, but it seems that nevertheless adding a tag makes IK calculations a bit more perdictable.

One extra step before we're going to actually set up the IK on this leg is to record the chain's current pose somewhere in negative time. This is again rather essential, especially as there are bones in there that have no limits whatsoever. Providing c4d this 'base' pose of the chain effectively means that you provide a pose for the IK calculations to start out from. If you don't do this, you may see the leg making wild turns once you've been animating the IK target a lot, because the starting pose of each IK calculation is effectively the result of the previous IK calculation. And I don't know if you've heard about chaos theory, but this comes pretty close :)

In other words, select L LEG U, and record a rotation keyframe for the whole hierarchy, I myself actually record a keyframe for every object and every animation channel (position, rotation and scale) just to be sure the structure I started out with is stored somewhere, and if I screw it up completely by some error in my expressions, I can always retrieve it. For now, we only really need rotational keyframes for L LEG U and all it's children.

now for the target object

For the IK chain to start working, we need a proper target object. We'll be targetting the footbone to this object, and use an expression to also keep it oriented like this target. But there is one problem: simply animating this null object isn't going to cut it, as that'd mean that you'd be rotating the foot around the ankle, something rather awkward if you're trying to keep the foot on the ground. It's much better to either rotate the foot around pivot in the heel or in the ball of the foot, both are points on the sole of the foot, and rotating around there would mean that you don't have to move the foot at all to keep it firmly placed on the ground. I'll be using the ball of the foot as a pivot point, because more leg-movements involve keeping the toes to the ground than keeping the heel to the ground.

Create a spline object and shape it roughly like the foot. I use a spline here because they're easily selectable, have shape, and never render. Be sure to take care that the bottom of the spline is also at the bottom of the foot, so you'll have instant feedback when placing the spline shape on a flat surface if the character's sole will touch the ground correctly, even when it is not visible. Also, make sure to have the axis center positioned on the location of your chosen pivot point for the foot.

Next add a null object to the scene, go to functions->transfer, fill in L foot, and turn all options on, and hit OK. This places the null in the exact position as where the foot is currently located. Link this null object to the spline shape. Call the spline 'L FOOT' and the null '+L foot'. You should have something like this:

Note the little orange dot at the ankle position: that's the null object you just placed. I also put an orange texture on the L FOOT controller object, making it easily distinguishabel. It could be handy to also record this controller object's position, rotation and scale, so you won't lose the state of the object where the IK chain perfectly fits.

the actual IK

Now we're finally ready to implement the actual IK itself. Select the L foot bone, and add an IK expression tag to it, fill in "+L foot". Move the controller object around. Dang, that doesn't look too good does it? That's because we didn't set the correct limits for the L leg d bone yet, it's completely rigid! So, with IKtool open, and the controller object somewhere at a plausible placement, select the L leg d bone and turn up the maximum P limit (it might be that you made a slightly different setup than me, and that you actually need to set the minimum P limit or one of the H limits). Look at the editor updating the IK solution untill it finds a limit where the solution can be found in. Great, the leg works! Set the L leg d limit so that the knee can bend completely backwards, but not forwards. Also, it's best to give just a few degrees of freedom in the other two axes (in my case H and B) so it's just that tad more easy for the leg to find a good solution.

In the scene I have here, it all works magically well. If that is not the case at your side, try to meddle some with the damping of the L LEG U bone - a bit of damping may do wonders, even if the limits are turned off, damping will just bring the leg closer to the basepose you recorded in negative time. Also, if the solutions are found, but you're not too satisfied with the pose, try rotating L LEG U in B and see what happens.

an expression to finish off

Ok, so the leg works fluidly, but the foot itself is still pointing everywhere, and not in the direction of the target object. This can be solved with a very simple expression. Add a new COFFEE expression tag to the L foot bone, drag it to behind the IK expression tag (so it is evaluated after this one) and type in the following:

   var pos=op->GetPosition();
   var sca=op->GetScale();
   op->SetMg(doc->FindObject("+L foot")->GetMg());
What this expression does is first store the object's current position and scale, then copy over the global matrix of the +L foot object (in other words: it's global position, rotation and scale) and then, since we're only really interested in the global rotation of the two objects, it restores the stored position and scale data. Try moving around and rotating the control object now :)

mirroring the structure

Now all you need to do is to mirror the complete structure to the right leg as well. The best way to do this is to actually rebuild the right leg, along with all IK settings etcetera (which actually isn't so much work!). In the case of this extremely simple and symmetric leg I just described, it's a simple matter of copying the leg over to the other side, but sometimes you actually need to mirror the structure, because it has asymmetric elements. But if you ever tried to mirror a set of bones by scaling them negatively, you may have come across a weird problem in which the bones pop into and out of their mirrored state whenever they're fixed and reset. Here then, to finish off, is a little trick that seems to surpass this problem and mirrors a bones structure including all IK limits.

First, turn off animation and expressions in the edit menu. Next add a null object to the scene, taking care to place it in the exact left-to-right middleplane of the character (so with the X axis pointing to one of the sides). Drag a copy of the to-be-mirrored structure into this null (in this case, the object L leg 00) as well as maybe controller objects, L FOOT in this case. Select the null object, switch to oject tool, and go to the coordinates manager. Set this to Scale instead of Size or Size+. Fill in -1 for the x scale, and press apply. Whallah! mirrored bones. But you're not done yet, this structure is completely useless. With the null selected, go to the menu function, choose Reset System, turn on all options, press OK.

Now, in the mirrored copies, turn all L's into R's (so +L foot becomes +R foot), and (very important) do this in the expression tags as well! In this case that is the IK expression tag and the COFFEE expression tag. Now, drag the objects to their correct places in the hierarchy, and if you recorded any data in the timeline on these objects, record it again. Turn expressions and animation back on, and it should all work just dandy!

There can be some problems with IK tags having to be readjusted in some cases, but now you have IKtool there can't be too much trouble with it, can there? :)


Go play with the structure you just built :) It's realy that easy to use IK, just drag the PELVIS and L FOOT and R FOOT objects around, and try to apply the same methods in your own characters. More difficult chains follow the same rules as simple ones like the one described above, and shouldn't be too much harder to achieve. Just to sum up the main points of above excersise once more:

  • Record a Base-pose for your IK chain as kind of a starting point for IK calculations
  • Try to keep angles close to zero in this base pose
  • Keep joints that should only bend a certain way always bent, even if only in the bones themselves and not the mesh.
  • Don't be afraid to free bones up completely - if there is a basepose, calculations will almost always come up with a solution close to this, especially if you also apply damping
  • If you can't free up a bone, like the knee, try giving the restricted axes at least a bit of freedom. Even a few degrees can do wonders for IK calculations
  • You can influence IK solutions by rotating the root of the chain (or any other bone for that matter)

Hope this all got you somewhere, maybe just seeing a chain reacting the way you'd expect will give you some more confidence in IK, as judging from some of the messages I see floating around in the Cinema4D forums I get the idea that people are loosing it :) IK can work for you pretty well as long as you keep some things in mind. Good luck!