> For the complete documentation index, see [llms.txt](https://jorge-jgnz94.gitbook.io/hptk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jorge-jgnz94.gitbook.io/hptk/master/integrations/leap-motion.md).

# Leap Motion

{% hint style="info" %}
Leap Motion Controller (LMC) can be used attached to headset (**XR mode**) or relied on a surface, in front of the user (**Desktop mode**).
{% endhint %}

## &#x20;1. Import LeapMotion Integration Package

Open the **Integration Manager,** click on **Leap Motion** and import the built-in integration package.

## 2. Add the default setup prefab to your scene

In the Project window, within the **Assets** folder, search for "**DefaultSetup"**. You should see some entries. HPTK integration package for Leap Motion includes setup prefabs optimized for both modes:

* **XR mode:** drag & drop the prefab called **DefaultSetup.LeapMotionXR** into your scene.
* **Desktop mode:** drag & drop the prefab called **DefaultSetup.LeapMotionDesktop** into your scene.

## 2. Add an avatar to your scene

Leap Motion input data providers (IDPs) offer hand data in **world space**, taking world origin as the top center point of the LMC. As our LMC won't be placed in the floor, we need some **Transform that will represent the real hand data origin in the scene**. This Trasform can be:

* Master representation of avatar's head if LMC is attached to user's headset **(XR mode).**
* An arbitrary Transform that is child of avatar's origin if LMC relies on a surface, in front of the user **(Desktop mode).**

Leap Motion integration package includes prefab variants of the built-in DefaultAvatar prefab that implement these modifications.

In the Project window, within the **Assets** folder, search for "**DefaultAvatar"**. You should see some entries.

* **XR mode:** drag & drop the prefab **DefaultAvatar.URP.LeapMotionXR.**
* **Desktop mode:** drag & drop the prefab **DefaultAvatar.URP.LeapMotiponDesktop**.

## 3. Fine-tune setup and avatar

{% hint style="info" %}
If you need to move or pose hands in **Unity Editor** without using Leap Motion, go to **HPTK singleton** and replace **Left Editor IDPs and Right Editor IDPs** by the input data providers **PoseSkeletonTracker.L and PoseSkeletonTracker.R**.
{% endhint %}

### 3.1. XR mode

If the distance between LMC origin and headset origin is too big, **virtual hands might not match real hands** perfectly, breaking immersion. You can solve this by **slightly moving LeapMotionOrigin** (child of master representation of avatar's head) until finding the right offset.

### 3.2. Desktop mode

If the given position of **LeapMotionOrigin** does not match real LMC position relative to avatar, you can move this object until placing virutal hands in the desired position/rotation.
