Daily progress: IK Weapon system in Unity
We’re almost ready to implement our weapon system, but first let’s attach our gun to the player using Unitys rigging system.
First, you’ll have to install Unitys Animation Rigging system from the package manager. You may need to enable preview packages in advanced settings.
Now select the main man object, remember that any kind of animation-related action MUST be done at the parent level. That said, add a rigbuilder component:
There’s a slot for a rig so we’ll need to create one. While still in the man parent, create an empty and call it IK.
Place a rig component in the IK empty
Inside of this empty, create 4 more empties called L_Hand, R_Hand, L_hint, R_Hint
and then put this empty into the rig slot.
Next, we’ll assign the actual rig to the newly created IK. We can find the necessary rig under mixamorig_Hips
Now with the left hand selected, add a two-bone IK Constraint
It’s now asking for 3 bones, a Root, Mid, and tip. In the mixamo rig, place the LeftShoulder in root, LeftForeArm in Mid, and LeftHand in tip:
Next, under source objects, we want to put our IK L_Hand as the target, and our L_Hint as the hint.
Next, do the same for the Right Hand.
Now we’ll probably want to create some markers for our empties so we can actually see where they’re placed in our scene. The reason you do this will make sense in a moment.
If we press play, the players hands will move to the new IK constraints. Here, I’m moving the Hand, and then the hint which controls the elbow. The only problem here is when you stop playing, everything will reset so you’ll want to move the empty in game mode, copy its values, and then paste them back into the component in edit mode. Lengthy example gif ensues.
Tomorrow we’ll go into how to get the Players hands to stick to the gun!