I have a question. I’m working on a level editor for my game and have run into a problem regarding object placement.
I can place the objects along a grid and rotate them around a axis at a set increment.
When just placing the objects in a straight line everything seems fine. However when one of the items are rotated, small, tiny tiny gaps appear between them. (Think of the objects like pipes fitting together but some having a different rotation.)
The objects should fit together and when I use the vertex snap in the editor this is the case. I have tried rotating using euler angles and I have tried using quaternions.
So, I guess I’m asking, 1) What’s the cause of this? 2) Any ideas on how to fix this.
1: the cause of this is something called a floating point percision. This is caused because the float that Unity uses to position things is made of of 4 bytes and must represent a number from 0.0000000001 to 1000000000. The number is generated via a couple of different mathematical means. a negative/positive bit, a whole number byte, a half number byte and then a logrithmic calculator that multiplies the whole number/half to get a value. This means that when you change points via rotation and try to get them close, you end up with small gaps, or overlaps because of the “floating point imprecision”
2: you can correct this by simply overlapping your meshes. Push the edge verts out just a little to hide the gap.
Now, if you are using this as a race track, I wouldnt worry about it so much. If you are doing a first person shooter, its cleaner if you overlap. Most pros do not try to match edges like this. You would want to put a natural overlap so that the player cant see this.
Thanks for the explanation bigmisterb. Had a hunch it was because of floating point precision, but I didn’t have a good handle on why until your excellent writeup.