use raycaster over aabb-collider for saber collisions
This commit is contained in:
@@ -5,6 +5,10 @@
|
||||
AFRAME.registerComponent('cursor-laser', {
|
||||
dependencies: ['geometry'],
|
||||
|
||||
schema: {
|
||||
enabled: {default: true}
|
||||
},
|
||||
|
||||
init: function () {
|
||||
const el = this.el;
|
||||
const box = new THREE.Box3();
|
||||
@@ -21,9 +25,15 @@ AFRAME.registerComponent('cursor-laser', {
|
||||
this.currentLength = size.y;
|
||||
},
|
||||
|
||||
update: function () {
|
||||
this.el.object3D.visible = this.data.enabled;
|
||||
},
|
||||
|
||||
tick: function () {
|
||||
const el = this.el;
|
||||
|
||||
if (!this.data.enabled) { return; }
|
||||
|
||||
const cursor = el.parentNode.components.cursor;
|
||||
if (!cursor) { return; }
|
||||
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
* 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; }
|
||||
el.addEventListener('mouseenter', evt => {
|
||||
if (!evt.detail || !evt.detail.intersectedEl) { return; }
|
||||
|
||||
const intersectedEl = evt.detail.intersectedEl;
|
||||
if (!intersectedEl.classList.contains('blade') || intersectedEl === el) { return; }
|
||||
|
||||
this.el.components.haptics__saber.pulse();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,16 +2,14 @@
|
||||
* Listen to aabb-collider event for wall haptics.
|
||||
*/
|
||||
AFRAME.registerComponent('haptics-wall', {
|
||||
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);
|
||||
el.addEventListener('mouseenter', this.checkIfHittingWall);
|
||||
el.addEventListener('mouseleave', this.checkIfHittingWall);
|
||||
|
||||
this.tick = AFRAME.utils.throttleTick(this.tick.bind(this), 50);
|
||||
},
|
||||
@@ -20,7 +18,7 @@ AFRAME.registerComponent('haptics-wall', {
|
||||
* On aabb-collider event, check if we are still hitting a wall.
|
||||
*/
|
||||
checkIfHittingWall: function () {
|
||||
const intersectedEls = this.el.components['aabb-collider'].intersectedEls;
|
||||
const intersectedEls = this.el.components.raycaster__game.intersectedEls;
|
||||
this.isHittingWall = false;
|
||||
for (let i = 0; i < intersectedEls.length; i++) {
|
||||
if (intersectedEls[i].components.wall) {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
AFRAME.registerComponent('raycastable', {});
|
||||
@@ -13,13 +13,13 @@ AFRAME.registerComponent('wall', {
|
||||
pause: function () {
|
||||
this.el.object3D.visible = false;
|
||||
this.el.removeAttribute('data-collidable-head');
|
||||
this.el.removeAttribute('data-collidable-saber');
|
||||
this.el.removeAttribute('raycastable-game');
|
||||
},
|
||||
|
||||
play: function () {
|
||||
this.el.object3D.visible = true;
|
||||
this.el.setAttribute('data-collidable-head', '');
|
||||
this.el.setAttribute('data-collidable-saber', '');
|
||||
this.el.setAttribute('raycastable-game', '');
|
||||
},
|
||||
|
||||
tock: function (time, delta) {
|
||||
@@ -35,6 +35,6 @@ AFRAME.registerComponent('wall', {
|
||||
this.el.object3D.position.z = 9999;
|
||||
this.el.pause();
|
||||
this.el.removeAttribute('data-collidable-head');
|
||||
this.el.removeAttribute('data-collidable-saber');
|
||||
this.el.removeAttribute('raycastable-game');
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user