# Introduction

Inverse Kinematics is something that is always being over complicated. With this script I attempt to simplify it for a broader audience to see the cool things they can do with it. This is a simple crane driven by IK to give an example of what is possible.

# Usage

To use this script, first create a root prim, then create a swivel joint for the bottom of the boom. After that make a lower and upper arm prim and then create a prim box for the end of it to represent the target point.

Name the arm closest to the base lowerLeg0 and make its size <2.0,0.1336,0.1336> set its Path Cut to B:0.125 E:0.625.

Name the arm furthest from the base upperLeg0 and make its size <2.0,0.1336,0.1336> set its Path Cut to B:0.125 E:0.625.

Name the end point foot0.

Name the swivel base hipHinge0.

Link all the parts to the original root prim.

Save the script.

Move the final point with the build menu's edit linked parts to see it in action.

# The Code

This version is solving a 3D point for the knee using the Doom 3 IK function. You may do anything you like with this code, without limitation. It's for educational purposes only and will need modification to be used in large projects.

```//written by To-mos Codewarrior (tomos.halsey)
//3D IK crane exmple using doom3 Source conversion

float IK_angle(vector offset)
{return  llAtan2(offset.z,-offset.x);}
//compressed doom 3 IK ported by To-mos Codewarrior on (6/22/2012)
vector IK_bones(vector startPos,vector endPos, vector dirNorm, float upperLeg, float lowerLeg)
{
vector offsetEnd=endPos-startPos;float lengthTemp=llPow(llVecMag(offsetEnd),2);
float lengthTemp2=llPow(lengthTemp,-0.5);lengthTemp*=lengthTemp2;
if(lengthTemp>upperLeg+lowerLeg||lengthTemp<llFabs(upperLeg-lowerLeg))return startPos+0.5*offsetEnd;
offsetEnd*=lengthTemp2;lengthTemp2=(lengthTemp*lengthTemp+upperLeg*upperLeg-lowerLeg*lowerLeg)*(0.5*lengthTemp2);
return startPos+lengthTemp2*offsetEnd+
llSqrt(upperLeg*upperLeg-lengthTemp2*lengthTemp2)*
llVecNorm(dirNorm-offsetEnd*dirNorm*offsetEnd);
}
default
{
state_entry()
{
integer total=llGetNumberOfPrims()+1;
while((total--)-1)
{
}
llSetTimerEvent(0.15);
}

timer()
{
llSetText((string)(llGetFreeMemory()*0.000977)+"KB",<1.0,1.0,1.0>,1.0);//debug