diff --git a/src/components/haptics-saber.js b/src/components/haptics-saber.js index e07203d..0ffd357 100644 --- a/src/components/haptics-saber.js +++ b/src/components/haptics-saber.js @@ -4,15 +4,32 @@ AFRAME.registerComponent('haptics-saber', { init: function () { const el = this.el; - el.setAttribute('haptics__saber', {dur: 100, force: 0.025}); + + this.isColliding = false; + this.tick = AFRAME.utils.throttleTick(this.tick.bind(this), 100); + + el.setAttribute('haptics__saber', {dur: 100, force: 0.1}); el.addEventListener('mouseenter', evt => { if (!evt.detail || !evt.detail.intersectedEl) { return; } const intersectedEl = evt.detail.intersectedEl; - if (!intersectedEl.classList.contains('blade') || intersectedEl === el) { return; } + if (!intersectedEl.classList.contains('blade') || intersectedEl === el) { + this.isColliding = false; + return; + } + this.isColliding = true; this.el.components.haptics__saber.pulse(); }); + + el.addEventListener('mouseleave', evt => { + this.isColliding = false; + }); + }, + + tick: function () { + if (!this.isColliding) { return; } + this.el.components.haptics__saber.pulse(); } }); diff --git a/src/components/haptics-wall.js b/src/components/haptics-wall.js index 1cb7fbd..e50a7b7 100644 --- a/src/components/haptics-wall.js +++ b/src/components/haptics-wall.js @@ -5,7 +5,7 @@ AFRAME.registerComponent('haptics-wall', { init: function () { const el = this.el; this.isHittingWall = false; - el.setAttribute('haptics__wall', {dur: 50, force: 0.025}); + el.setAttribute('haptics__wall', {dur: 50, force: 0.1}); this.checkIfHittingWall = this.checkIfHittingWall.bind(this); el.addEventListener('mouseenter', this.checkIfHittingWall); @@ -15,7 +15,7 @@ AFRAME.registerComponent('haptics-wall', { }, /** - * On aabb-collider event, check if we are still hitting a wall. + * On raycaster event, check if we are still hitting a wall. */ checkIfHittingWall: function () { const intersectedEls = this.el.components.raycaster__game.intersectedEls;