files/en-us/web/api/gamepadhapticactuator/playeffect/index.md
{{APIRef("Gamepad API")}}
The playEffect() method of the {{domxref("GamepadHapticActuator")}} interface causes the hardware to play a specific vibration effect.
playEffect(type, params)
type
"dual-rumble" and "trigger-rumble", and their effects can vary depending on the hardware type. See {{domxref("GamepadHapticActuator.effects")}} for further details of the effect types.params
: An object to describe a desired haptic effect.
Expected values are:
duration {{optional_inline}}
0.startDelay {{optional_inline}}
0.strongMagnitude {{optional_inline}}
0.0 and 1.0.
Defaults to 0.0.weakMagnitude {{optional_inline}}
0.0 and 1.0.
Defaults to 0.0.leftTrigger (relevant to "trigger-rumble" effects only) {{optional_inline}}
0.0 and 1.0.
Defaults to 0.0.rightTrigger (relevant to "trigger-rumble" effects only) {{optional_inline}}
0.0 and 1.0.
Defaults to 0.0.[!NOTE] A new call to
playEffect()overrides a previous ongoing call.
A promise that resolves with "complete" when the effect successfully completes, or "preempted" if the current effect is stopped or replaced by another effect.
The promise may reject with the following exception types:
InvalidStateError {{domxref("DOMException")}}
NotSupportedError {{domxref("DOMException")}}
type is not supported by the current gamepad's actuator.TypeError {{domxref("DOMException")}}
type is not a valid effect type.const gamepad = navigator.getGamepads()[0];
gamepad.vibrationActuator
.playEffect("dual-rumble", {
startDelay: 0,
duration: 200,
weakMagnitude: 1.0,
strongMagnitude: 1.0,
})
.then((result) => console.log(result));
// Should log "complete" if effect successfully runs
{{Specifications}}
{{Compat}}