Building a Stretchy IK Chain in Maya
Hello persons! I'm Wesley Wilson, 3D artist with Tiny Phoenix and I'm here to tell you all about building a stretchy Ik chain in Maya. Let's dive in and get started building the arm rig!
Start by making a 3 chain joint chain and naming the chain as shoulder_jnt, elbow_jnt, and wrist_jnt. It is important that you introduce a bit of a bend in the elbow in order for predictable IK behavior.
It is also crucially important to orient your joints so that the shoulder joint's X axis points towards the elbow joint, and the elbow joint's X axis points towards the wrist joint. This detail is critical when it comes to building our stretching functionality later. Orienting joints is also something anyone interested in rigging should become very familiar with. It is impossible to overstate the importance of joint orientations to any rig building involving joints.
We then will want to create an IK solver running from the shoulder to the wrist. Choose Skeleton, then click on the option box beside Create IK handle. We will be using a Rotate Plane Ik solver, as opposed to the other selection, a single chain solver. All the rest of the tools settings should be at the default position. If they are not, please click on Reset Tool, then change the solver type to rotate plane. Maya's Rotate Plane solver calculates the polevector of the IK chain in a predictable and stable fashion, making it ideal for it's use in building arm or leg rigs. Select the newly made IKhandle in maya's outliner and rename it "test_ikh".
Next we will make a control object to manipulate our IKchain. Creating control objects and understanding their transforms is critical in making a clean and stable rig. Choose create>nurbs primitives> nurbs circle. Rename this new control as "wrist_ctrl", then group this object while it is at the center of the world, with 0's in the translates and rotates. Rename this new group as "wrist_ctrl_grp". Now we need to position this new control where it will do the most good - the wrist joint. A quick trick for doing this is with parent constraints. Simply select the wrist joint, add the wrist control group to your selection, then navigate to constrain>parent option box. Modify the default settings by turning OFF maintain offset. When you apply the constraint you will see the control's group, and thus the control, have snapped to the wrist joint, perfectly matching the joints position and orientation. We need to delete this constraint by going to the outliner and selecting the constraint underneath the wrist control group.
After the control is in position, we are ready to attach it to our IK solver. The wrist control will control the IK chain via a parent constraint. select the control, then the IK handle, then click on parent constraint.
The wrist control cleanly controls the ik handle! Because we used groups for our control object, we can return it back to its starting position at anytime by simply entering 0's for the values in the channel box! But, we still have no control over the scaling of the joints.
Now, we need to control the scaling of the joint chain. This will require a SLIGHT amount of math and some use of maya utility nodes. We need to measure the length of our chain to determine the maximum length we can go before starting to stretch the joints. We also need a way to track the current chain length, so we know when to apply the stretching. This is what the distance measure node will do for us. To make a distance measure node, choose create>measure tool > distance tool. Click on the shoudler joint and the wrist joint and notice how the node gets created in the outliner with two new locators. Parent one of the new locators underneath the wrist ctrl and move it to the wrist ctrl. Move the other one to the shoulder joint. This next part involves the node editor and some simple math.
Open up the node editor and select the distance node in the outliner. Graph the connections in the node editor and find the shape node for the distance node. The attribute we are concerned about is the distance attribute in this node and we will use it in a formula to drive the scale of our joints intelligently. We will also need to create a multiplyDivide. Once created, map the distance into the input1X slot.
Change the operation of the multDiv node to be division and set the input2x value to the combined total of our elbow joint's and our wrist joint's translateX values. In my case, that number is 3 + 2.987. The reason we use the translate X of the elbow joint is because of the way we built our joints in teh very beginning of this. The X-axis points down the elbow joint towards the wrist joint and provides us with a distance between the two. In my case, the wrist joint is 3 units away from the elbow joint. These translate X values are also the maximum length of our joint chain. we want to divide the current distance (input1x) by the maximum length of our joint chain (input2x) inside our multiply divide node. we next need some way to use the resulting number to drive the stretching of our joints. This will be done conditionally, with there being conditions when we want the joints scaled and conditions when we would rather the joints not be scaled. So what better node to use than a condition node?!
In the node editor, create a condition node. The condition node works by comparing the first and second terms, using the operation you select. If the result is true, then the color if true is the result of the node, and if the result is false the color if false is the result. We want to compare actual chain's length to the maximum length. When the first term (the actual length) is greater than the second term (the maximum length), then our condition is true and we use the color if true result. Conversly, when the actual length is less than the maximum length, we should get the color if false as the result.
Let's plug the actual length of the chain (the distance attribute we also have plugged into our multiply divide node) into the first term slot of the condition node. the second term in the condition node should be the total maximum length of our chain, which is the input 2x value in our multiply divide node. Set the operation to greater than on the condition node, and we will need the result of the multiply divide node (it'll be called output X) plugged into the color if true R of our condition node. We are almost done.
The last thing we need to do is to channel the outcolor R number from the condition node into the shoulder and elbow joint's scale X attributes. Now take this knew found knowledge out for a spin and impress all your friends at parties!
Comments
Excellent Tutorial!
Wow, a perfectly explained tutorial! Great work and thanks
When I do this I get the
When I do this I get the error "Cycle on 'L_Arm_DIST_LOCShape2.worldPosition[0]' may not evaluate as expected.", and the IK will not stretch. I looked over this tutorial and others multiple times, is there something I'm doing wrong?
Hey Stef, I asked Wes about
Hey Stef, I asked Wes about this and he said it's most likely related to a faulty connection schema. If you upload the file you're working with and provide us a link we can help you trouble shoot!
Hi, this is a great tutorial!
Hi, this is a great tutorial! However, my arm is stretching only halfway to the controller. So if I move my controller 4 units away, my joints only stretch 2 units.
Hi Mike,
Hi Mike,
Thanks for the compliment! As for you problem, I can think of several reasons why it might be moving half as far as needed when stretching. It could be a node set to the wrong Operation or perhaps a connection to only one joint's scaleX instead of both joint's scaleX attribute or even simply a connection to the wrong two of the 3 necessary joints. I could speculate all day about what it could be.
If you would like to send me a copy of the file you are working with perhaps I could help you figure it out.
- Wes
Thanks! I got it working now.
Thanks! I got it working now. But I did have to parent the shoulder locator to the shouler joint so that I could move the main control around the scene without stretching the legs uncontrollably. It warps the locators but it seems to work like it should. My only other concern is scaling the stretchy ik with the rest of the rig. I did find a video by Jason Baskin about a workaround but it doesn't quite work for my rig and I keep getting cycle errors on the multiply/divide nodes. I'm also working with a unique quadruped. (A treasure chest mimic with little club feet)
Hi I can't seem to make it
Hi I can't seem to make it work. :(
Using maya 2017. Been trying this for an arm and leg IK stretch with IK/FK switching
Hello there,
Hello there,
Are you able to make it work with just an IK rig? How are you setting up your IK/FK switching? The tutorial is meant for a simple IK only rig, so the switching adds a level of complexity that might be breaking the system somewhere. I suggest getting the switching working on it's own, then getting the IK stretching working on it's own and *then* finding a way to combine the 2 intelligently to switch between FK and stretchy IK.
Thanks for the message!
This was helpful! How would
This was helpful! How would you add a switch to enable and disable stretch?
Add new comment