Using Inverse Kinematic Rigs for a First-Person Shooter in Unity 3D

Keeping Your Hands On Your Weapon

So, here’s a bit of a problem. I have an idle animation for my player holding a pistol, and I’ve placed a weapon prop in the player’s hands. But if I pan away from my hands and the weapon, they leave my view. It doesn’t really feel like aiming. If I set my weapon as a child of the camera, the gun will move along with my aim, but my hands are stuck in the place where the animation has left them.

To solve this problem, I need to set up an Inverse Kinematics Two-Bone Constraint. Don’t worry if those terms seem beyond comprehension. You’ll see what we’re up to pretty quickly. The gist is, we’re going to create targets for our hands to stick to, and other targets to guide the kinematics of the model’s rigging so our player moves naturally as the gun follows our aim.

The first step is to create the targets for each hand and elbow. Create an empty object in your Hierarchy called IK_Rig, and four child objects within the IK rig called L_Hand, R_Hand, L_Hint, and R_Hint.

Once you have your rig set up, place a Rig Builder component on the root Player object, and place the rig in the slot provided.

Next, on the L_Hand and R_Hand objects, place the IK Two Bone Constraint component. In the blanks provided we’ll be placing the bones of our player’s arms and hands, starting with the Upper Arm in the Root and the Hand in the Tip:

We’ll also place the L_Hand object itself in the Source Objects > Target spot, and the L_Hint in the Hint spot.

The Tip will stick to the Target, and the joint in between the Root and the Mid will bend toward the Hint when necessary to accommodate the movement of the Tip.

Now, all we need to do is move the Target (the L_Hand and R_Hand objects) into the proper position and rotation to appear to be holding the prop.

This has to be done from Play mode, as the character won’t apply it’s IK component in the Edit mode. BE SURE TO RECORD YOUR TARGET LOCATIONS BEFORE LEAVING PLAY MODE. Once you have a look you like, exit play mode and enter the coordinates for rotation and position for each target into their respective transforms. If you had to adjust the Hints to get the elbows bending correctly, make sure to readjust those as well.

Keep in mind that this is a FPS view, so the best angle to refer to is the game view. The trigger finger doesn’t need to line up perfectly, because the player won’t see it.

And there we have it. Your hands are accurately holding your prop, and your arms will move in a more or less realistic fashion wherever the prop happens to go. It’ll even make your arms kick a little when the weapon animation bucks.

That’s all for today. See you again tomorrow for the next progress update.

--

--

--

Unity Developer / Game Developer / Artist / Problem Solver

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

Recommended from Medium

NumPy Basics — A Pocket Guide with Practical Examples in Python

Setting up Git with Unity

Scrolling lines of console code

göttliche druzy vergoldet Multi-Anhänger Schmuck l-1in de

Understanding the impact of Open Booking

Four women take part in an indoor aerobics class

$COGI’s IDO event on BSCSstation and KaiStarter on November 12th

Migrating to a Neo4j Graph Database with Ruby on Rails

Gitlab setup tutorial — Things to do after installation

ASP .NET Core 3.0 and JWT

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
Micha Davis

Micha Davis

Unity Developer / Game Developer / Artist / Problem Solver

More from Medium

Day 95: Pushing Objects in Unity to Complete Puzzles

Journal 143 — Unity Project Development, 2.5D Shooter

Creating A 2.5D Character Controller In Unity

Shooting Enemies in Unity.