w3c / gamepad

Gamepad
https://w3c.github.io/gamepad/
Other
139 stars 49 forks source link

[Extensions] make pulse() more like navigator.vibrate #66

Closed GrosSacASac closed 5 years ago

GrosSacASac commented 6 years ago

It would be nice to have pulse be like navigator.vibrate or to have something similar

navigator.vibrate(100) // simple value for duration
navigator.vibrate([100,500, 100]) // array for duration, pause duration patterns

Thoughts ?

nondebug commented 6 years ago

I think this is insufficient for the types of vibration effects that are common on gamepads. For instance, most modern gamepads support vibrating at varying intensity levels rather than simple on/off durations as used by navigator.vibrate.

I've proposed an alternate extension for vibration effects, please take a look:

https://github.com/w3c/gamepad/issues/19#issuecomment-321424335

It's used like this:

let pads = navigator.getGamepads();
pads[0].vibrationActuator.playEffect("dual-rumble", {
    startDelay: 0,
    duration: 1000,
    weakMagnitude: 0.5,
    strongMagnitude: 0.5
});

playEffect returns a Promise that resolves once the effect playback is complete. You can take advantage of this to simulate the on/off durations used by navigator.vibrate:

let startEffect = { duration: 100, weakMagnitude: 1.0 };
let continueEffect = { startDelay: 500, duration: 100, weakMagnitude: 1.0 };
pads[0].vibrationActuator.playEffect("dual-rumble", startEffect).then(() => {
    pads[0].vibrationActuator.playEffect("dual-rumble", continueEffect)
});
GrosSacASac commented 5 years ago

closing to continue discussion github.com/w3c/gamepad/issues/19