Friday, June 22, 2018

floating point - Unity, 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.



Answer



No, you can't do that because Unity is doing all its internal calculation in float.


But if you would like to implement your game mechanics completely with integer arithmetics, you could write your own Vector3Int class, use it for all of your game mechanics, and then have each of your game objects write its Vector3Int-position to transform.position in LateUpdate().


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...