Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
A-frame limite cámaras y distancia

Tengo un código que restringe el movimiento de la cámara en el cuadro A, por lo que cuando la cámara se aleja 10 espacios del punto de partida, se teletransportan a la posición 0, 1.6, 0. Actualmente, esto funciona en los ejes x o y de los jugadores. se aleja 10 espacios de su punto de partida. ¿Cómo puedo modificar esto para que el jugador solo se teletransporte de regreso si solo su posición y se mueve 10 espacios desde su punto de partida? Código:

 <!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>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Si desea verificar solo el eje y , entonces es tan simple como verificar la diferencia de dos números:

 // distance = |y_position - y_start| const y = this.el.object3D.position.y; const distance = Math.abs(0 - y); if (distance > 10) {// do your stuff}

Algo como esto:

 <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script> <script> AFRAME.registerComponent('limit-my-distance', { tick: function() { if (Math.abs(this.el.object3D.position.y) > 3) { this.el.object3D.position.y = 2; } } }); AFRAME.registerComponent("fall", { tick: function() { this.el.object3D.position.y -= 0.15 } }) </script> <a-scene> <a-sphere position="0 2 -5" color="red" fall limit-my-distance></a-sphere> <a-plane color="green" position="0 0 -5" rotation="-90 0 0" width="20" height="20" material="wireframe: true"></a-plane> <a-camera></a-camera> </a-scene>

about 4 years ago · Juan Pablo Isaza Report

0

¡incluso puedes hacer algo como esto para no quedar atrapado en las paredes en la posición 4 a tu alrededor! Aquí también con la configuración de movimiento de la cámara WASD

 <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script> <script> AFRAME.registerComponent('limit-my-distance', { init: function() { // nothing here }, tick: function() { // limit Z if (this.el.object3D.position.z > 3.8) { this.el.object3D.position.z = 3.8; } if (this.el.object3D.position.z < -3.8) { this.el.object3D.position.z = -3.8; } // limit X if (this.el.object3D.position.x > 3.8) { this.el.object3D.position.x = 3.8; } if (this.el.object3D.position.x < -3.8) { this.el.object3D.position.x = -3.8; } } }); </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 look-controls wasd-controls="acceleration:10" position="0 1.6 0"></a-camera> <a-sky color="#fff"></a-sky> </a-scene>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!