continued haptic rumble when sabers touch

This commit is contained in:
Kevin Ngo
2018-12-02 15:02:28 -08:00
parent 7b22c83517
commit ccded32073
2 changed files with 21 additions and 4 deletions

View File

@@ -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();
}
});

View File

@@ -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;