Nerd For Tech
Published in

Nerd For Tech

Creating a First-Person Gun Holding Animation in Unity

I have been working on a zombie survival game. I decided to create a first-person perspective of the character holding the gun. The character and gun models I am using come from the custom package created by GameDevHQ. I will also use a premade first-person character controller from the custom package.

With the models and the character controller imported I added the character controller to the scene.

I added the character model to the scene. I then copied all the scripts from the character controller to the character model and put the main camera under the character model. I then deleted the leftover parts from the character controller.

I used an idle animation from Mixamo for the character.

After adding the idle animation, I aligned the gun model with the screen to look like a first-person shooter. I also temporarily have the gun model parented to the main camera.

To start rigging, I added four empty game objects to be positioned for the right and left hands along with the hints for where the elbows should bend.

Unity has a preview package called animation rigging. I downloaded this to use the two-bone IK constraint. I added this to the right and left hands. The root, mid, and tip spots match up with the right and left shoulder, arm, and hand of the character model.

The source object would be the hand and hint for each hand.

In the gun model, add two empty game objects to represent the right and left hands and place them on the corresponding sides of the gun.

I created a simple lerping script to get the hand positions in place smoothly.

Add the game objects in the gun model to the respective spots in the left and right hands.

Now you need to hit play and rotate and move the hands to get them to line up the best you can. You will want to copy the transforms in play mode and paste them when you exit play mode to save the positions.

With the hands in place, you can create an empty game object in the main camera and give it the position of the gun. Take the gun out of the main camera and add the lerp script. The target will be the new game object.

This will get you a pretty good first-person gun animation.

--

--

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