Haptics
Haptics are in beta. The iPhone support relies on how iOS plays the native switch tick, which Apple could change in a future iOS release.
Vibrate
JestSDK.haptics.vibrate(pattern)
Same as the browser's
navigator.vibrate():
pattern is a duration in milliseconds or an array of alternating vibrate and
pause durations, 0 cancels, and it returns true when the request was
accepted. Unlike navigator.vibrate(), it also works on iPhone.
- HTML5
- Unity
canvas.addEventListener("pointerdown", () => {
JestSDK.haptics.vibrate(10);
});
JestSDK.Instance.Haptics.Vibrate takes a duration in milliseconds, or an int[] pattern of
alternating vibrate and pause durations:
using com.jest.sdk;
using UnityEngine;
public class TapFeedback : MonoBehaviour
{
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
JestSDK.Instance.Haptics.Vibrate(10);
}
}
}
In the Unity Editor mock, Vibrate logs the pattern and returns false.
Haptics are best effort. A phone in silent, Do Not Disturb or battery-saving
mode, or with haptics turned off, may not vibrate even when the call returns
true. If nothing vibrates while you test, check those first.
iPhone
iPhone has no vibration API. Instead, the SDK plays the system's native tick when the player lifts their finger from a tap on your game canvas:
- The tick ignores the pattern: there is one strength and no duration.
- Only a call made during a tap counts: while the finger is down, or
synchronously in your canvas
touchend,pointeruporclickhandler. Calls from timers, or from input your engine handles on a later frame, do nothing. In Unity, call it from the frame that sees the touch begin. - Drags and multi-finger gestures don't tick.
To make this work, the first vibrate() call places an invisible layer over
your canvas, so the first tap never ticks. The layer passes the player's
touches on to the canvas as copies. Keep in mind:
- Load the SDK before your engine adds its input listeners, so those listeners only see the copies.
isTrustedisfalseon the copies.- The layer sits right after the canvas, so selectors such as
canvas + .hudstop matching.
If your game doesn't work with the layer, skip vibrate() on iPhone:
- HTML5
- Unity
if (JestSDK.haptics.getCapability() !== "tap") {
JestSDK.haptics.vibrate(10);
}
if (JestSDK.Instance.Haptics.GetCapability() != HapticsCapability.Tap)
{
JestSDK.Instance.Haptics.Vibrate(10);
}
Check the capability
JestSDK.haptics.getCapability() (Unity: JestSDK.Instance.Haptics.GetCapability())
"vibrate"(HapticsCapability.Vibrate): the browser hasnavigator.vibrate(Android, and desktop Chromium, which has nothing to vibrate)."tap"(HapticsCapability.Tap): iPhone on iOS 18 or later."none"(HapticsCapability.None): no haptics (Safari and Firefox on desktop, older iOS).
You don't need to check it before calling vibrate(). Haptics run on the
device, so mock mode behaves like production.