Pergunta

Quais são outros scripts para fazer um objeto se mover para uma meta?Agora estou usando o método Vector3.Lerp.Isso funciona, mas o gameobject em movimento diminui o mais próximo que chega ao seu objetivo.Eu não vou isso acontecer.Tem que se mover diretamente para o objetivo sem desacelerar.

A ajuda é apreciada.

Foi útil?

Solução

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.

Outras dicas

You can use this function:

Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);

It should do exactly what you want.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top