> For the complete documentation index, see [llms.txt](https://rigonix3d.gitbook.io/rigonix3d-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rigonix3d.gitbook.io/rigonix3d-docs/documentation/systems-in-depth/interaction-system.md).

# Interaction System

How the character finds, prompts, and activates things in the world.

## Interaction module — inspector reference

### Settings

| Field                 | Type      | Default    | What it does                                           |
| --------------------- | --------- | ---------- | ------------------------------------------------------ |
| **Interaction Range** | float     | `2.0`      | Radius of the sphere that looks for interactables.     |
| **Interaction Layer** | LayerMask | Everything | Which layers are scanned for interactables.            |
| **Can Interact**      | bool      | `true`     | Master toggle — off disables all scanning and prompts. |

### State *(read-only)*

| Field                  | Type       | What it shows                                                  |
| ---------------------- | ---------- | -------------------------------------------------------------- |
| **Current Target Obj** | GameObject | The interactable currently in focus, shown live for debugging. |

***

The Interaction system lets the character pick up items, open doors, flip switches — anything in the world worth touching. It's built around one small interface, so *your* objects become interactable with a few lines.

### The IInteractable interface

Any object that wants to be interacted with implements `IInteractable`:

```csharp
public interface IInteractable
{
    string GetInteractionPrompt();          // "Press E to Open"
    InteractionType GetInteractionType();   // Press, Hold, Tap, Automatic
    void Interact(RigonixController player); // do the thing
    float GetDuration();                    // for Hold / Tap
    bool interactionAvailable { get; set; }
}
```

`InteractionType` covers the four common patterns:

| Type          | Behaviour                                                    |
| ------------- | ------------------------------------------------------------ |
| **Press**     | Single tap fires immediately.                                |
| **Hold**      | Must hold for `GetDuration()` seconds — revive, pick a lock. |
| **Tap**       | Tap N times — mash to force a door.                          |
| **Automatic** | Fires on proximity, no button.                               |

### How the module finds targets

Each frame (when `canInteract` is on) the Interaction module sweeps an `OverlapSphere` of `interactionRange` on the `interactionLayer`, then scores candidates by how far they are *and* how directly the character faces them (a dot-product test rejects things behind you). The best target gets a line-of-sight raycast so you can't interact through walls. The winner's prompt is pushed to the interaction UI.

```mermaid
flowchart LR
    A[OverlapSphere] --> B[Score by distance + facing]
    B --> C[Line-of-sight raycast]
    C --> D[Show prompt]
    D --> E{Input matches type?}
    E -->|yes| F[Interact player]
```

### Making your own interactable

Implement the interface and put the logic in `Interact`:

```csharp
public class Chest : MonoBehaviour, IInteractable
{
    public bool interactionAvailable { get; set; } = true;
    public string GetInteractionPrompt() => "Press E to Open";
    public InteractionType GetInteractionType() => InteractionType.Press;
    public float GetDuration() => 0f;

    public void Interact(RigonixController player)
    {
        Open();
        player.inventory.AddItem(loot);
    }
}
```

Toggle `interactionAvailable` to `false` and the scanner skips it — a clean way to disable a used-up object without removing the component. The base package includes ready-made interactables (doors, teleporters, pickups, levers) you can crib from.

{% hint style="info" %}
Input is device-agnostic here too: the module reads `wasInteractPressed` / `isInteractHeld`, and on mobile it wires up the on-screen action button automatically — so Hold and Tap interactions work on touch without extra code.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://rigonix3d.gitbook.io/rigonix3d-docs/documentation/systems-in-depth/interaction-system.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
