Hello, I had a “nice” meeting with float precision limitation, and I found an easy solution. If player position on x, y or z axis is bigger than 10,000 units then subtract 10,000 units from player pos and position of every chunk of world. It works good. I use thread independent from main to generate vertices’ heights array and than in coroutine I attach generated array to mesh. I use threading not to freeze the game, because ganerating can take about one second, but time is not my problem. The problem occurs when the distance between player and some chunk is enough to generate it, but a little time later player position on some axis is bigger 10,000 so i had to change chunk pos to new, displaced position, but generating thread have an old chunk position and as a result generated mesh is displaced and don’t match the actual chunk position. I hope you understood what I wanted to say. I also hope that you have some ideas to solve this.
Thanks in advance.
One of the possible solutions is to “revert” the Universe - don’t move player, move the world around.
So your player is always at (0,0,0) and when he/she moves in some direction, the world moves in opposite direction instead.
Generation of each chunk happens on the edges of the world (say, 5000 units away) so much earlier than the player reaches any of the border, and a chunk(s) which goes out of 5000 limit just been destroyed. Imagine your player in the middle of 10000x100000 terrain, and chunks of the terrain appear/disappear at the outer edges of the terrain when the player move in some direction so the terrain around the player is always of the same size.
The approach described above allows to create really “infinite” worlds to explore.
And for your case with displacement I would suggest to save the value of the displacement when the generation thread started generation and when generation is done check that current value of the displacement matches the saved value. If “yes”, then continue, if “no” then re-generate the same chunk with the new displacement value.