From 6b483775e849c2bda21922373835325a303a37d7 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Tue, 4 Apr 2023 05:51:25 +0200 Subject: [PATCH] pulling element to hand --- index.html | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index fc8210a..9b5649b 100644 --- a/index.html +++ b/index.html @@ -2989,8 +2989,21 @@ AFRAME.registerComponent('collider-check', { dependencies: ['raycaster'], init: function () { + let worldPosition=new THREE.Vector3(); + let v3 = new THREE.Vector3 + let comeCloserInterval this.el.addEventListener('raycaster-intersection', function (e) { - console.log('Player hit something!',e.detail); + console.log('intersected') + comeCloserInterval = setInterval( _=> { + document.getElementById("leftHand").object3D.traverse( e => { if (e.name == "wrist") { + worldPosition.copy(e.position);e.parent.updateMatrixWorld();e.parent.localToWorld(worldPosition) + } }) + e.detail.intersections[0]?.object.el.object3D.position.lerp(worldPosition, 0.1) + }, 100) + }); + this.el.addEventListener('raycaster-intersection-cleared', function (e) { + console.log('cleared') + clearInterval( comeCloserInterval ) }); } });