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

109
Views
Rotación suave de la torreta 2d que tiene en cuenta el envoltorio

Deseo hacer una torreta en un juego 2d, que debería girar suavemente al ángulo del mouse. Se me ocurrieron dos soluciones, pero ninguna es satisfactoria. El primero:

 currentRot = targetRot; // Produces snapping + doesn't look realistic

El segundo, inspirado en Girar suavemente la torreta y mantener la precisión :

 if (currentRot < targetRot) { currentRot += 2; if(currentRot > targetRot) { currentRot = targetRot; } } if (currentRot > targetRot) { currentRot -= 2; if(currentRot < targetRot) { currentRot = targetRot; } }

Sin embargo, el segundo enfoque no gira en la dirección óptima todo el tiempo. El código no "sabe" qué forma de rotar es más corta. No puedo usar bibliotecas y creo que los cuaterniones son excesivos, así que no estoy seguro de cómo resolver este problema. Además, ¿hay un tercer enfoque que sea más simple/mejor?

Otra información: targetRot es de 0°-360°

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

¡Encontré una solución con queso, después de mucho tiempo! Esto fue extrañamente desafiante. Sin embargo, todavía siento que mi solución no fue óptima

Solo comprueba qué camino es más corto

 var dp = /*world distance from currentRot to targetRot+5 on unitcircle*/ var dp = /*world distance from currentRot to targetRot-5 on unitcircle*/ if (currentRot < targetRot) { currentRot += rate * (dp < dm ? -1 : 1); if (currentRot > targetRot) { currentRot = targetRot; } } if (currentRot > targetRot) { currentRot -= rate * (dp < dm ? 1 : -1); if(currentRot < targetRot) { currentRot = targetRot; } }

y también esta línea corrigió algunos errores

 if (currentRot < 0) {currentRot += 360;}
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!