# Unity > Interaction framework

Source: https://docs.manus-meta.com/3.2.1/Plugins/Unity/interaction%20framework/

> **Warning: License requirement**
>
> The functionality described requires a `MANUS Bodypack` or a `MANUS license key` with the `Unity` feature enabled.

Our interaction framework is a powerful tool that allows you to easily implement interactive elements in your Unity projects. With this framework, you can create realistic hand interactions, such as picking up objects, interacting with buttons and switches, teleporting, and more. To help you get started, we provide an example scene that showcases the capabilities of the interaction framework. This scene demonstrates various interactable objects, including grabbables, switches, turnables, sliders, and buttons. By following the step-by-step instructions below, you can set up the hand and interactables in your own Unity project. Each section provides clear guidance on how to add the necessary scripts and components to achieve the desired functionality.

## Quick Start

XRRig and a pair of ManusInteractionHand prefabs are provided allowing for a quick start using the Interaction Framework. To use them, only a few manual steps described below are needed.

### XRRig

XRRig has a hard dependency on the OpenXR plugin, so to use the Interaction Framework, you need to install the OpenXR plugin.
The XRRig prefab contains a pair of ManusInteractionHands that can be used to interact with objects in your Unity project.

To use the XRRig prefab, a couple of references need to be added when dragging the prefab into the scene.

On ManusInteractionHand(L/R) open the hierarchy until we find a node called Teleporter, select it, and on the inspector we can see two fields that need to be filled in:

- ManusInteractionHand_L
  - Teleporter Preview = TeleTargetL
  - Line Renderer = TeleLineL
- ManusInteractionHand_R
  - Teleporter Preview = TeleTargetR
  - Line Renderer = TeleLineR

These references can be dragged from the Teleportation Game Object present in the scene.

![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-17.png)

### ManusInteractionHand

The ManusInteractionHand(L/R) prefabs are a pair of hands that can be used to interact with objects in your Unity project. You can use this prefab to easily add hand interactions to your project.

To use the ManusInteractionHand prefab, a few more references need to be added when dragging the prefab into the scene.

First, make sure your scene has a camera tagged as "MainCamera". Convert the camera to an XRRig if needed.

![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-18.png)

When dragging the ManusInteractionHand prefab into the scene, make sure to drag into the XRRig node.

On ManusInteractionHand(L/R) open the hierarchy and navigate to the Teleporter (ManusInteractionHand_L/R->SK_Hand->root->hand_l/r->Teleporter), select it, and in the inspector we can see four fields that need to be filled in:

- ManusInteractionHand_L
  - Player Transform = XRRig (can be an XRRig created by the OpenXR plugin)
  - Player Camera Transform = Camera (MainCamera)
  - Teleporter Preview = TeleTargetL
  - Line Renderer = TeleLineL
- ManusInteractionHand_R
  - Player Transform = XRRig (can be an XRRig created by the OpenXR plugin)
  - Player Camera Transform = Camera (MainCamera)
  - Teleporter Preview = TeleTargetR
  - Line Renderer = TeleLineR

These references can be dragged from the Teleportation Game Object and from the XRRig created by the OpenXR plugin.

![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-19.png)

## Setting up the hand

To enable hand interactions in your Unity project using the Unity Interaction Framework, you need to follow these steps:

1. Add the `HandGrab` script to the wrist bone of your character model. This script allows the hand to grab objects.

   ![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image.png)
2. For the ghost hand effect, add the `InteractionHand` script to the same object that contains the `Skeleton` script. This script provides visual feedback for hand interactions.

   ![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-1.png)
3. Optionally, you can modify the grab radius or the physics layer to customize the hand interactions.

You have now set up the hand in your Unity project and can start implementing interactive elements.

### Interacting with buttons/switches

To interact with objects, you need collision. You can do this manually by adding colliders to the objects, or you can use the `ColliderGenerator` script provided with the plugin. Simply add the `ColliderGenerator` script to the same game object that contains the skeleton script.

![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-2.png)

### Teleporting

To enable teleportation controls place the `teleporter` prefab as a child of the wrist bone in your Unity project.

![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-3.png)

## Setting up interactables

The Interaction Framework provides a variety of interactable objects that you can easily incorporate into your Unity projects. These objects include grabbables, switches, turnables, sliders, and buttons. This section will guide you through the process of setting up each type of interactable.

### Grabbables

Grabbables are objects that can be picked up and manipulated by the player. They are typically used for objects that the player can hold or move around in the game world. To make an object grabbable, follow these steps:

![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-4.png)

1. Add the `GrabbableObject` script to the object that you want to make grabbable. This script enables the object to be grabbed by the player.

   ![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-5.png)  
   Make sure the object has a collider component as well.
2. (Optional) If you want to make the object throwable, you can also add the `ThrowableObject` script. This script allows the player to throw the object after grabbing it.

   ![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-6.png)

### Switches

Switches are interactive objects that can be toggled between two states, such as on/off or open/closed. They are commonly used for controlling lights, doors, or other game mechanics. To set up a switch, follow these steps:

![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-7.png)

1. Add the `RockerSwitch` component to the object that represents the switch.

   ![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-8.png)
2. Add two collision areas for both sides of the switch with colliders. These collision areas define the regions where the player can interact with the switch.

   ![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-9.png)
3. Set the pivot point around which the switch should rotate.
4. Set the rotation amount that determines the range of motion for the switch.

### Turnables

Turnables are objects that can be rotated by the player. They are often used for knobs, dials, or other objects that can be turned. To make an object turnable, follow these steps:

![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-10.png)

1. Add the `TurnableObject` component to the object that you want to be rotatable.

   ![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-11.png)
2. Set the turn axis and the up axis. The up axis should be perpendicular to the turn axis.
3. Make sure the object has a collider component.

### Sliders

Sliders are interactive objects that can be moved along a linear path. They are commonly used for volume controls, settings, or other adjustable parameters. To set up a slider, follow these steps:

![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-12.png)

1. Add the `MovableObject` component to the object that you want to be movable.

   ![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-13.png)
2. Set the start and end position of the slider. These positions define the range of motion for the slider.
3. Make sure the object has a collider component.

### Buttons

Buttons are interactive objects that can be pressed or released by the player. They are often used for triggering actions or events in the game. To set up a button, follow these steps:

![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-14.png)

1. Add the `PushButton` component to the button object.

   ![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-15.png)
2. Assign the moving part of the button. This is the part that visually moves when the button is pressed.
3. Assign the two collision areas for pressing and releasing the button.

   ![](https://docs.manus-meta.com/3.2.1/Plugins/Unity/assets/B%20Interaction%20Framework/image-16.png)

### Prefabs

The Interaction Framework ships with prefabs for each type of interactable object mentioned above. You can inspect these prefabs to understand how they are set up and use them in your own projects. Simply navigate to the appropriate folder in the Unity Editor and drag the desired prefab into your scene.

By following these instructions, you can easily incorporate interactive elements into your Unity projects using our Interaction Framework.

## Haptics

The interaction framework supports haptic feedback on MANUS Glove devices that support haptics. When the `skeleton` object has the `enable haptics` boolean enabled, colliders are added to the hand to detect collisions with interactables. When a collision is detected, the haptic feedback is triggered on the glove.

### Framework haptics

The interactables come with built-in haptic feedback. Each hand will include a `HandHaptics` component. When a hand interacts with an interactable, the system retrieves the `HandHaptics` component and overrides the haptic feedback using the `SetHapticsStrengthOverride` function, as described below. When extending the interaction framework, this method is the recommended approach for implementing haptic functionality.

*HandHaptics.cs*

```csharp
/// <summary>
/// Sets the override haptics strength for a particular finger
/// Override values will be used in place of physically determined collider values unless the override value is -1
/// </summary>
/// <param name="p_FingerIndex">index of the finger to set haptics strength for</param>
/// <param name="p_Strength">Haptic strength to set, [0,1] or -1 for no override</param>
public void SetHapticsStrengthOverride( int p_FingerIndex, float p_Strength )
{
    m_HapticsStrengthOverride[p_FingerIndex] = p_Strength;
}
```

### Manual haptics

However, manual triggering of haptic feedback is also possible, either by skeleton ID or glove ID. The following code snippets outline the functions for triggering haptic feedback on a specific hand given the skeleton or glove ID. To stop the haptic feedback, the power value needs to be returned to `0`

> **Note**
>
> It's recommended that you disable the skeleton based haptic feedback when manually triggering haptic feedback as to avoid feedback overlapping.

*CommunicationHub.cs*

```csharp
/// <summary>
/// Activate haptics on specific hand given the skeleton id.
/// </summary>
/// <param name="p_SkeletonId">Skeleton id</param>
/// <param name="p_HandType">Hand type to send to</param>
/// <param name="p_Powers">Strength to send to hand</param>
public void SendHapticDataForSkeleton( uint p_SkeletonId, CoreSDK.Side p_HandType, float[] p_Powers )
{
    CoreSDK.SDKReturnCode t_Result = CoreSDK.VibrateFingersForSkeleton( p_SkeletonId, p_HandType, p_Powers );
    if( t_Result != CoreSDK.SDKReturnCode.Success )
    {
        Debug.LogError( $"MANUS-ERROR: {t_Result}, could not vibrate fingers." );
        return;
    }
}

/// <summary>
/// Activate haptics on specific hand given the glove id.
/// </summary>
/// <param name="p_SkeletonId">Glove id</param>
/// <param name="p_Powers">Strength to send to hand</param>
public void SendHapticDataForGlove( uint p_GloveID, float[] p_Powers )
{
    CoreSDK.SDKReturnCode t_Result = CoreSDK.VibrateFingersForGlove( p_GloveID, p_Powers );
    if( t_Result != CoreSDK.SDKReturnCode.Success )
    {
        Debug.LogError( $"MANUS-ERROR: {t_Result}, could not vibrate fingers for glove." );
        return;
    }
}
```
