如何使用加速度计更改 aframe vr 中的相机 position/walk?
How to change camera position/walk in aframe vr with accelerometer?
(我知道会不稳定但还是想试试)
我想使用加速度计在框架场景中四处移动
AFRAME.registerComponent('acccam',{
window.addEventListener('devicemotion', function(){
var acc = event.acceleration;
this.el.object3D.position.x += acc.x*9.8;
this.el.object3D.position.y += acc.y*9.8;
this.el.object3D.position.z += acc.z*9.8;
}, true);
})
我希望相机移动或至少 shake/something 但什么都没有发生 getelement by id, get attribute 和 set attribute 用于通过获取临时值然后克隆它们来更新位置如果是的话怎么样?
确保事件正在触发,并确保您没有在同一实体上启用类似 look-controls
的功能,否则它将被覆盖。
您可能需要确保 this
是正确的指针。当您换行 function ()
时,this
变为 window
。您可以使用 (evt) => {
而不是 function (evt) {
(我知道会不稳定但还是想试试)
我想使用加速度计在框架场景中四处移动
AFRAME.registerComponent('acccam',{
window.addEventListener('devicemotion', function(){
var acc = event.acceleration;
this.el.object3D.position.x += acc.x*9.8;
this.el.object3D.position.y += acc.y*9.8;
this.el.object3D.position.z += acc.z*9.8;
}, true);
})
我希望相机移动或至少 shake/something 但什么都没有发生 getelement by id, get attribute 和 set attribute 用于通过获取临时值然后克隆它们来更新位置如果是的话怎么样?
确保事件正在触发,并确保您没有在同一实体上启用类似 look-controls
的功能,否则它将被覆盖。
您可能需要确保 this
是正确的指针。当您换行 function ()
时,this
变为 window
。您可以使用 (evt) => {
而不是 function (evt) {