Journal 119 — Unity 3D Zombie Shooter, Add Animations with Rig Builder

Objective: To update our 3D player character with our own animations

In the previous example, we added a 3D player character to the scene and set up a gun prop in the first person view. Now, we want to add our own animation rigging to fix some of the movements.

To start, we can add the Animation Rigging package through the Package Manager.

Once this is installed, we need to do two things: Add a Rig Builder component to the root object with the Animator component, and create a child object with a Rig component. Instead of calling the child “Rig”, let’s call it “IK”.

Animate Hands

Let’s start the setup for animating the hands. In the IK object, we’ll make two empty objects for the left and right hands, and two more for what we’ll call “hints”, which will serve as guides or constraints for how the arms need to move.

For the left hand, we will then add a component called the Two Bone IK Constraint. In this case we want to target a new location for the hand to move with the pistol. So we can assign the following:

Then repeat the process for the right hand. To make the IK objects easier to see you can assign them 3D Icons in the Inspector, and resize them in the Gizmos window.

Gun Position and Hands

Let’s use the gun as the guide for how the hands move. To start this, we can create two empty game objects on the pistol for the hand position. We can create a short C# script to left hand and right hand IK objects, and set the gun hand position objects to both sides of the pistol.

Now let’s attach the script to the IK hands, and set the targets as the two hand position objects on the gun.

Let’s try this out.

Not quite, but we can start making adjustments to hand rotation and position to fix this. In Play mode, you can find a view of the gun and hand placement in the Game view, and then click outside of the Game view to hold the view for inspection and to see modifications. I’ll go through several trial and error attempts to move the gun prop, hands, and IK Hint objects to try and make the Game view look reasonable. Don’t forget to write down or screenshot all the modified positions, since we are working in Play mode and none of these tweaks will be saved.

As you can see in the above screen capture, the gun travel and the hand movement is not quite in sync. We can help this by smoothing the movement of the gun with the SmoothDamp script we created earlier.

We can add an empty game object to the Main Camera that contains the gun prop, and then copy the position and rotation of the gun and paste it on this new empty game object called “Gun_Pos”. Then we can drag the gun prop above the hierarchy of Main Camera, and attach the SmoothDamp script, and add the Gun_Pos object as the target to follow.

Thank you for your time!

--

--

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
Chris Nielsen

Chris Nielsen

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.