- Home /
Positioning with ints instead of floats
I round my transform.position to the nearest integer at the end of every frame so it's never a decimal number. I would like to know if there's a way to make unity store the position in ints instead of floats to prevent floating points precision problems.
You could perform the rounding using LateUpdate() to make it happen at the end of each frame. It is not possible to change how unity stores positons.
Answer by meat5000 · Mar 28, 2017 at 06:30 PM
I do not believe this is possible. You can store the values as int but Unity will always use decimals for the actual positional representations, so at the point the int information is handed back to Unity, floating point error is reintroduced. The error will be very small. If you are relying on int information you need to write a simple function to truncate or round your floats when you attempt to use them as ints. This totally negates the need to store as int; however storing as int may serve to reduce error, marginally.
Answer by AurimasBlazulionis · Oct 08, 2016 at 08:00 AM
No, it is not possible. Also, if you round to ints you will still have pretty good precision, because you simply do not store with decimal points.
To avoid floating point errors completely, you will have to move all objects by am offset to make a character go back closer to the zero coordinates.