use raycaster over aabb-collider for saber collisions

This commit is contained in:
Kevin Ngo
2018-11-04 19:28:10 +08:00
parent 0139133dc3
commit 36b7032418
7 changed files with 45 additions and 33 deletions

View File

@@ -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) {