Leg rigging V.2.1 By Matthew Chitty
This leg rig is a combination of various other rigs that I have used and found things that I liked and disliked about them. I decided to take the best of each and create one very stable and functional IK leg rig.
Building the bones
1. Under the systems panel and click the bones button then In the front viewport create a pelvis bone where you would like it to be in the model. Make sure to right click to end the chain so that you get One bone with a tip. Name this bone _R_BONE_pelvis dont bother to name the tip as it will be deleted soon.

2. Create a 3 bone leg chain in the left viewport, start chain by clicking on the pelvis bone and continuing from there the chain should start at the end of the pelvis boen where it meets the tip.

3. Delete the pelvis tip bone.

4. Starting at the end point of the 2nd leg bone create a 3 bone foot chain do this by clicking the bones button then clicking on the 2nd leg bone to start the new chain at the end of this bone not the tip bone.

5. name the bones name_BONE_R_legUpper, name_R_BONE_legLower, name_R_BONE_legTip, name_R_BONE_Foot, name_R_BONE_Toe, name_R_BONE_ToeTip
Where "name" is the name of your character that you are rigging. I like to have this prefix in case you have more that one rigged character in the scene.

6.Double click on the top legbone to select the whole chain then select character>bone tools in the bone tools panel expand the fin adjustment tools and add a front fin to all bones. (refernce for orientation)
Creating the IK chains
1. Create an HIsolver IK chain starting from legupper to R_BONE_leg_tip name name_R_IK_ankle.

2. Create an HIsolver IK chain starting from foot to toe name_R_IK_ball

3. Create an HIsolver IK chain starting from toe to toetip name_R_IK_toe
Creating the Helper and CTRL objects
1. Make sure you are in the perspective viewport and Create a helper Point object name_R_HELPER_ankle, align this new helper to BONE_legtip assure that the shapes local axis are matched to the bone tip.

2. Shift drag the helper to create 2 copies named _R_HELPER_toerotate _R_HELPER_toeLift.

3. Align(position) _R_HELPER_toelift to IK_toe, _HELPER_toerotate to _IK_ball and HELPER_toelift to IK_toe

4.
Shift scale the _R_CTRL_footroll down a little to make a copy name this copy HELPER_footroll.

5. In the left viewport pull down the HELPER_ankle helpers to match the level of the other two helpers.

6. Create a shape to act as controls for the foot. First create an Ngon shape and align/orient it to the Helper_ankle goal then drag the object down till it is level with the bottom of the models foot. Name this shape CTRL_foot.

7. Create a small circle shape and position it right at the back of the foot control shape. Name this shape CTRL_knee
Linking it all up
1. link IK_toe to HELPER_toerotate

2. link IK_ankle to HELPER_footroll

3. Link IK_ball to HELPER_footrol

4. Link HELPER_toerotate & HELPER_footroll to HELPER_toelift

5. Link HELPER_toelift to HELPER_ankle

6. Link HELPER_ankle to CTRL_foot

7. Create an orientation costraint for BONE_legtip to the helper_ankle (this will keep the foot flat to the ground when you drag the foot control out)

8. link BONE_foot to BONE_legtip

9. link CTRL_Knee to CTRL_foot
Creating a Knee control
1. create a helper point object in the perspective viewport and align it to the pivot of BONE_leglower name the helper name_R_HELPER_knee

2. Move the helper out on the y axis a good amount infront of the knee

3. select IK_ankle and goto the motionpanel under IK Solverproperties picktarget press button and select the HELPER_knee point.

4. link HELPER_knee to CTRL_knee

At this point we have a stable leg rig with lots of control and freedom. Using wiring parameters and some custom attributes we can make the rig a little easier to use when keying in animation.
Creating Custom attributes
1. Be sure to set the animation playback range from -1000 to 10000 wire controllers are active for the time frame that is set when you first create them. If you do need to extend the time frame after creation you can do it by rescaling time however it is easier just to create them with a huge time span from the start.

2. Place the Attribute holder modifer on the CTRL_foot to hold the custom scripted roll and rotate functions.

3. Select CTRL_foot then Goto Animation>Custom attributes to open the custom attributes panel.

4. Create a spinner named FootRoll with a range from -100 to 100 default at 0 click Add

5. Create a spinner named ToeRotate with a range from -100 to 100 default at 0 click Add

6. Close custom attributes window and look at the new attributes in the modify panel for the foot ctrl

Wiring it all up Have some work to do on making sure the expressions are completely stable.
Note: When wiring up the controls you may find that after you wire the attribute to the helper the foot twists into a strange position in this case you just need to select the control point that caused in and turn on angle snaps then in heirarchy panel click Affect Pivot Only and rotate the the pivot point till the foot goes back to its normal postion.

Also make sure to use the 'Attribute Holder' for the foot control attributes because I found that if you place the custom attributes on the root object there are stability issues when keying the foot animation.

Wire the' name_CTRL_R_foot' > Modified Object > Attibute Holder> Custom_Attributes> FootRoll to the X rotation of the 'name_R_HELPER_ankle helper'. In the attributes window click the arrow to pass the info from the FootRoll to the Helper.

Input this expression into the field.

if (footRoll <0) then
degToRad(0.6*footRoll);
else
0.0;


Then click the connect/update button to apply the wire to the object.
Now repeat this previous step but wire the FootRoll to the X Rotation of 'name_R_HELPER_footroll' using this expression.
if (footRoll >50) then
degToRad(50);
else if (footRoll >0) then
degToRad(footRoll);
else
0.0;

Repeat the wiring now for the 'name_R_HELPER_toelift' X Rotation using this expression.
if (footRoll >50) then
degToRad(1.5*(footRoll-50));
else
0.0;


Now the FootRoll attribute will control the foot roll forwards and backwards and can be keyed at the same time as the position track. The roll will have its own Curve in the curve editor also making tweaking the curves as one curve controls 3 seperate Helpers in your scene.

The final wire in the leg consists of wiring the custom atrribute ToeRotate to 'name_R_HELPER_toerotate' X Rotation using the following expression.

degToRad(ToeRotate)

The wiring is complete now for your Leg move the controls around and test the way it all works.

If at this point you notice that the toe or any part of the foot has flipped or rotated out of Wack dont worry we can easily fix this by going to the Hiearchy panel under Pivot and adjust the pivot point of the faulting Helper 180 Degrees around the X axis and this will correct the problem. ( I have had this happen a couple of times, and wanted to add the fix to this tutorial)

You can make the rig a little simpler by locking out the Transforms that you dont use eg: Move and Scale on the Knee CTRL.
This is done in the Heiarchy> Link Info panel.