I’m trying to create an infinite flying game. So far I have created an aeroplane and the ground. Both these are moving forward along with a acceleration component. The aeroplane can also move right, left. Now the issue is, since the ground is also moving forward, I read that that might lead to something called floating point error and way to avoid this is to reset the gameobject to origin after something. Can someone tell me the code to do so. The ground and the plane have an update function that transforms the z position: transform.Translate(0,0,10 * Time.DeltaTime);
Seeing the game is “infinite” you have to generate the world on the fly.
So why not keep the plane at z=0, and have it move left/right/up/down in the xy plane.
Then spawn new terrain at z=100 or so, and give it a velocity in the -z direction.
Once a chunk of terrain has scrolled out of view, behind the player, remove it from the scene.
You just need to reverse your thinking a little… if the plane “slows down” you make the terrain (plus enemies) scroll slower. If the plane “speeds up” the terrain scrolls underneath faster.
The real velocity of the plane object is always zero in the z-component, though, and only ever moves in y or x.
Note that in this scheme, you can also keep your camera steady. It doesn’t have to move towards +z, as the world moves towards the camera instead.
if there are less objects in scene , which are moving along with ur player(camera) (i mean dependent on something), collect them in a list and just reset the player and other gameobjects with a difference of player pos and their positions. let me know i will explain it more correctly if you still not get it