I just want to know if this is even possible. I used the following code to change the player’s position to the position of a tile in my 3D grid based project:
The problem is that player is slightly off. For example instead of being 16, 0, 24, the player is 15.999889, 0.156, 23.999889. The most confusing is the y position as I have no idea why that is greater than zero. I’m trying to get the player’s position to be exactly the same as the grid tile’s position.
You can make 2 variables point to the same piece of information but I doubt very highly that that bit of information will ever be so accurate. This is the only way to make them equal. This wont make them accurate.
In JS for example, I read that an int is just a parsed float anyway.
I’ve used Matlab and such programs extensively and it will produce accurate reproductions just about every time. Unfortunately Unity’s floating point is not nearly so accurate as it simply does not need to be.
Where an integer might tell you its a round number, place that into a transform and its a float. With error.
Use RountToInt and store it in a float. With Error.
The further you get from the origin, the larger the error gets also.
I think a Unity float is accurate to .000001 (I could be wrong I worked it out last week). Which isnt great to be honest.
The point is, I guess, making Unity swear to you that two numbers are the same is nice to make you feel good but by the time it uses the value there will be error introduced.
This will always happen in floats.
Make note of Daves point that an error of 0.156 from an int is NOT FLOATING POINT ERROR and something else is at work.