Passare verso un obiettivo
-
15-11-2019 - |
Domanda
Quali sono gli altri script per fare un oggetto passare a un obiettivo?In questo momento sto usando il metodo Vector3.Lerp
.Questo funziona, ma il gameobject in movimento rallenta più vicino al suo obiettivo.Non succederò.Deve muoversi direttamente verso l'obiettivo senza rallentare.
Guida è apprezzata.
Soluzione
One approach is just to work out the direction it should head in and then move at a constant speed in that direction:
function Update() {
var dir = target - transform.position;
dir.Normalize();
transform.position += dir * speed * Time.deltaTime;
}
You'd have to make it a little more complicated than that so that it doesn't overshoot on the final frame, but this should give you a crude approximation of what you want.
Altri suggerimenti
You can use this function:
Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
It should do exactly what you want.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow