Aframe 如何使用setAttribute更改对象在A帧中的位置?

Aframe 如何使用setAttribute更改对象在A帧中的位置?,aframe,virtual-reality,webvr,Aframe,Virtual Reality,Webvr,我在0.8.0中面临这个问题。我的 <a-sphere id="ball" position="-1 0.59 -4"></a-sphere> 但它们似乎都不起作用 我正在构建一个应用程序,其中球的位置将更改为单击光标的点 两种方法: document.getElementById("ball").setAttribute('position', '-3 0.59 -3') document.getElementById("ball").setAttribute('po

我在0.8.0中面临这个问题。我的

<a-sphere id="ball" position="-1 0.59 -4"></a-sphere>
但它们似乎都不起作用

我正在构建一个应用程序,其中球的位置将更改为单击光标的点

两种方法:

document.getElementById("ball").setAttribute('position', '-3 0.59 -3')
document.getElementById("ball").setAttribute('position', {x:-3, y:0.59, z:-3})
正确,并将球移动到选定位置。在我的网站上查看。
您:
1。在加载场景之前调用方法,因此无法抓取球
2。未将光标或鼠标设置为使用渲染对象
设置鼠标很简单-只需将
光标
组件添加到场景:

<a-scene cursor="rayOrigin: mouse">
如果您不熟悉组件系统,请确保检查它们

<a-scene cursor="rayOrigin: mouse">
 AFRAME.registerComponent("foo", {
   init: function() {
      this.el.addEventListener("click", (e)=>{
        //do Your thing here
      })
   }
 })