[MEL] beginner, IK leg stretch script


#1

I apologize if this is a common question. I’m rigging a human character and I’m following the Maya Learning Channel tutorials:
https://www.youtube.com/watch?v=iUPbO9-iEWs&list=PL8hZ6hQCGHMXKqaX9Og4Ow52jsU_Y5veH&index=13

This is the script I’m using to get my thigh and shin IK joints to stretch as I translate my foot control:

string $driver = “leftLeg_IK_lengthShape.distance”;
float $leftThighLength = getAttr (“leftShin_IK_JNT.translateX”);
float $leftShinLength = getAttr (“leftFoot_IK_JNT.translateX”);
float $sumLength = $leftThighLength + $leftShinLength;

setDrivenKeyframe -currentDriver $driver -driverValue $sumLength -attribute “translateX” -value $leftThighLength leftShin_IK_JNT;

setDrivenKeyframe -currentDriver $driver -driverValue ($sumLength2) -attribute “translateX” -value ($leftThighLength2) leftShin_IK_JNT;

setDrivenKeyframe -currentDriver $driver -driverValue $sumLength -attribute “translateX” -value $leftShinLength leftFoot_IK_JNT;

setDrivenKeyframe -currentDriver $driver -driverValue ($sumLength2) -attribute “translateX” -value ($leftShinLength2) leftFoot_IK_JNT;

When I execute these commands, my “knee” juts out (the thigh joint elongates) and it wont retain its shape. My joints are oriented as like the video, with no rotation or scale values. I have written this command with both tildas and with (" ") and have gotten the same result.

Trying to learn why this might happen and how to recognize it in the future. Thank you again for your help.


#2

Without seeing your rig this is a bit of a guess with some assumptions…

If your knee is bent in its default pose, then the leftLeg_IK_lengthShape.distance will be less than the sum of the two bone lengths. Normally an ik stretch solution will be made conditional on the leftLeg_IK_lengthShape.distance being greater than the sum of the two bone lengths before it has any effect. So, if less than, do nothing, if grater than apply the stretch. If you pull the ik handle until the bones are at 180deg with each other (ie knee straightened out), then run the code to created the sdk’s you might get something more like you expect. Make sure the the in-tangent on the first key is flat, so that the length isnt affected when the leg is bent.

David


#3

My working units were incorrect. One part of the process had them changed and I never changed them back to cm. But, I solved the problem without someone telling me the answer, so I guess that’s something, right?

I adjusted the graph editor like you recommended and it now transitions smoothly past max length. Thank you again.