but what if velocity is negative… btw i understood what you are trying to say but problem now arises that it never reaches perfectly 0. I tried to round it to zero but not succeded
thanks for your attention
Vikrant | 2021-02-24 14:37
you can check if it’s smaller than or equal zero , also there’s a function called is_zero_approx() and is_equal_approx() in gdscript to check if the numbers are nearly equal a value and returns true , you can search it in C# api
Whalesstate | 2021-02-24 14:42
and btw the reason it will never reach zero is because lerp always return
value1 + (value2 - value1) * amount [ 0.2 ] . means it will keep multiply value - difference with 0.2 forever , so you need to stop the lerp whenever it reach a small number like 0.01 and then set velocity.x to zero
Whalesstate | 2021-02-24 15:35
Ok this helped alot, i used this to check if it is approx 0
private bool myApproximation(float a)
{
return (Math.Abs(a) < 0.25f);
}
and if it so then i stopped executing lerp()
If you know any better way to do so pls consider contacting me