wall haptics

This commit is contained in:
Kevin Ngo
2018-10-22 03:29:17 -07:00
parent 4f6768777c
commit 139b6954a8
5 changed files with 63 additions and 14 deletions

12
package-lock.json generated
View File

@@ -92,9 +92,9 @@
}
},
"aframe-aabb-collider-component": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/aframe-aabb-collider-component/-/aframe-aabb-collider-component-2.2.1.tgz",
"integrity": "sha512-DejvmaP+1Em660oMEPU8C4SYmiRkn7bpq0ttBwqw/N3In8/QODI2S1RYuJHEkZWde6XCfAiSuBpOBcRTnbSn/w=="
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/aframe-aabb-collider-component/-/aframe-aabb-collider-component-3.0.0.tgz",
"integrity": "sha512-xWkE5S8+pET9IYOS95KV8ChrIIJxg3dCpiXS4j7SOKn0Yn3UZ5HHbI8mvQYtq95xuxi7kHD7kjloGrJ89FEQVg=="
},
"aframe-atlas-uvs-component": {
"version": "2.1.0",
@@ -102,9 +102,9 @@
"integrity": "sha512-+zUnGMcj20Lkbth1/nWJjJoKsoc3jOTj8tuD3vy5BjWDha3cpQhBslxekvFL8LcAl88yv0WwD1kfkmLKQKcdvw=="
},
"aframe-audioanalyser-component": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/aframe-audioanalyser-component/-/aframe-audioanalyser-component-5.2.0.tgz",
"integrity": "sha512-RuRvY24t/+lYIeisk6Yko7qXjoW9sfrRiV/QRR1m9W94YeXfSHtK9Zbc8jMlk25VApRpQtrr57iGOS+tru6K7A=="
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/aframe-audioanalyser-component/-/aframe-audioanalyser-component-5.2.1.tgz",
"integrity": "sha512-/nmpBL0j8+RQhxru0aLuuFD3wnLYm5XOKvOFFkjbTPCeLq9qaaKYrUZVqZVqkSOdu9yr3EUiGPlcBC3KXqPTYQ=="
},
"aframe-event-decorators": {
"version": "1.0.2",

View File

@@ -8,9 +8,9 @@
"start": "webpack-dev-server --host 0.0.0.0 --progress --colors --hot --inline --port 3000"
},
"dependencies": {
"aframe-aabb-collider-component": "^2.2.1",
"aframe-aabb-collider-component": "^3.0.0",
"aframe-atlas-uvs-component": "^2.1.0",
"aframe-audioanalyser-component": "^5.2.0",
"aframe-audioanalyser-component": "^5.2.1",
"aframe-event-decorators": "^1.0.2",
"aframe-event-set-component": "^4.0.1",
"aframe-geometry-merger-component": "^2.0.0-beta1",

View File

@@ -0,0 +1,37 @@
/**
* Listen to aabb-collider event for wall haptics.
*/
AFRAME.registerComponent('wall-haptics', {
dependencies: ['aabb-collider'],
init: function () {
const el = this.el;
this.isHittingWall = false;
el.setAttribute('haptics__wall', {dur: 50, force: 0.025});
this.checkIfHittingWall = this.checkIfHittingWall.bind(this);
el.addEventListener('hitstart', this.checkIfHittingWall);
el.addEventListener('hitend', this.checkIfHittingWall);
this.tick = AFRAME.utils.throttleTick(this.tick.bind(this), 50);
},
/**
* On aabb-collider event, check if we are still hitting a wall.
*/
checkIfHittingWall: function () {
const intersectedEls = this.el.components['aabb-collider'].intersectedEls;
this.isHittingWall = false;
for (let i = 0; i < intersectedEls.length; i++) {
if (intersectedEls[i].components.wall) {
this.isHittingWall = true;
return;
}
}
},
tick: function () {
if (!this.isHittingWall) { return; }
this.el.components.haptics__wall.pulse();
}
});

View File

@@ -1,3 +1,6 @@
/**
* Wall speed and haptics.
*/
AFRAME.registerComponent('wall', {
schema: {
speed: {default: 1.0}
@@ -9,23 +12,29 @@ AFRAME.registerComponent('wall', {
pause: function () {
this.el.object3D.visible = false;
this.el.removeAttribute('collidable');
this.el.removeAttribute('data-collidable-head');
this.el.removeAttribute('data-collidable-saber');
},
play: function () {
this.el.object3D.visible = true;
this.el.setAttribute('collidable', '');
this.el.setAttribute('data-collidable-head', '');
this.el.setAttribute('data-collidable-saber', '');
},
tock: function (time, delta) {
this.el.object3D.position.z += this.data.speed * (delta / 1000);
if (this.el.object3D.position.z > this.maxZ) { this.returnToPool(); }
if (this.el.object3D.position.z > this.maxZ) {
this.returnToPool();
return;
}
},
returnToPool: function () {
this.el.sceneEl.components.pool__wall.returnEntity(this.el);
this.el.object3D.position.z = 9999;
this.el.pause();
this.el.removeAttribute('collidable');
this.el.removeAttribute('data-collidable-head');
this.el.removeAttribute('data-collidable-saber');
}
});

View File

@@ -93,7 +93,7 @@
<a-entity
id="cameraCollider"
bind__aabb-collider="enabled: isPlaying"
aabb-collider="objects: [collidable]; interval: 50; collideNonVisible: false"
aabb-collider="objects: [data-collidable-head]; interval: 50; collideNonVisible: false"
geometry="primitive: box; width: 0.25; height: 0.25; depth: 0.25"
proxy-event__wallhitstart="event: hitstart; to: a-scene; as: wallhitstart"
proxy-event__wallhitend="event: hitend; to: a-scene; as: wallhitend"
@@ -103,19 +103,22 @@
{% macro saber (hand, otherHand, bladeColor, beamColor) %}
<a-entity id="{{ hand }}Hand"
mixin="raycaster"
bind__aabb-collider="enabled: isPlaying"
bind__hand-swapper="enabled: {{ otherHand }}RaycasterActive"
bind__menu-controls="page: search.page; selectedChallengeId: menuSelectedChallenge.id"
bind__pauser="enabled: isPlaying"
bind__raycaster="enabled: {{ hand }}RaycasterActive"
bind__saber-controls="bladeEnabled: isPlaying; isPaused: isPaused"
bind__trail="enabled: isPlaying"
aabb-collider="objects: [data-collidable-saber]; interval: 50; collideNonVisible: false"
haptics="events: mouseenter; dur: 35; force: 0.075"
haptics__beat="eventsFrom: #beatContainer; events: beathit{{ hand }}; dur: 80; force: 0.2"
haptics__draw="events: drawblade; dur: 750; force: 0.025"
saber-controls="hand: {{ hand }}"
thumb-controls
thumb-controls-debug="enabled: false; hand: {{ hand }}; controllerType: vive-controls"
trail="color: {{ bladeColor }}; hand: {{ hand }}">
trail="color: {{ bladeColor }}; hand: {{ hand }}"
wall-haptics>
<a-entity
id="{{ hand }}Laser"
bind__visible="menuActive && activeHand === '{{ hand }}'"