The Complete Guide To Animating Hands In Unity With SteamVR

By popular request, there is a new tutorial that uses blend states instead of animation states that you can find here.

For this tutorial you are going to need your own hand model, I’m sorry but you don’t want mine:

notice how it looks like the joints have a gooey substance between them.
I am not a 3D modeler!

You can make it in blender or any other 3D cad software you like, I personally use OnShape to model things, and blender to animate and color them. So after you have your model we have to create a few poses, this can be done in blender the way described in the video below (Not made by me):

So what we want is a relaxed hand position:

A fist:

And one with a pointed pointer finger:

Once you have those animated and ready to go you can import it simply by saving the blender project in your Unity Assets folder. Next, we need to set our inputs. Open the steam VR input panel and create two boolean inputs, one for trigger pulled, and one for grip pressed:

Open up the Binding UI and pair the actions to your trigger and grip button respectively. If you are unsure how to do this I have a tutorial on it!

Now we should probably get to adding our hands into the scene, navigate to the folder in your assets where you saved the hand file and open it and it should look like this, though it may not:


Next, drag the root of your hand model onto both of your controllers so they show up attached to them in the scene preview. Then you will have to manually reposition them so that the hands match up with the controllers and feel natural. What I did was put on my headset and adjust the hand until my first knuckle lines up with the knuckle on the model. Just remember to write your values down so you don’t lose them when you exit play mode.

Now all that’s left is to animate our hands. To do this create an animator component and drag it into your hand components in your scene so it can control them. Next, open it in the animator and drag your animations into it from your hand model, then create connections between them so it looks like this:

Also create two boolean variables in the animator like this:

Now here’s the magic, select one of the transitions between the animations and look in the inspector under the conditions section. This is where you can add conditions to your transition. Basically, it won’t transition to another animation unless all the conditions are met.

So what you want to do is set conditions on all the transitions so that depending on what buttons you are pressing the hand moves into the appropriate position.

Now one final step, we need to create a script so that our buttons update the variables of our animator.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
public class Hand : MonoBehaviour
{
public SteamVR_Input_Sources hand;//gives us a way to select what hand our script is attached to.
public Animator anim;//refrence to our animator
void Update()//update our animator values
{
if (SteamVR_Actions._default.TriggerDown.GetStateDown(hand))
{
anim.SetBool("Trigger Pulled", true);
}
if (SteamVR_Actions._default.TriggerDown.GetStateUp(hand))
{
anim.SetBool("Trigger Pulled", false);
}
if (SteamVR_Actions._default.GripClicked.GetStateDown(hand))
{
anim.SetBool("Grip Pressed", true);
}
if (SteamVR_Actions._default.GripClicked.GetStateUp(hand))
{
anim.SetBool("Grip Pressed", false);
}
}
}

Now attach the script to your hand components, and you should be done.

Here’s what you should have when you’re done:

Liked it? Take a second to support WireWhiz on Patreon!
Become a patron at Patreon!