Day 138 — IK Weapon System in Unity Part 1

Hey and welcome!

In this one we’re going to look into the rigging and work involved to have our player holding a gun from a first person view.

Let’s start by getting our model/pistol idle animation into the game. Head over to mixamo.com and pick out an fbx you like and search for the Pistol Idle animation:

Choose the download option and make sure the format is set as FBX for Unity and that you’re downloading this with the skin and then save it into your assets folder in Unity. If you prefer you can also search up the T-Pose in Mixamo and import your model that way and then import your Pistol Idle animation separately.

When you’ve done that, find your model in Unity and click into the Rig tab and make sure that you change the animation type from “Generic” to “Humanoid” and then drag and drop your model into the hierarchy so that it shows up in your scene.

Once you’ve done that go ahead and copy and paste your components from your player object onto your model and drag and drop the camera into your model so that it’s a child of it and then adjust your Character Controller and Main Camera accordingly.

Rename this model to Player and set the tag to player as well as this is going to be your new Player object. It’s fine to delete the old one now as we won’t be using it.

Once you have that done it’s time to sort out the animation. Start off by duplicating your animation and your avatar using CTRL + D when you click on them in your model in the project view. Store them in an animations folder to keep things tidy and then create an animator component on your new Player object. Drag and drop your animation into the Player’s inspector window, this can be done anywhere and it will automatically create a controller for your animator. Now drag and drop your avatar into your animator and you should have something like this:

Next you’re going to want to adjust the setting in your animation as well so click on that in your project view so that it opens the inspector for it and adjust the settings so that it matches this:

Making sure that Loop Time is checked is important as we want the idle animation to play over and over indefinitely. You’ll notice as well that we’re baking the root transform rotation and position and making sure that the rotation and Y position are based upon Original. This fixes our animation so that our character isn’t aiming off to the side or any other weird behaviours when we run the game.

You should have something like the above working for you after following along with this.

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.