# Haptics API

Trigger tactile feedback across supported devices without worrying about platform differences. normalizes style names and falls back gracefully when hardware lacks vibration support.

{% hint style="warning" %}
All SDK methods can reject — unhandled rejections crash the app. Even fire-and-forget calls like `triggerHapticAsync()` return promises that can fail. Always attach a `.catch()` handler. See [Error Handling](/rundot-docs/v5.15.0/readme/error-handling.md) for details.
{% endhint %}

## Quick Start

```typescript
import RundotGameAPI from '@series-inc/rundot-game-sdk/api'
import { HapticFeedbackStyle } from '@series-inc/rundot-game-sdk'

await RundotGameAPI.triggerHapticAsync(HapticFeedbackStyle.Success)
await RundotGameAPI.triggerHapticAsync(HapticFeedbackStyle.Warning)
await RundotGameAPI.triggerHapticAsync(HapticFeedbackStyle.Heavy)
```

`triggerHapticAsync` gracefully no-ops on hosts that lack vibration hardware, so you can call it defensively without extra guards.

## Supported Styles

`triggerHapticAsync` only accepts the `HapticFeedbackStyle` enum exported from `@series-inc/rundot-game-sdk`. Stick to the enum (or the equivalent string literal) to avoid typos.

| Style (`HapticFeedbackStyle`) | String literal | Typical use                                                       |
| ----------------------------- | -------------- | ----------------------------------------------------------------- |
| `Light`                       | `'light'`      | Subtle taps for UI chrome (button clicks, light impacts).         |
| `Medium`                      | `'medium'`     | Noticeable impulses when you need emphasis without being jarring. |
| `Heavy`                       | `'heavy'`      | Strong pulses for collisions, explosions, or high-stakes input.   |
| `Success`                     | `'success'`    | Reward cues after quests, crafting, or confirmations.             |
| `Warning`                     | `'warning'`    | Prompt the player about risky states or invalid actions.          |
| `Error`                       | `'error'`      | Hard-stop feedback when something definitively fails.             |

## Capability Detection

Capability data lives on the device payload that provides during the host handshake. Cache it once so you can tailor UI (for example, hide haptics toggles if unsupported).

```typescript
const { haptics } = RundotGameAPI.system.getDevice()

// Useful if you want to adjust UI, prompt the player, or log analytics.
const supportsHaptics = haptics.supported && haptics.enabled
```

## Patterns

* **Reward cues:** fire `Success` when players complete goals or receive loot.
* **Error signaling:** use `Warning` or `Error` to reinforce invalid actions.
* **Moment-to-moment feel:** pair `Light`, `Medium`, or `Heavy` pulses with button presses or impacts.

## Best Practices

* Cache `RundotGameAPI.system.getDevice().haptics` to avoid repeated lookups and to understand if the host supports feedback.
* Avoid spamming vibrations—respect rhythm and allow cooldowns so the experience stays premium.
* Wrap calls in `try/catch`; some desktop browsers reject vibration promises.


---

# 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://series-1.gitbook.io/rundot-docs/v5.15.0/readme/haptics.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.
