Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用对象';A帧中事件的位置_Javascript_Html_Three.js_Aframe - Fatal编程技术网

Javascript 使用对象';A帧中事件的位置

Javascript 使用对象';A帧中事件的位置,javascript,html,three.js,aframe,Javascript,Html,Three.js,Aframe,我正在尝试制作一个组件,用于检查球体在一个帧场景中的当前位置,以及当它到达特定坐标时,以及当它触发事件时(在下面的示例中,它将其重置为默认位置): AFRAME.registerComponent(“轨迹球”{ 更新:函数(){ 设pos=this.el.getAttribute(“位置”); 如果(pos={x:-21.821,y:1,z:0}) { 该.el.setAttribute(“位置”,“-21.821 5 0”); } } }); 我不确定调用.getAttribute(“pos

我正在尝试制作一个组件,用于检查球体在一个帧场景中的当前位置,以及当它到达特定坐标时,以及当它触发事件时(在下面的示例中,它将其重置为默认位置):

AFRAME.registerComponent(“轨迹球”{
更新:函数(){
设pos=this.el.getAttribute(“位置”);
如果(pos={x:-21.821,y:1,z:0})
{
该.el.setAttribute(“位置”,“-21.821 5 0”);
}
}
});

我不确定调用
.getAttribute(“position”)
时返回的是什么格式,这可能就是它不工作的原因。我正在运行Frame 1.1.0。

首先,当通过
setAttribute()
更改属性时,将调用
更新
。如果希望在每个渲染帧上调用函数,请使用
tick()

其次,尝试使用范围,而不是固定点,对象很可能会在两个刻度之间移动过该点

大概是这样的:


注册表组件(“轨迹球”{
勾选:函数(){
设pos=this.el.getAttribute(“位置”);
如果(位置y<0.5){
//复位位置
此.el.setAttribute(“位置”,“03-4”)
//同步
this.el.components[“dynamic body”].syncToPhysics();
}
}
});

使用特定点可能很难检测,我宁愿尝试使用
pos.y<1和&pos.z<-21.821
哦,使用像
(pos.x>-23和&pos.x<-20)和&(pos.y>0和&pos.y<2)和&(pos.z>-1和&pos.z<2)这样的范围。
是的。我正要把这个作为答案贴出来。我没有意识到只有在调用
.setAttribute()
时才会触发
update
。现在可以了。这正是我的代码看起来的样子well@ProtocolAlpha我还想到了一件事——看看editI,我从来都不擅长3.js代码。所以我使用了一个框架代码。@ProtocolAlpha它迟早会成为必要的,它只是出现在我的脑海中,因为它在