【发布时间】:2021-11-24 01:13:24
【问题描述】:
我有一些代码可以限制相机在 A 帧中的移动,所以当相机从起点移动 10 个空间时,它们会被传送回位置 0、1.6、0。目前,这适用于玩家 x或 y 轴从起点移动 10 个空格。我该如何修改它,以便玩家只有在仅他们的 y 位置从他们的起点移动 10 个空格时才会被传送回来?代码:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<meta charset="UTF-8" />
</head>
<body>
<script>
AFRAME.registerComponent('limit-my-distance', {
init: function() {
this.zero = new THREE.Vector3(0, 0, 0);
},
tick: function() {
if (this.el.object3D.position.distanceTo(this.zero) > 10) {
this.el.object3D.position.set(0, 1.6, 0);
}
}
});
</script>
<a-scene>
<a-sphere position="0 2 -10"color="red"></a-sphere>
<a-plane color="green" position="0 0 -5" rotation="-90 0 0" width="20" height="20"></a-plane>
<a-camera limit-my-distance></a-camera>
<a-sky color="#fff"></a-sky>
</a-scene>
</body>
</html>
【问题讨论】:
标签: javascript three.js aframe webvr