-
Dan Ebbert’s Inverse Kinematics Expression
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 UPPERcw = 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;
}