Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Dan Ebbert’s Inverse Kinematics Expression

  • Dan Ebbert’s Inverse Kinematics Expression

    Posted by Cutter Johnston on October 11, 2010 at 4:52 am

    I am using Dan Ebbert’s Inverse Kinematics expression for animating a solider marching while holding a rifle. I want the extremity to be the rifle I have added past the hands. I am only having success one (the left side). It behaves beautifully. Getting both left and right to behave together is not working. Does anyone have an idea? The hands need to be locked to the rifle or vise-versa. Otherwise I keep the left as is and keyframe the right hand to “appear” locked to the barrel of the rifle. Yikes!.

    ARM LEFT UPPER

    cw = true;
    upper = true;
    upperLimb = "ArmLeftUpper";
    lowerLimb = "ArmLeftLower";
    extremity = "Rifle";
    effector = "LeftHandEffector";

    function getWorldPos(theLayerName){
    L = thisComp.layer(theLayerName);
    return L.toWorld(L.anchorPoint);
    }

    A = getWorldPos(upperLimb);
    B = getWorldPos(lowerLimb);
    C = getWorldPos(extremity);
    E = getWorldPos(effector);

    a = length(B,C);
    b = length(E,A);
    c = length(A,B);

    x = (b*b + c*c - a*a )/(2*b);
    alpha = Math.acos(clamp(x/c,-1,1));
    if (upper){
    D = E - A;
    delta = Math.atan2(D[1],D[0]);
    result = radiansToDegrees(delta - (cw ? 1 : -1)*alpha);
    V = B - A;
    adj1 = radiansToDegrees(Math.atan2(V[1],V[0]));
    result - adj1 + value;
    }else{
    y = b - x;
    gamma = Math.acos(clamp(y/a,-1,1));
    result = (cw ? 1 : -1)*radiansToDegrees(gamma + alpha);
    V1 = B - A;
    adj1 = radiansToDegrees(Math.atan2(V1[1],V1[0]));
    V2 = C - B;
    adj2 = radiansToDegrees(Math.atan2(V2[1],V2[0]));
    result + adj1 - adj2 + value;
    }

    ARM LEFT LOWER

    cw = true;
    upper = false;
    upperLimb = "ArmLeftUpper";
    lowerLimb = "ArmLeftLower";
    extremity = "Rifle";
    effector = "LeftHandEffector";

    function getWorldPos(theLayerName){
    L = thisComp.layer(theLayerName);
    return L.toWorld(L.anchorPoint);
    }

    A = getWorldPos(upperLimb);
    B = getWorldPos(lowerLimb);
    C = getWorldPos(extremity);
    E = getWorldPos(effector);

    a = length(B,C);
    b = length(E,A);
    c = length(A,B);

    x = (b*b + c*c - a*a )/(2*b);
    alpha = Math.acos(clamp(x/c,-1,1));
    if (upper){
    D = E - A;
    delta = Math.atan2(D[1],D[0]);
    result = radiansToDegrees(delta - (cw ? 1 : -1)*alpha);
    V = B - A;
    adj1 = radiansToDegrees(Math.atan2(V[1],V[0]));
    result - adj1 + value;
    }else{
    y = b - x;
    gamma = Math.acos(clamp(y/a,-1,1));
    result = (cw ? 1 : -1)*radiansToDegrees(gamma + alpha);
    V1 = B - A;
    adj1 = radiansToDegrees(Math.atan2(V1[1],V1[0]));
    V2 = C - B;
    adj2 = radiansToDegrees(Math.atan2(V2[1],V2[0]));
    result + adj1 - adj2 + value;
    }

    Michel Pensas replied 15 years, 3 months ago 4 Members · 7 Replies
  • 7 Replies
  • Benjamin Graham

    October 11, 2010 at 10:37 am

    Not to take away from Dans fantastic work on the ik stuff but have you seen https://www.duduf.com/ressources/duik/en/index.html. I found it much simpler to work with and more robust (which is important in character setup). I’ve found the other things in this little toolkit useful too. I’d love to pay for it but I don’t have a paypal account. Should do in the coming months and then I totally will. Dans expression is a really good learning resource though I just found the Duik tools a little less intimidating to be honest. It’s also a bit easier to debug (another biggie in character setup). Still I’m in awe of Dans understanding of the mathematics that goes into ik, and his tireless dedication to providing useful learning examples for the less mathematically inclined is fantastic.
    Benjamin.

  • Benjamin Graham

    October 11, 2010 at 10:46 am

    For the record. What I’d do here at least in 3d (honestly in 3d I’d probably do more but in 2d simple is good) is simply setup the arms as usual with the hands as the end of the ik chain and then parent the ik handles under the rifle and then parent the rifle to the root control of the character. Now just animate the rifle movement and as you move his root around (you decide – hips or masterControl) the gun moves with him so if he’s walking the gun follows along. a bit of vertical movement is okay but you may need to isolate the gun so it moves around in x but not in y or something if it looks weird although chances are good that a straight parent under the root is all you need.

    Hope this is helpful and that I’ve properly understood your question.

  • Benjamin Graham

    October 11, 2010 at 10:51 am

    Oh there’s another important reason I used the duik tools. Dans expression is great but only works on cutout style stuff so to make it work on puppet tools as I’ve been needing to do I’d basically have to create a bunch of solids aligned to each puppet pin and then setup the ik chain on the solids and then connect the puppet pins to the solids. Which, wouldn’t you know it, is exactly what the duik toolset does. And I get to type and click less, which always makes me happy.

  • Dan Ebberts

    October 11, 2010 at 4:33 pm

    I think all you need to do is to create some hands using nulls and use those as the extremities. Parent them to the lower arms where the hands would be. Then position the effectors where you want them on the rifle, and parent them to the rifle. Then both effectors will follow the rifle. I just tried it and it seems to work.

    Dan

  • Cutter Johnston

    October 11, 2010 at 8:33 pm

    Thank you! I will give these solutions a try. Here goes another long evening animating.

  • Cutter Johnston

    October 12, 2010 at 4:32 pm

    It is working! Gracias Amigos!

  • Michel Pensas

    January 8, 2011 at 2:34 pm

    cool

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy