Vector3.Lerp is not smoothing out movement

Hello, I am having trouble with Vector3.Lerp(), I have the player’s current position, as well as an accurate vector3 I want the player to move to. I understand that the third float parameter is a percentage, and when equal to 1, the player will be at the given position. For some reason even though I add a small amount to the percentage each time it runs in the loop, in the game it looks instantaneous. Any help is appreciated, thanks!

Vector3 _currentPos = gameObject.transform.position;
Vector3 _dashPoint = new Vector3 (wallPos.x - 0.23f, wallPos.y, 0);
float _dashTimer = 0;
while (_dashTimer < 1) {
    _dashTimer += 0.01f;
	transform.position = Vector3.Lerp (_currentPos, _dashPoint, _dashTimer);

the problem is here :
“I add a small amount to the percentage each time”

by each time u are not seeing that the Update method run so many frames per second ;

so _dashTimer will be 1 in no time that u can see;

and the next framt it gets to 0 again ;

so u got into a loop ;

so first of all u should multiplay it by time like this :

 _dashTimer += 0.01f * Time.deltaTime;

this way it will move a little slower but more stable;
u can increaste that 0.01f too ;

i cant see your full script so i dont know if it gets to 0 again or not ;

and for movement u better use MoveTowards instead :

     transform.position = Vector3.MoveTowards(_currentPos, _dashPoint, _dashTimer);

here is the problem

transform.position = Vector3.Lerp (_currentPos, _dashPoint, _dashTimer);

here for each and every frame the object going to it’s initial position. But it has to start from where it left

i mean try to use below code

transform.position = Vector3.Lerp (transform.position, _dashPoint, _dashTimer);

I think the problem you’re seeing is simply the result of combining the Update() function with a while() loop.

I’ll demonstrate using a simple script example:

// C#
void Update()
	int myValue = 0;
	Debug.Log("Starting Value: " + myValue); // 0
	while(myValue < 100)
		myValue += 1;
	Debug.Log("Ending Value: " + myValue); // 100

By using the while() loop with the condition of lerpValue < 1, you can only continue with the current frame once the condition is met. As a result, your interpolated value will always be the maximum (more or less) of 1 by the time you will see any of it.

Now, here’s an example using a coroutine to stagger the process:

IEnumerator increment;
int myValue;

IEnumerator Start()
	increment = IncrementValue();
	Debug.Log("Starting value: " + myValue); // 0
	myValue = 0;
	yield return StartCoroutine(increment);
	Debug.Log("Ending value: " + myValue); // 100

IEnumerator IncrementValue()
	while(myValue < 100)
		myValue += 1;
		Debug.Log("Current value: " + myValue); // 0-100
		yield return null;

In this example, the value will be reached 100 frames later, because the game will move on to the next frame after every change is made to the value. yield return null;

In your case, _dashtimer probably needs to be incremented on a frame-by-frame basis in order to utilize the functionality of the Lerp(). Right now, you’re effectively only displaying the result of an interpolation value of 1, which means you’re only showing the final destination.