# Moving an object from A to B with a certain speed

I’m trying to make a “Hook” sprite move from its position to a fish with a certain speed using Vector2.Lerp() functio, but the problem is, it seems that the sprite teleports (in high speed), I tried a while loop to add distance, but still teleports.
How can I make it go slowly ? (maybe using “Time” class)

``````f(Hit.collider !=null && Hit.collider.GetComponent<Rigidbody2D>() !=null){
Hook_Distance = 0f;
joint.enabled = true;
Line_Go.enabled = true;
Line_Go.SetPosition(0, new Vector3(this.transform.position.x, this.transform.position.y, -1));
Line_Go.SetPosition(1, new Vector3(Hook_Sprite.position.x, Hook_Sprite.position.y, -1));

while( Vector2.Distance(Hit.collider.transform.position, Hook_Sprite.position) > Hook_Distance){
Debug.Log(Hook_Distance);
Hook_Distance =+ 0.1f ;
Hook_Sprite.position = Vector2.Lerp(Hook_Sprite.position, Hit.collider.transform.position, Hook_Distance);
}
``````

You are using Lerp in a weird way I think. Lerp paramater should be in the 0 to 1 range.
You need to calculate your distance, and from that the time given your target movement speed.

pass in (startpos, endpos, lerp value) where lerp value is in the 0-1 range.
Distance = (endpos - startpos).magnitude
totalTime = distance / speed
so make a time loop, where currentTime goes from 0 to totalTime, adding Time.deltaTime added each frame update.
and in your move function pass in lerp value = currentTime/totalTime;
That should do the trick.

make a loop with something like this.

``````    positionA =  Vector3.MoveTowards( positionA, PositionB, mySpeed );
``````