【问题标题】:What is the best way to track teleport position in Aframe?在 Aframe 中跟踪传送位置的最佳方法是什么?
【发布时间】:2017-06-09 06:05:19
【问题描述】:

我正在使用aframe-teleport-controls,我想知道跟踪用户位置的最佳方法是什么。

我一直在寻找,发现了两种方法。

1 - 我使用传送控制器的位置,这几乎是用户的位置。

var teleportControls = el.closest('a-scene').querySelector('[teleport-controls]');
var worldPos = new THREE.Vector3();
worldPos.setFromMatrixPosition(teleportControls.object3D.matrixWorld);
console.log(worldPos);

2 - 我在场景中定义了一个相机元素并使用了他的位置。

var teleportControls = el.closest('a-scene').querySelector('a-camera');
var worldPos = new THREE.Vector3();
worldPos.setFromMatrixPosition(teleportControls.object3D.matrixWorld);
console.log(worldPos);

我不确定这是一种好的做法,我如何才能听到用户改变了他的位置?

感谢您阅读本文。

【问题讨论】:

    标签: javascript aframe webvr


    【解决方案1】:

    控制器元素(不是相机)将在用户传送时发出teleport 事件(在source here 中找到)。检测这些事件的最简单方法是在事件冒泡时监听场景元素。

    sceneEl.addEventListener('teleport', function (e) {
      console.log(e.detail.oldPosition, e.detail.newPosition);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多