-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjump.js
32 lines (25 loc) · 779 Bytes
/
jump.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const JUMP_KEY = ' ';
AFRAME.registerComponent('jump', {
schema: {
height: {
type: 'number',
},
interval: {
type: 'number'
},
timingFunction: {
type: 'string'
},
},
init: function() {
document.addEventListener('keydown', e => {
if (e.key != JUMP_KEY) return;
const upInterval = setInterval(() => this.el.object3D.position.y += this.data.height / this.data.interval, 10);
setTimeout(() => {
clearInterval(upInterval);
const downInterval = setInterval(() => this.el.object3D.position.y -= this.data.height / this.data.interval, 10);
setTimeout(() => clearInterval(downInterval), this.data.interval / 2);
}, this.data.interval / 2);
});
},
});