dom / latest / gamepadhapticactuator / playeffect.html /

GamepadHapticActuator.playEffect()

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The playEffect() method of the GamepadHapticActuator interface makes the hardware play a specific vibration pattern.

Syntax

playEffect(type, params)

Parameters

type

A string representing the desired effect. This can vary depending on the hardware type. Possible values are "dual-rumble" or "vibration".

params

An object to describe a desired haptic effect.

Expected values are:

  • duration: The duration of the effect in milliseconds.
  • startDelay: The delay in milliseconds before the effect is started.
  • strongMagnitude: Rumble intensity of the low-frequency (strong) rumble motors, normalized to the range between 0.0 and 1.0.
  • weakMagnitude: Rumble intensity of the high-frequency (weak) rumble motors, normalized to the range between 0.0 and 1.0.

Note: A new call to playEffect() overrides a previous ongoing call.

Return value

A promise that resolves with true when the playEffect successfully completes.

Examples

const gamepad = navigator.getGamepads()[0];

gamepad.vibrationActuator.playEffect('dual-rumble', {
  startDelay: 0,
  duration: 200,
  weakMagnitude: 1.0,
  strongMagnitude: 1.0,
});

Specifications

No specification found

No specification data found for api.GamepadHapticActuator.playEffect.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
playEffect
68
15
No
No
55
No
No
68
No
48
No
10.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/GamepadHapticActuator/playEffect