Holding a two-handed weapon

November 22nd, 2019

final result

Ever wondered how to create a setup in Spine that would allow your character to hold a weapon, but also throw it away if needed? Wonder no more! In this blog post we'll explain step-by-step how to do exactly that, expanding on one of our tips.

Spine Professional is required to follow this tutorial as we will use IK constraints and transform constraints to achieve our goals.

Skeleton setup

initial skeleton setup

We start out with a basic body rig and create a bone representing our weapon. We'll omit image and mesh attachments in this tutorial so we can more easily focus on the skeleton structure.

For the weapon bone to be able to move freely, it must not be a descendant of the body bone. A good place to parent it to is the root bone of our skeleton.

The above image illustrates this initial setup. The weapon is represented by the green bone called weapon, while the rest of the body follows a pretty standard humanoid bone hierarchy setup.

In addition to the weapon and body bones, we also created 2 bones called hand-on-weapon-l and hand-on-weapon-r. These will become IK constraints targets that help us to keep the hands of the body rig on the weapon.

Constraints setup

Once all the bones are in place, and with the weapon and the body being separate within the bone hierarchy, we can connect the two via constraints.

Creating the IK constraints

ik setup

First, we want to make the arms follow the left and right hand attachment points on the weapon. We start with the left arm by selecting the two arm bones arm-l-up and arm-l-down and creating an IK constraint with hand-on-weapon-l as the target. We repeat this process for the right arm.

The two arms will immediately try to point to their respective target bones. We want to disable this behavior in setup mode so we can more easily animate poses and movements without the weapon. For each of the two IK constraints, change the Mix from 100 to 0. This way the arm will use its original pose instead, allowing us to animate it as we please.

Creating the transform constraints

transform setup

As a final touch we want to ensure that the hands will match the weapon rotation, so they look as if they are actually holding the weapon instead of following their respective parent's rotation. We can achieve this by selecting hand-l and creating a new transform constraint with the bone weapon as the target. The same needs to be done for the other hand bone. To make things look right, we set the offset rotation to 90. We keep all the mixes at 0, so the hands don't rotate with the weapon in setup mode, again making it easier to animate weaponless movements and poses.

Creating animations following the weapon

When creating an animation where the arms and hands should follow the weapon, we simply key the mixes of the IK and transform constraints to a value of 100. Voila, the hands and arms will follow the weapon!

ik animate

transform animate

If everything went well, your final setup in animate mode could look like this:

final skeleton setup

Variations

It is possible to constrain both hands to the weapon using a single transform constraint. In general, fewer constraints is better because it makes the rig simpler. However, this may be an inconvenience if the character needs to detach only one hand from the weapon.

The character could use IK constraints on the arms when not holding a weapon. In that case, the mix for those IK constraints can be set to 0 when the mixes for the constraints to hold the weapon are set to 100.

Conclusion

final result

The character can hold the weapon with one or both hands, throw away the weapon, do tricks with it, and so on. Since it can be turned on or off, multiple similar setups can be used for different weapon types, such as a pistol, shotgun, machine gun, spear, etc. The constraint mixes can be set in animations or by code at runtime.

You can download an example of this setup here.

We hope you'll find this little setup useful for your projects! Feel free to discuss this post on the forum.