I got stuck on my project, I have 2 positions and when distance is zero it should go into the “if” condition and set “isCharging” false, but it keeps going without entering the if, you can see it on the pdf, values are same of both positions. I uploaded step by step but it keeps passing inside of “if”, please help.
Without going into detail about why your comparison fails, the right way to compare two floating-point values on equality in Unity is to use Mathf.Approximately (Scripting API).
Here is my whole script; When enemy is close enough to the player, it charges toward to with extra speed. If “isCharging” false then it simply follow when it is close enough then enemy charges. But “isCharging” stuck on true because of that if condition. So using Vector3.Distance is wrong on my situation?
Don’t actually use Mathf.Approximately, as it’s threshold for “close enough to be the same” is too small to be useful. It’s generally a lot smaller than floating point errors. Your example in the latest post is functionally the same as == 0.