# Make Lerp or other more fluid or continuous

OK, so I am making an algorithm that goes to one point to another point and I am already done but, when the enemy is walking to the final point it moves to slow, it means that as some knows some algorithm use the grid so is separated in squares(or triangles) so this makes that it doesn't goes fluid or continuous. So my question here is: how can I make a movement more fluid or continuous having the same speed. This is part of what I am doing so you can see it how I do it:

``````enemy.position = Vector3.Lerp(enemy.position,nodes[newdistance],Time.deltaTime * speed);

``````

Your problem is that everyone is using lerp in that strange way. Lerp is meant to lineary go from start to end, but for that behaviour you need a fix start and end point and the last parameter specify how far the interpolation is at the moment. This parameter t have to be between 0 and 1 (0==start 1==end). Everyone uses as start the sctual position and a more or less constant value for t. If t is 0.1 that means that the calculated position is exact 10% toward the target position from the actual position. When the start position comes closer to the end the distance will get smaller. We move always 10% each frame but 100% is the current distance. So with this method you will never reach the target, you come very close and the speed is almost zero but theoretically you can't reach the end (due to float inaccuracy you may reach it)

In short: what you want is a constant movement, so a distance independent movement speed. Unity have this very nice function called MoveTowards. This function is supposed to take the current position and moves it towards the target position.

``````enemy.position = Vector3.MoveTowards(enemy.position,nodes[newdistance],Time.deltaTime * speed);

``````

For a nice Lerp you need something like:

``````transform.localPosition =
Vector3.Lerp(
startPos,
targetPos,
(Time.time - startTime) / duration);
``````

Do not put in the current position each frame or it will not interpolate linear! Save the start position and calculate with that until the end.

And you will have to cancel the Lerp as soon as ((Time.time - startTime) / duration) is >= 1.0

As Bunny said (Time.deltaTime * speed) is the right thing for MoveTowards not for Lerp.