haptics on saber collide

This commit is contained in:
Kevin Ngo
2018-10-23 06:26:42 -07:00
parent 620f0a2846
commit bbea47911c
5 changed files with 27 additions and 7 deletions

6
package-lock.json generated
View File

@@ -92,9 +92,9 @@
}
},
"aframe-aabb-collider-component": {
"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=="
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/aframe-aabb-collider-component/-/aframe-aabb-collider-component-3.1.0.tgz",
"integrity": "sha512-aJ8EhBf2VLyGV/wi84Hkxf8RGQyij1pMtvy/536LLvbO3Y1JVHkP1Yk/FWOizhqJJ73IPo+dSDICz+tw/uYzng=="
},
"aframe-atlas-uvs-component": {
"version": "2.1.0",

View File

@@ -8,7 +8,7 @@
"start": "webpack-dev-server --host 0.0.0.0 --progress --colors --hot --inline --port 3000"
},
"dependencies": {
"aframe-aabb-collider-component": "^3.0.0",
"aframe-aabb-collider-component": "^3.1.0",
"aframe-atlas-uvs-component": "^2.1.0",
"aframe-audioanalyser-component": "^5.2.1",
"aframe-event-decorators": "^1.0.2",

View File

@@ -0,0 +1,17 @@
/**
* Haptics when sabers collide.
*/
AFRAME.registerComponent('haptics-saber', {
dependencies: ['aabb-collider'],
init: function () {
const el = this.el;
el.setAttribute('haptics__saber', {dur: 100, force: 0.025});
el.addEventListener('hitclosest', evt => {
if (!evt.detail || !evt.detail.el.classList.contains('saber') ||
evt.detail.el === el) { return; }
this.el.components.haptics__saber.pulse();
});
}
});

View File

@@ -1,7 +1,7 @@
/**
* Listen to aabb-collider event for wall haptics.
*/
AFRAME.registerComponent('wall-haptics', {
AFRAME.registerComponent('haptics-wall', {
dependencies: ['aabb-collider'],
init: function () {

View File

@@ -102,6 +102,7 @@
{% macro saber (hand, otherHand, bladeColor, beamColor) %}
<a-entity id="{{ hand }}Hand"
class="saber"
mixin="raycaster"
bind__aabb-collider="enabled: isPlaying"
bind__hand-swapper="enabled: {{ otherHand }}RaycasterActive"
@@ -110,15 +111,17 @@
bind__raycaster="enabled: {{ hand }}RaycasterActive"
bind__saber-controls="bladeEnabled: isPlaying; isPaused: isPaused"
bind__trail="enabled: isPlaying"
bind-toggle__data-collidable-saber="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 }}"
haptics-saber
haptics-wall
thumb-controls
thumb-controls-debug="enabled: false; hand: {{ hand }}; controllerType: vive-controls"
trail="color: {{ bladeColor }}; hand: {{ hand }}"
wall-haptics>
trail="color: {{ bladeColor }}; hand: {{ hand }}">
<a-entity
id="{{ hand }}Laser"
bind__visible="menuActive && activeHand === '{{ hand }}'"