# After Effects - Arm Rig

### Full step by step Tutorial:

{% embed url="https://www.instagram.com/p/B_vU7oNHL4W/?utm_source=ig_web_copy_link" %}

Code for UPPER ARM rotation:

```javascript
var cw = false;
var upperLimb = "UPPER ARM";
var lowerLimb = "LOWER ARM";
var extremity = "HAND";
var effector = "CONTROLLER";
function getWorldPos(theLayerName){
  var L = thisComp.layer(theLayerName);
  return L.toWorld(L.anchorPoint);
}
var A = getWorldPos(upperLimb);
var B = getWorldPos(lowerLimb);
var C = getWorldPos(extremity);
var E = getWorldPos(effector);
var a = length(B,C);
var b = length(E,A);
var c = length(A,B);
var x = (b*b + c*c - a*a )/(2*b);
alpha = Math.acos(clamp(x/c,-1,1));
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;
```



Code for LOWER ARM rotation:

```javascript
var cw = false;
var upperLimb = "UPPER ARM";
var lowerLimb = "LOWER ARM";
var extremity = "HAND";
var effector = "CONTROLLER";
function getWorldPos(theLayerName){
  var L = thisComp.layer(theLayerName);
  return L.toWorld(L.anchorPoint);
}
var A = getWorldPos(upperLimb);
var B = getWorldPos(lowerLimb);
var C = getWorldPos(extremity);
var E = getWorldPos(effector);
var a = length(B,C);
var b = length(E,A);
var c = length(A,B);
var x = (b*b + c*c - a*a )/(2*b);
alpha = Math.acos(clamp(x/c,-1,1));
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;

```



Original code by Dan Ebberts: [https://www.motionscript.com/design-guide/ik.html](https://www.motionscript.com/design-guide/ik.html)
