- Home /
Problem with precision of moving object many times.,Moving object many times with precision
Hi. I wrote script that moves object a = 110 times by b = 0.1f from x = -5.5f and i expected that this object will be in position x = 5.5 but insteed it is in position x = 5.499995. Why is that ? How to deal with it ? I dont want to extort specific values because a and b will be change during the game. Sorry for bad english and thanks !
Answer by Jwizard93 · Jun 28, 2017 at 08:58 PM
I don't know how to do what you are asking. But I'm imagining it would not be worth it. If you need to test whether the object is in position or not just test that it's within a very small range. I mean you are talking about very very small discrepancies. I always see unity moving my objects very close to where I wanted and not the actual spot. I let it go..
Answer by DamianHell · Jun 29, 2017 at 10:57 AM
Ok I found a solution. Using a Kahan summation algorithm i can reduce error very strong. If I would move object milion times, error would be greater and impossible to miss. This alghoritm unfortunately is not perfect and goes 4 times longer but in my case I move object with relatively long time intervals so i can calmly use it :)
It was silly of me to assume your example was also your use case. I'm wondering if maybe this bit of information might help you achieve even more accuracy:
http://davenewson.com/posts/2013/unity-coordinates-and-scales.html
It explains the finite limits of one scene and a little bit about how to define a certain location within a large space. Which I do believe can be used leverage high precision in any sized scene.
Your answer
Follow this Question
Related Questions
How Precise is Random.Range? 1 Answer
Vector3 constructor precision 1 Answer
Question on scale of imported 3D models 1 Answer
float precision, wrong computations 1 Answer
Convert double to float for Vector3 1 Answer