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

619
Views
¿Cómo debo calcular la velocidad de un Lerp?

Tengo una declaración de Vector2 Lerp:

 Vector2.Lerp(spawnPos, target, position);

La variable de position es un número entre 0 y 1 y, para todos los efectos, se incrementa con el tiempo. Piense en la forma en que estoy rastreando la position como un "cabezal de reproducción", como en la música o la animación, donde un cursor se mueve de izquierda a derecha a medida que continúa la reproducción.

Quiero que el objeto continúe moviéndose después de alcanzar su objetivo, a la misma velocidad EXACTA, infinitamente en una dirección. Intenté cambiar el objetivo a la dirección multiplicada por la distancia entre el punto de generación, pero aún no sé cómo obtener la velocidad correcta.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Gracias al comentario de Llama , pude calcular la velocidad de un Lerp.

Primero, registre la hora de inicio y finalización de la interpolación, y si la interpolación se ha completado o no ( position >= 1 ). Luego, si no ha terminado, lee como de costumbre. Si HA terminado, anote la hora de finalización, calcule la velocidad y la dirección en la que se moverá e incremente Transform.position en ese valor.

 bool finished = false; // Since I'm using AudioSettings.dspTime, I need to use double. // Most forms of telling time in Unity will use float double startTime; double endTime; void Start() { // This is what I am using for my game, // but you can use any way of telling time that Unity/C# provides. startTime = AudioSettings.dspTime; } void Update() { if(!finished) { // interpolate transform.position = Vector2.Lerp(spawnPos, targetPos, position); if(position >= 1) { // Record our end time endTime = AudioSettings.dspTime; finished = true } } else { // How long it took to lerp double lerpTime = endTime - startTime; // How far we lerped float distance = Vector2.Distance(spawnPos, targetPos); // The speed to further move float speed = distance / (float)lerpTime; // The direction in which to move Vector2 direction = (targetPos - spawnPos).normalized; // Continue moving transform.position += (Vector3)direction * speed * Time.deltaTime; } }
over 4 years ago · Santiago Trujillo Report

0

Una respuesta un poco más fácil para usted: en lugar de usar Vector2.Lerp y calcular todo, simplemente use Vector2.LerpUnclamped e ingrese cualquier valor de t que desee.

over 4 years ago · Santiago Trujillo 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!