我正在使用 A-Frame 并希望一个对象与相机一起移动。为此,我组装了一个组件,该组件根据相机位置更新对象的位置:
AFRAME.registerComponent('follow', {
schema: {
distance: {type: 'vec3'},
target: {type: 'selector'}
},
tick: function() {
const targetItem = this.data.target;
const relativePosition = this.data.distance
var tempPos = targetItem.getAttribute("position").split(" ").map(Number);
targetPos = new THREE.Vector3(relativePosition.x + tempPos[0], relativePosition.y + tempPos[1], relativePosition.z + tempPos[2]);
this.el.setAttribute('position', targetPos)
}
});
当我使用init
而不是,这工作正常,tick
但由于它是一个初始化函数,它只在场景开始时更新一次。出于某种原因,当我使用tick
一切都会中断。我用错了吗?我应该做一些不同的事情来不断更新它的位置吗?
提前致谢!
编辑:我应该提到目标是让一些东西跟随,但不要固定在你的观点上。想想《时之笛》中的 Navi。