How to make Vector2.MoveTowards keep GameObject moving after it reaches target position

Hi. I’m making a game and want missiles to get fired at the player.

I found the function Vector2.MoveTowards, the problem is that the function makes the missile stop once it has reached its targets position.

  • Is there any way to make it carry on in the same trajectory?

  • Or is there another function that just gives me the amount you need to move per frame by the x and y coordinates to get to the target position?

vectors 101

Vector3 toTarget = target - myPosition;
Vector3 direction = toTarget.normalized;
Vector3 velocity = direction * speed;
Vector3 stepThisFrame = velocity * Time.deltaTime
transform.position += stepThisFrame;

To make it a dumb missile either calculate it’s direction once only and store this value in a class field or stop updating it after some condition is met (time, distance etc).

See velocity or stepThisFrame.