Infinite World in UE4

01/16/2021

When I was a kid, I went to the local gym with my mom and saw something neat. It was a “Virtual Reality Bike” with several games built into it. I loved to play that thing so much that I would beg my mom to take me to the gym so I could play it. There was a game on there called “Sweeny Town”. Not so much a game, but more of a little virtual town that you could bike around in.

One really neat thing I liked was that you could seemingly bike forever. The world wrapped around itself in 3d space. This means that if you biked to the left end of the map you would seamlessly wrap around on the right side of the map, giving the illusion that the world repeats forever.

I wanted to try and recreate this effect in a modern game engine and the test was a success! I personally did it in Unreal Engine, but the same could be replicated easily in your engine of choice. There are a few things to note using this method

  1. This could be expensive depending on the complexity of your map
  2. It would work better with a bigger environment. My test uses a very small map so I used fog to mask the effect

I originally considered a system that would spawn a new copy of the level when you got close to the edge and despawn the one you are leaving from when you get far enough away. The only problem I could see with this technique is running into some sort of limit eventually. It won’t be truly infinite. Eventually at some point (and it would be a very large point) the x and y position of the main character could error out for being too large.

SpawnEnv

I settled making a flat plane that was 1700 x 1700 in size. When I was exporting the model I made sure to snap the upper left vertice to 0, 0, 0. If we import this into our engine and zero out its transforms, we know the top corner will be x0 and y0. The bottom right corner will be x1700 and y1700.

Plane

I created a blueprint of the plane and I added some trees and a building. Next step is to create 8 duplicates of the landmass so that we have a copy on every edge and corner.

Landmass

Once you get to this point, you’re pretty much done. What I did in my main character controller was check the position on every tick. If the x position of the player character is less than or equal to 0, set the character’s X position to 1699. If the x position is greater than or equal to 1700, set the character’s x position to 1. I increment/decrement by 1 because if you put the full values in there the character will get stuck between 0 and 1700 and cannot move. The same applies for the y coordinates. This now gives a seamless illusion that the level is looping forever!


This footage is sped up, but you can see the player continuously running and it never seems to end. I added some pretty deep fog to hide the edge of the map.

Here’s the same scene with a static camera. You can see that the player is just being moved to the opposite side of the grid when they reach a specific point.

And that’s pretty much it! Again, please note that this method is fairly expensive since you have to create duplicates of the map to make the illusion work. You could get around this by creating passages between the maps and only include geometry that you see when crossing the edges. The bigger the map (and bigger the outer edges) the better the effect will look. With specific geometry, you could get away with not having to use fog to hide the effect.

> Back to blog