Last active
August 25, 2023 02:18
-
-
Save esnosy/94bf8a0d8cec14b6b40ee37f0db86617 to your computer and use it in GitHub Desktop.
networked-aframe simple jump component
This file contains 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
// License Public Domain | |
// These constants are arbitrary but make sure they do not accidentally collide with other things | |
const animationAttributeName = 'animation__onkeydown_space'; | |
const animationStartEvent = 'onkeydown_space'; | |
AFRAME.registerComponent('simple-jump', { | |
schema: {}, | |
init: function () { | |
var el = this.el; | |
// Thank you!!!: https://stackoverflow.com/a/47019444/8094047 | |
// https://stackoverflow.com/a/51050251/8094047 | |
el.setAttribute(animationAttributeName, { | |
'property': 'object3D.position.y', | |
'from': 0, | |
'to': 1, | |
'startEvents': animationStartEvent, | |
'dir': 'alternate', | |
'loop': 2, | |
'dur': 300, | |
'easing': 'easeInOutQuad' | |
}); | |
addEventListener('keydown', function (e) { | |
if (e.code === 'Space') { | |
el.emit(animationStartEvent, null, false); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment