Holding Weapon with IK Pt.02- Game Dev Series 129

Objective: using IK to make Player holding a pistol.

After creating the IK system to both arms, now we can make Player holding a pistol with it.

Import a pistol

First, let’s import the pistol gameobject. You can download one from Unity Assets Store, or using the pistol prefab from GameDevHQ Filebase like me.

After imported the pistol prefab, drag it to Camera as its child object. Now the pistol should be under Camera, and Camera should be under Player.

Adjust the hand position

Now we can make the arms holding this tiny weapon.
To make it holding perfectly when game starts, we need to use codes to control arms moving to the right position.
Let’s create the holding point to pistol first. Create 2 empty objects under pistol prefab.

Next, create a script called “SmoothDamp”, and attach this script to both left and right hand gameobjects under IK.

Inside this script, we will make both hands snapping to the position we just created in pistol.

Back to editor and drag the HandPosition objects into this script on both hands.

Now you can press Play and see what would happen.

Fix the holding position

When play the game, you should see something quirky like this:

And now we need to fix this issue.
When under Play Mode, click some place outside the Game window, Player movement should be paused at where it is.
With that position, adjust the position and rotation of HandPosition gameobject.
Remember, one gameobject a time.

After adjust it, copy the transform component. Then exit Play Mode and paste it back to the HandPosition gameobject as new value.

Do the same setting to another HandPosition gameobject.
And don’t forget to adjust the snapping speed of SmoothDamp script, which will make the movement of hands look more naturally.

Once done, your Player should holding the pistol tightly when playing the game.




A passionate gamer whose goal is to work in video game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Thoughts about Formality

What is Drupal and its advantages?

How to Get Inspired to Code Every Single Day

Beyond the Cutting Edge of DevOps — From Mindset to Action

Managing Product Risk and Uncertainty with Design

Deploying High Availability CDN Architecture on AWS Using AWS CLI

C dynamic memory allocation and free

How to Find and Remove Bottlenecks in Your Process Flow

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Day 103: Creating A Ledge Grab in Unity Part 1

Using 2D Vector Composite for Movement in the New Input System with Unity 2021

GamePad Support w/ New Unity Input System

Unity camera plugin save image data as bytes