繁体   English   中英

如果触摸 object 移动到位置框架

[英]if touching object move to location aframe

我想知道如果相机从点 0 0 0 到达 20 个空间以将它们传送回该点,那么如何在框架中实现。 这样的事情是容易实现还是困难? 我怎样才能做到这一点。

You can get the position of the object using el.object3D.position - that would return x,y,z vector or you can use el.object3D.position.x (or.y /.z for just one axis).

您还可以使用相同的 function el.object3D.position.x = 23.12设置 position。

正如@Piotr Adam Milewski 所说,您需要计算距离 - 您可以使用以下表达式distance = sqrt(x^2 + y^2 + z^2)或使用THREE.Vector3.distanceTo()然后进行比较设置为某个值并相应地设置 position (相机默认 position 为0, 1.6, 0而不是0, 0, 0 )。

一个非常简单的例子:

 <: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). } //this.el.object3D.position.x += 0;1; } }); </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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM