1
votes

i need to know how can i get a camera cursor position and add entity on that position i check many solution as like how can i add entity on cursor position using aFrame here is my code example `

  <a-text font="kelsonsans" value="Puy de Sancy, France" width="6" position="2 11 0"
          rotation="0 15 0"></a-text>
          
          <a-camera camera-logger id="camera"> <a-cursor fuse="true" color="yellow"></a-cursor> </a-camera>
</a-scene>`

here is my JS code

  function getPos(){
     var cameraEl = document.querySelector('#camera');
     var WorldPosition = cameraEl.object3D.getWorldPosition();
     var pos = cameraEl.getAttribute('position');
     var rot = cameraEl.getAttribute('rotation');
     console.log(WorldPosition);
     console.log(pos);
     console.log(rot);
  }

but when i try to set entity position as per below out put it's not showing on that location because it's showing like position coordinates "x: -5.385803274229736, y: 69.90085100596048, z: 0"
but aframe position coordinates are difference Might be it's a ThreeJs Position please help me with the full solution

2

2 Answers

2
votes

As of AFRAME 1.0.4, JULY 2020:

Kevin knows his shit on this topic obviously, but his answer didn't work for me either; I presume it's because of changes since 1.0.0 in aframe.

The only thing wrong was that cursor.components.intersectedEl does not seem to be a thing anymore. Still, at least for my case, that was easy to get around because I knew the object I wanted intersections from, and so could listen for mouseenter and mouseleave events.

Won't solve every situation, but for the next guy:

var cursor = document.querySelector('[cursor]');
var elToWatch = document.querySelector('[gameboard]')
var intersection = cursor.components.raycaster.getIntersection(elToWatch);
var intersectionPosition = intersection.point;
1
votes

Here's how to get the intersection data from the cursor.

var cursor = document.querySelector('a-cursor'); 
if (!cursor.components.intersectedEl) { return; }
var intersection = cursor.components.raycaster.getIntersection(cursor.components.intersectedEl);
var intersectionPosition = intersection.point;

I think in master, cursor event detail contains a reference to getIntersection so you can call like evt.detail.getIntersection(evt.detail.intersectedEl).