IK Weapon System in Unity

I’m more and more satisfied with the choice made months ago to start a course with GameDevHQ because although it is not my first experience with Unity, I’m discovering many new things. Today I talk about a tool that I really would not have expected, it is the Animation Rigging.

In short a tool that allows you to create and organize the rigs of an animation, or sets of constraints to add procedural movement to animated objects.

As usual, we have to go to the package manager to install this tool, once inserted in the project the steps are quite immediate the difficult part will come later.

We need to create a new game object and we will give it the name IK, under this object we should create 4 other game objects that will serve for the right and left hands.

The first two will represent the position of the hand while the two additional game objects that we have created, will determine the direction in which the elbow should bend.

To the two game objects that we have placed for the hands, we need to assign a script from the newly installed package. Specifically the “Two Bone IK Constraint” script. From the inspector, we will notice that we should now assign different components. Starting from our model in the scene we should go for arm, forearm, and hand.

Instead in the second block, we are going to insert the two game objects Hand and Left Hint if we started with the left arm otherwise the right one.

Very important not to forget to assign the script “Rig” to the parent game object that I renamed IK.

The next step is to insert a gun and make my player’s hands more towards the camera.

Let’s start by inserting respectively two game objects children of our weapon that will represent the points where our hands will be positioned.

We have to make a little script to bring the hands in the right position.

With this script, we are going to move the hands from the generic position we had before to the ones near the gun we have just created and make them always follow it.

Assign them respectively to the left and right hands under the game object IK

All that remains is to go into play to try the position of the hands, find the one you like best, save the transform values and apply them out of play mode.

Do this step on the other hand as well.3

project manager by day, unity developer by night