我正在尝试创建一种变通方法,以便在移动设备上的A帧场景中四处走动,因为在我的情况下,远距传输并不是一种选择。如果用户向下看,我希望他朝相机的方向移动。
使用以下代码,可以很好地工作:
AFRAME.registerComponent('rotation-reader', {
tick: function () {
var rotation = this.el.getAttribute('rotation');
if (rotation.x < -30) {
this.player = document.querySelector("#player");
var x = 0.1 * Math.cos(rotation.y * Math.PI / 180);
var y = 0.1 * Math.sin(rotation.y * Math.PI / 180);
var pos = this.player.getAttribute("position");
pos.x -= y;
pos.z -= x;
this.player.setAttribute("position", pos);
}
}
});
相机实体:
<a-entity id="player"
camera rotation-reader
universal-controls="movementEasing: 15; movementAcceleration: 50;" kinematic-body position="0 2.45 -17;" rotation="0 180 0;“></entity>
但是,如果它们在俯视时仍在移动,则将忽略该静态组件,从而使用户能够在分配了静态组件的墙壁和其他实体之间移动。有什么办法可以解决这个问题?
我正在使用a.frame 0.7.1和aframe-extras。
编辑:这是一个简单的示例(使用wasd / arrow键移动时适用于静态物体,但是当向下看时向前移动会忽略静态物体):https://hollow-salt.glitch.me/