# Warp Providers

## Technical Aspects

**Warp Providers** are components that provide active interaction with target points.

{% hint style="success" %}
**Example**: the built-in **MantleComponent** will search for the climbable obstacle point, and then pass it to the *Motion Warping* component.
{% endhint %}

This plugin offers a common interface - **IWarpProvider** - that can be used to create custom *Warp Providers*. This interface contains a single method called **Interact** that returns the result of a check:

{% code title="WarpProviderInterface.cs" %}

```csharp
public struct WarpInteractionResult
{
    public WarpPoint[] points;            // Target points.
    public MotionWarpingAsset asset;      // Warping asset with settings.      
    public bool success;                  // If the interaction can be started.

    public bool IsValid()
    {
        return success && points != null && asset != null;
    }
}
    
public interface IWarpPointProvider
{
    public WarpInteractionResult Interact(GameObject instigator);
}
```

{% endcode %}

The plugin supports both moving and static obstacles out of the box. Here is how to correctly pass the data for each obstacle type:

<details>

<summary>Moving obstacles</summary>

To make the **Warp Point** depend on a specific transform, make sure to specify that target transform, and convert the point world coordinates to that transform's space:

```csharp
result.points = new[]
{
    new WarpPoint()
    {
        transform = hit.transform,
        position = hit.transform.InverseTransformPoint(_targetPosition),
        rotation = Quaternion.Inverse(hit.transform.rotation) * _targetRotation
    }
};
```

</details>

<details>

<summary>Static obstacles</summary>

If you want the **Warp Point** to be static in world space, make sure to pass the world coordinates of the desired interaction point:

```csharp
result.points = new[]
{
    new WarpPoint()
    {
        position = _targetPosition,
        rotation = _targetRotation
    }
};
```

</details>

## Example

Here is how to use a **Warp Provider** in code. We are going to use **VaultComponent** in this example:&#x20;

```csharp
public class YourController : MonoBehaviour
{
    //...
    private MotionWarping _warpingComponent;
    //...
    
    //...
    private VaultComponent _vaultComponent;
    //...

    private void Start()
    {
        //...
        _warpingComponent = GetComponent<MotionWarping>();
        //...
    }
        
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.F))
        {
            _warpingComponent.Interact(_vaultComponent);
        }
    }
    
    //...
}
```

It is also possible to pass the *gameObject* as a parameter in the Interact method:

```csharp
_warpingComponent.Interact(gameObject);
```

In this case, the **Motion Warping** will try to get the first component that implements the **IWarpProvider** interface and interact with it.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kinemation.gitbook.io/motion-warping-for-unity/fundametals/warp-providers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
