简体   繁体   English

在Aframe中跟踪传送位置的最佳方法是什么?

[英]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.

相关问题 将元素放在div中的最佳方法是什么? - what is the best way to position elements inside of a div 在查看器中放置html的最佳方法是什么? - What is the best way to position html in the viewer? 跟踪实时通知发送给用户的最佳方法是什么? - What's the best way to keep track of live notifications to send to a user? 通过javascript跟踪表单中的更改的最佳方法是什么? - What is the best way to track changes in a form via javascript? 在谷歌分析中跟踪 facebook 评论小部件的最佳方法是什么? - What is the best way to track facebook comment widget in google analytics? 进行原型制作时跟踪javascript对象引用的最佳方法是什么 - What the best way to keep track of a javascript object reference when prototyping 跟踪Jquery和CSS标识符的最佳方法是什么? - What is the best way keep track of your identifiers for your Jquery and CSS? 在MongoDB中跟踪文档属性更改的最佳方法是什么? - What is the best way to keep track of changes of a document's property in MongoDB? 在 requestAnimationFrame 游戏循环中跟踪时间/帧的最佳方法是什么? - What is the best way to track time/frames in a requestAnimationFrame game loop? 在嵌套的ng-repeat中通过$ index跟踪的最佳方法是什么? - What would be the best way to track by $index in nested ng-repeat?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM