Infinite scroller

I had some time to give it a try on the ways it could be implemented.

At first, I just spawned a new set of tiles around me. This quickly surfaced an issue that tiles are ignorant of whether there was a tile before or not, it just spawns at the same location regardless, making lots of duplicates. I had to figure out how to make tiles be aware of neighbors and not spawn, if the neighbor position is occupied.

I tried to use the trigger volumes at first, by positioning them at the edges of the tile. Idea was that if a tile spawns on its side, it would collide, and I know there is another tile at the place. But it didn’t go well, since the trigger volume acts on rigid bodies, not statics, if I am correct.

Then I decided to change an approach, and add a position probe to each tile under it. When the tile spawns, its probe tests the directions on each side of the tile, to know if it is available for future spawns. When I step onto that tile, it spawns only at free positions.


Here is a public demo of the current attempt. I put the probes above the ground and with visible lines for easier debugging. The lines represent the probe’s ray and the available direction the next tile can spawn.

I still have some issues with it, that I need to tackle:

  1. If you stand at the intersection of 4 tiles. So you basically trigger all 4 tiles at the same time. I think currently 3 will ignore you, but the last one will require a tile from the pool for a spawn. So that one active tile becomes active at some point, running in circles. The engine will start continuously return the tile to the pool and get another for the neighbor spawn, then proceed with the next one, etc, resulting in flickering.
  2. I don’t know yet which tile to return to the pool. First I simply returned the oldest one that was spawned. But that didn’t go well, when I move forward, then return back to the old tile - it just gets removed as the oldest one. The current implementation is based on the distance from the player. I just pick one tile randomly which is over some distance from player and reclaim it. It works better, but can leave “floating islands”. Suggestions are welcome.