Last active
March 14, 2022 21:29
-
-
Save sorskoot/7af51a23cb01ddb3cab653847eaa9a88 to your computer and use it in GitHub Desktop.
Example of a Wonderland component that adds Haptic feedback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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