[英]What is the best way to track teleport position in Aframe?
I am using the aframe-teleport-controls and I was wondering what is the best way to track the position of the user. 我正在使用aframe-teleport-controls ,我想知道什么是跟踪用户位置的最佳方法。
I've been searching and I found two ways to do that. 我一直在搜索,发现了两种方法可以做到这一点。
1 - I use the position of the teleport controller which is almost the position of the user. 1-我使用的是瞬移控制器的位置,几乎是用户的位置。
var teleportControls = el.closest('a-scene').querySelector('[teleport-controls]');
var worldPos = new THREE.Vector3();
worldPos.setFromMatrixPosition(teleportControls.object3D.matrixWorld);
console.log(worldPos);
2 - I define an a-camera element in my scene and I use his position. 2-我在场景中定义了一个相机元素,并使用了他的位置。
var teleportControls = el.closest('a-scene').querySelector('a-camera');
var worldPos = new THREE.Vector3();
worldPos.setFromMatrixPosition(teleportControls.object3D.matrixWorld);
console.log(worldPos);
I'm not sure it is the good practice, and how can I listen that the user change his position? 我不确定这是否是个好习惯,如何听用户更改位置?
Thanks for reading this. 感谢您阅读本文。
The controller element (not the camera) will emit a teleport
event when the user teleports (found in source here ). 当用户进行传送(在此处的源代码中找到 )时,控制器元素(不是摄像机)将发出
teleport
事件。 The easiest way to detect those events would be to listen on the scene element, as the events bubble up. 检测这些事件的最简单方法是在事件冒泡时侦听场景元素。
sceneEl.addEventListener('teleport', function (e) {
console.log(e.detail.oldPosition, e.detail.newPosition);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.