Search code examples
aframevirtual-reality

How to follow raycaster intersection coordinates on an entity?


I'm trying to use the raycaster to draw on a plane.

I know how to be notified when the raycaster and the plane intersect but after that i don't know how to get updated coordinates of the intersection while the raycaster is moving acrosse the plane.


Solution

  • AFRAME.registerComponent('raycaster-listen', {
      init: function () {
        this.raycaster = document.querySelector('#myRay');
      },
    
      tick: function () {
        var intersection = this.raycaster.components.raycaster.getIntersection(this.el);
        if (!intersection) { return; }
        console.log(intersection);
      }
    });
    
    <a-entity geometry material raycaster-listen></a-entity>