Answers for "Patrol unit lose speed when get close to target"
http://answers.unity.com/questions/1737695/patrol-unit-lose-speed-when-get-close-to-target.html
The latest answers for the question "Patrol unit lose speed when get close to target"Answer by KoenigX3
http://answers.unity.com/answers/1737804/view.html
*Lerp* functions take 3 parameters: a start point, an end point, and an interpolant. If the interpolant is 0, the function returns the start point. If the interpolant is 1, the function returns the end point. If the interpolant is between 0 and 1, the function returns a point between the start and end point.<br><br>
Normally, to make the interpolation linear, you would need a static starting point and a dynamic interpolant. In your case, you are using the *Lerp* function in a different way.<br><br>
1. Your starting point is not static, which means that it changes every frame.
2. Your interpolant is not dynamic, which means that it is constant.<br><br>
By doing so, you are achieving a decreasing interpolation. The function returns a point between the start and end point about 0.5% from the start. Since you are using the current position (*this.transform.position*) as the starting point, the distance between the start and end point decreases, and since you are always returning 0.5% of the distance, it decelerates.<br><br>
The solution is to use a fixed starting point and an increasing interpolant.<br><br>
Vector3 startingPoint;
float interpolant = 0;
void Update()
{
Vector3 temp2 = Vector3.Lerp(startingPoint, path[current_point].position, interpolant);
interpolant += Time.deltaTime;
}
<br>Whenever you change the end point, you also have to change the start point to the current position (but only once, of course), and the interpolant to 0.Wed, 03 Jun 2020 08:56:37 GMTKoenigX3