- Open your Unity project.
- First check that you have installed the official Leap motion V2 skeletal tracking asset, available free on the asset store. Optionally you may also want the Leap Motion OVR assets, available from the Leap motion developer website.
- Download and import the Avatar Hand Controller for Leap Motion from the asset store.
- That’s it! The package will be installed into a LeapAvatarHands folder. You can check out a demo scene in the Scenes sub-folder.
Configuring your own avatar
Adding this solution onto a player avatar in your Unity scene is quite easy, although does require a little bit of configuration for the avatar.
- Set the update mode on the Animator component of your character to “Animate Physics”.
- Add a child gameobject to your player gameobject. The player gameobject must be a properly rigged character with 5 fingered and 3+ jointed hands. I did all my testing with characters generated by Mixamo Fuse, and then rigged with the Mixamo auto-rigger.
- Position this child gameobject where you want the virtual Leap controller to sit, generally speaking you will want this to be about 10-30cm out from the avatar’s belly button.
- Add the IKLeapHandController script to this empty gameobject.
- Go to the avatar’s left hand and add the RiggedHand script from the Leap Unity package (v2.0+) to it.
- Go to each of the avatar’s fingers and add the RiggedFinger script to them.
- Set the finger type on each of the fingers.
- Set the bones (transforms) on each of the fingers, you should have 3, with the first one being the transform that represents the base of that finger, the second one being the knuckle, and the third one being the joint between the knuckle and fingernail.
- Go back to the avatar’s hand, and set each finger in the Fingers array: Thumb, Index, Middle, Ring, Pinky.
- You will also need to set the finger pointing and palm facing vectors for each hand and finger. For reference with my Mixamo characters I had the finger pointing as 0,1,0, and the palm facing as 0,0,0. For each finger I had 0,1,0 and 0,0,0 except the thumb which was 0,1,0 and either -1,0,0 for the left hand or 1,0,0 for the right hand. However, these settings will depend on how the character is setup.
- Do steps 4-9 for the right hand also.
- Go back to the IKLeapHandController gameobject and set the Avatar Left Hand and Avatar Right Hand fields to use the hands you just configured.
- Go to the root node of the avatar and add the IKActioner script, and tell it which gameobject you put the IKLeapController onto.
The IKActioner script passes the inverse kinematics pass from the animator component on the avatar up to the actual IKLeapHandController.
The IKLeapHandController is an extension of the provided LeapHandController, set up to work with avatar hands and inverse kinematics.
Using rigid hands
So that your hands can interact with physical objects in game, I have included a RigidIKHands prefab which will work with my IK solution. Simply add these into the physics hands slots on the IKLeapHandController component.