Skip to content

Instantly share code, notes, and snippets.

@sorskoot
Last active March 14, 2022 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorskoot/7af51a23cb01ddb3cab653847eaa9a88 to your computer and use it in GitHub Desktop.
Save sorskoot/7af51a23cb01ddb3cab653847eaa9a88 to your computer and use it in GitHub Desktop.
Example of a Wonderland component that adds Haptic feedback
WL.registerComponent('gun', {}, {
start: function () {
this.input = this.object.getComponent('input');
this.initialized = false;
WL.onXRSessionStart.push((session) => {
if (this.initialized) return;
session.addEventListener('select', (e) => {
if(!this.active) return;
if (e.inputSource.handedness === this.input.handedness) {
this.pulse(e.inputSource.gamepad);
// Add the rest of the shooting mechanic
}
});
this.initialized = true;
})
},
pulse: function (gamepad) {
let actuator;
if (!gamepad || !gamepad.hapticActuators) { return; }
actuator = gamepad.hapticActuators[0];
if(!actuator) return;
actuator.pulse(1, 100);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment