Hello guys, I am using lerp to move my objects around, and the problem i am facing is, how do I tell if my node have reached the end point and be precise about it, because my update method is called at regular intervals, I was wondering how i can tell it to stop lerping because the node has reached the target point.
spatial.getposition().equals(target.getPosition()) doesnt really work
But what are you LERPing with? Generally you are interpolating between some starting position and some ending position… so you will know if you are there when the interpolation value is 1.0.
If instead you are doing something like “going halfway each time”… then your movement will be a bit strange, starting fast and ending really slow (mathematically you will never get there… but in practical terms you do).
So maybe you can say more about what you are doing.
Actually single-precision IEEE floating point (what Java uses for float) can represent integers precisely up to about 16 million. And (2f + 3f == 5f) always evaluates to true (try it!)
However, most fractions (even simple ones like 1.2) cannot be represented precisely as floats. So for instance (1.2f * 3f == 3.6f) always evaluates to false.
So Daniel’s point is a good one. Almost all floating-point comparisons for equality should include a tolerance.
would there ever be a reason to want to utilize this in some way? or is it just some thing that happens to work out easily with the math so they included it in the spec.
@icamefromspace said:
i did not know that, i learned something new :D.
would there ever be a reason to want to utilize this in some way? or is it just some thing that happens to work out easily with the math so they included it in the spec.
Afaik it’s not explicit in the specification, just a side-effect of how numbers are represented in IEEE floating point.