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

More with mRemoteNG — How to with External Tools and FileZilla

Magento 2.3 Declarative Schema

All about Kafka

Why Developers Should Stop Fretting Over FAAMG Rejections

Visual Object Tracking (VOT) Toolkit With Python

Node.js vs Python — What to Choose in 2020?

Unemployment at a time of COVID-19: for developers fresh out of college

Visual Validation with Dynamic Data

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

Level Design in Unity Part 2: The Walls

Unity use right stick to aim in 2D with new input system

Starting To Feel Like A Real Game

Platformer: Player Animation Part 1