Basic IK/FK Switch
By, Tyler Thornock
Alright, to start it is pretty simple.
- Create a 3 joint chain (shoulder, elbow, wrist). Now these are
your bind joints. Name them appropriately. Make sure their
rotate axis are going the right directions. (make sure your rotation
mode is set to local for it to work right when testing the rotation)
- Now duplicate the bind chain twice and name one of them ik and the other fk. Now your setup should look like this:
- Next Place an IKHandle on the ik chain starting at the shoulder and
going to the wrist.
- Now create a control curve, and move it to the location of the wrist joint and freeze transformations.
- Alright, now point constrain (default settings are fine) the ikHandle to the control. Point constraints make the target object follow the translations of the control object.
- Now create a control for the pole vector and snap it to the elbow and freeze transformations (make sure you do this). Now to prevent the joints from moving to a different location when you apply the pole vector constraint the easiest way I found is to use the ikHandle's poleVector attributes to place the elbow control. A quick script to help you is:
//Select the elbow control and then the ikHandle
$sel = `ls -sl`;
//The following stuff gets the polevector's XY and Z and applys it to the elbow control.
//However, it MAY move the control to far/short, so you may need to change the value of
//2.5 higher or lower in order to place it correctly. (I had to raise it to 12)
setAttr ($sel+".tx") (`getAttr ($sel+".poleVectorX")` * 2.5);
setAttr ($sel+".ty") (`getAttr ($sel+".poleVectorY")` * 2.5);
setAttr ($sel+".tz") (`getAttr ($sel+".poleVectorZ")` * 2.5);
//This just freezes transforms on the control and applys the polevector constraint.
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $sel;
poleVectorConstraint -weight 1 $sel $sel;
Here is what my stuff looks like now:
- For simplicity's sake, this is all we are going to do with the ik setup.
- Now time for the fk. Now create 3 nurbsCircles and snap one to the Shoulder, Elbow, and Wrist. Now group each Circle once and snap the pivot point to the joint as well.
- Name the controls appropriately and the group node the same name as the control, except add "_Pad" at the end. Here is what it looks like now:
- Now orient constrain (default settings) the group node the the joint
(select the joint then the group node) and then delete the orient
constraint. This will make the control have the same rotation as
the joint...which is good, because if you didn't do this, then you would
have to rotate the elbow control on more then one axis to bend it right...and
it only bends in one directionso that is all you should have to rotate
- Next, orient constraint (default) the joint to the ctrl (select the ctrl then joint) and do these for the shoulder and elbow, for the wrist select the control and BIND wrist joint, not the fk wrist joint.
- Now it somewhat works, but we also want the elbow to bend with the shoulder and wrist with elbow and shoulder. To do this, you must select the shoulder control, and then the Elbow group node and orient constraint (turn maintain offset on!). Now to make the wrist follow, select the elbow control and then the Wrist group node and orient constraint (with maintain offset on).
- Now you FK controls rotate the arm correctly, but the controls dont move with the joints. You need to point constraint (default) the group node to the joint (select joint then group node).
- Yay, now the fk is finished. Here is how it looks now.
- All that is left now is to setup the ik/fk switching. First,
add an attribute called IK_FK to the WristFK control which has a minimum
of 0, max of 10 and default of 0.
- Now select the shoulder ik, shoulder fk, and finally the shoulder bind joints (in that order) then orient constraint (default). Do the same for the elbow. You don't have to do anything more for the wrist.
- If you move the ik or fk controls now the bind joints will follow each of them by half...which is not quite right. To finish the setup, we have to connect the IK_FK attribute to the orient constraints we just made. There a various ways to do this. But we will set it up using SDKs, though you could use a multiply divide node and a reverse node and connections, but that is a bit more confusing, so lets stay simple.
- Select the WristFK control, then click the IK_FK attr and then right click on the IK_FK attribute and select Set Driven Key.
- Click Load Driver and select IK_FK in the Set Driven Key window.
- Now open the outliner and select the Shoulder_b_orientConstraint1 and load it as the driven and select the W0 and W1 also in the Set Driven Key window..
- Now select the Shoulder_b_orientConstraint1 again and set the W0 to 1 and W1 to 0. This makes the bind joints just follow the ik joints.
- Now click key from the Set Driven Key window. This sets the default stat of the constraint.
- Now select the WristFK control and set IK_FK to 10.
- Finally select Shoulder_b_orientConstraint1 again and set the W0 to 0 and W1 to 1. Now the Shoulder's IKFK switch is setup. Do the same as you did for the shoulder to the elbow.
YAY! All done. Your ik/fk arm should work great :) You wrist
control will actually control the rotates of the bind wrist all the time,
which is ok.
Sample File from tutorial.