Infinite player movement (& map generation) in a single direction?

I’m working on a 3D endless runner similar to Temple run. I’m using object-pooling that places a running path in front of the player as soon as he walks on the next segment.

Unlike my original rough draft… The player moves, but the paths do not, I changed this so I can implement physics and dynamic shadows.

I noticed that my player and path are moving really far into Z, will this become a problem later on? Though about resetting the position of everything in the game, but was worried about seeing a graphical blip/anomaly.

I hope this question isn’t too confusing!

Have you tried leaving the player in the one position & scrolling the background/objects?

If you can’t keep the player at the origin, then you’ll need to reset the positions of everything eventually. I’d say try it: chances are good it won’t cause any noticeable blip.

2 Likes

If it does you can always add in a cut scene.

1 Like

Good question. My original code moved the ground-pieces towards the player (who was planted at (0, 0, 0)), they even rotated to simulate the effect of turning a corner. Looked pretty good at the time, but I noticed later that the shadows of objects attached to the ground piece were rotating… so goodbye dynamic shadows. I also had some problems with physics, since the ground shifted horizontally but bouncing objects/debris did not. There were also some other complications I can’t remember, the code got really hairy and I completely started over. I thought about baked shadows, or using point lights and maybe dropping all physics detail… I decided that I really didn’t want to limit myself.

Looks like I might try Joe’s idea with Mormon’s cutscene idea (if there’s a blip).

I’m still curious to know if there’s an issue with Unity and moving objects too far from the center of the grid. IF not I’ll just leave everything as it is.

There is eventually. You’ll get floating point precision errors with physics about 20 km from the origin. Rendering starts to get some major z fighting issues as you go further. At about 200 km physics breaks down completely.

If you player isn’t ever going to get that far then you might not have an issue. Most ‘Infinite’ runners are not actually infinite, and have practical limits much closer to home.

@Kiwasi yeah that’s a good point.

Another option is to not make it infinite, have separate levels with ends. Spiderman iOS infinite runner ends the level with a boss battle, that would be a challenge to make, but would definitely add some personality.

1 Like

Well, I hesitate to point this out, but… you could have just put the light source in the same group (container object) as the ground pieces, so they rotate with it, and then the shadows would have appeared properly stable.

Yes, I can believe that. There are ways to compensate for the physics issues, but it wouldn’t be easy, and yeah, your code would get complicated fast.

[QUOTE[I’m still curious to know if there’s an issue with Unity and moving objects too far from the center of the grid. IF not I’ll just leave everything as it is.[/QUOTE]

There is, though it’s not really Unity’s fault. Floating-point numbers only have 32 bits to work with; they simply can’t store large numbers with much precision. So if you get far away from the origin, then things will indeed start to go wonky.

1 Like

Thought of that after rewriting the code. I bet that method would still be tricky though, for example; the player’s shadow and any other gameobject that’s also not moving may have quirky shadow behavior.

I also considered a have a night and day transition, which (I’m guessing) would not look as nice with point lights.

… Anyway, now my challenge is to think of a way to reset all current objects to the point of origin. Perhaps some code in my “GameManager” script that moves everything. Any tips would help!