I am trying to capture the event raycaster-intersected
every time it happens.
To handle collisions, I need to know the distance to the first entity detected, but the event only triggers the first time the raycaster hits an entity.
If the raycaster continues to touch the entity, the event does not trigger again.
Here is the code snippet I have:
AFRAME.registerComponent("follow-body", {
'schema': {
entityId: {
type:'string',
default:''
}
},
init: function(){
this.pibot = document.querySelector("#" + this.data.entityId);
},
tick: function(){
let pibotPos = this.pibot.object3D.position;
let pibotRotation = this.pibot.object3D.rotation;
let el = this.el;
pibotPos.y += 0.2;
el.object3D.position.set(pibotPos.x, pibotPos.y, pibotPos.z);
el.object3D.rotation.set(pibotRotation.x, pibotRotation.y, pibotRotation.z);
el.addEventListener('raycaster-intersection', function(evt){
var e = new CustomEvent('intersection-detected', {detail: evt.detail});
this.dispatchEvent(e);
});
}
});