Setting Up an IK Weapon System in Unity! (1)

Marcus Ansley
4 min readAug 29, 2021

I recently worked on this IK weapon system for the First Person Shooter project. Essentially, I’m using a ‘Rig’ component, two ‘Two Bone IK Constraint’ components, and a custom lerp script to drive the player avatar’s hands so that they follow the position of the player’s gun. There are quite a few steps to this so I’ll break this one up into two parts 😉

1.To begin, head over into Package Manager and click on the ‘Advanced’ dropdown. Select ‘Show preview packages’ then search for ‘Animation Rigging’. Install this package then close the Package Manager window when that’s finished.

2. Something you’ll need to ensure before we get into implementing anything is that your player avatar is configured correctly. To do this, I’d recommend selecting your Player, then double-clicking the Avatar instance under ‘Avatar’ in the Animator component:

This should then take you to the specific Avatar being used in your Player GameObject. With this selected, click on ‘Configure Avatar’ in the Inspector. This should open up a window in the Inspector (and most likely a dedicated scene) in which you can edit your avatar:

If you notice any red areas in the model and/or any missing Transform references, see if you can find these in your character model and assign them appropriately. It’s a slightly tedious process, but it’s probably worth the time to fill this out as much and as accurately as possible. In our case, we’re particularly interested in the hands and arms, so do make sure these are all filled out as they need to be.

You might find your model already has all of these Transforms specified (in which case don’t worry about this)

3. Create a child object under your Player called “IK” and add a Rig component to it. The ‘Weight’ variable in the Inspector will essentially determine the extent to which our IK system will override the avatar’s animation. If we were to set this to 0, your avatar’s arms are likely to remain in the exact same place as they currently do (determined by the ‘Idle Gun’ animation in this case). If we set this to 1, however, our IK system should have full control over the avatar’s arms despite any animation the avatar might have.

4. Next, create four empty GameObjects under this IK object called something like “L_Hand”, “R_Hand”, “L_Hint”, and “R_Hint” respectively. On L_Hand and R_Hand, add a Two Bone IK Constraint component. For the Root, specify the respective arm or shoulder Transform; for the Mid, specify the forearm Transform; for the Tip, specify the hand Transform. For the Source Objects, we’ll have our L_Hand/R_Hand for the Target and our L_Hint/R_Hint for the Hint.

Essentially, the Target drives our avatar’s hands while the Hint tells the avatar’s arms which way to bend (particularly at the elbow). You’ll most likely need to head into Play mode and adjust/position these until you’re happy with them.

At this point, we should be able to have our avatar’s arms and hands positioned where they need to be. What we next need to work on is having the gun itself drive the movement of the arms and hands (and in a way that looks a bit more smooth and natural). I’ll cover how we can achieve this using a custom lerp script and some empty GameObjects in a follow-up article 😉

--

--

Marcus Ansley

Game Developer | Game Design and Literature Graduate