# IK Weapon System in Unity

First of all, let’s talk a bit about Inverse Kinematics IK
When working on animations, we may find something like this:

On the left we can see an articulated body, and on the right it’s Avatar’s rigging map

An articulated body is a tree made up of linked chains with links (13,11,9), joints (I,G,F) and a root joint (A)

## Articulations and Poses

Articulation is the rotation of a joint, and that rotation will move the connected links.
Pose is a set of joint articulations which result in positioning the articulated body

## Forward Kinematics

The Forward Kinematics function/algorithm:

• Takes the whole pose as the INPUT (A,B,C,1,2,3)
• Calculates the position of the end effector (E) as the OUTPUT

This means that you need to define the articulation of each joint in the articulated body. It is ok for a low number of joints, but not for a high number

## Inverse Kinematics

Let’s say we know the target position T that we want the end effector E to reach (left image), but as you may notice, for reaching T, the rest of the pose needs to be modified.

Inverse Kinematics is the inverse function/algorithm of Forward Kinematics. IK:

• Takes a target position (T) as the INPUT
• CALCULATES the pose required (A,B,C,1,2,3) for the end effector (E) to reach the target position T

So, the POSE (A,B,C,1,2,3) is the OUTPUT

Weapon with IK

• Add a Rig Builder component in the root gameobject that contains the Animator component
• Create an empty gameobject called IK and add a Rig component to it
• Add IK to the Rig Layers in Rig Builder
• Add a Two Bone IK component to L_Hand and add the gameobjects from hierarchy to inspector

Target will be the place I want the hand to move towards to. Weight 0 is original position, and 1 is target position
Hint will be position the joint (Left forearm) points to.

Do the same for Right Hand

Attach the `SmoothDamp `script to L_Hand. Do the same for R_Hand