Random Terrain Generation and 4D Cylinders

Codename: Grand Theft Spaceship

Julian Hernandez(gmfk07) and I are working on a new project that involves the exploration of randomly generated top-down worlds.

The first step to random terrain generation is to create a grid across your room. Each grid space spews out a random number from 0 to 100 representing th elevation level.

So the top left grid space would 100, or a mountain, while the top right grid space would be 0, or a deep lake. However true randomness is too archaic to pass off as natural so instead we would interporlate the different elevations to smooth it. Perlin Noise is the algorithm I used. It averages the elevation of its surroundings and produces random noise.

Two Dimensional Perlin Noise

Since I am making a 2D top-down shooter, I had to learn how to add a dimension to a one dimensional perlin noise script. This is where I have to give most of my credit to the YouTuber Arend Peter Teaches. In his video, he used Game Maker and taught me the ways to make 2D terrain generation so I highly reccomend giving his video a watch if you want to learn the details of a two dimensional perlin noise script.

Watch the video here

After the video, this is what I had:

2D Perlin Noise Map
2D Perlin Noise Map

A Planet is a Sphere?

Looks beautiful right? Well we wanted the terrain to loop around perfectly so the player can walk to the ends of the planet without falling into the depths of an ocean. To make a 2D randomly generated plane acknowledge the ends of the other side of the plane, one must grab the ends and close them onto each other. From the code of the video, I created a 3D space of perlin noise and then curved the x and z-values to make a cylinder– essentially bending the 2D plane into a cylinder to make a horizontally loopable generated map:

2D Perlin Noise Map Curved into 3D Cylinder
2D Perlin Noise Map Curved into 3D Cylinder

So What’s a 4D Cylinder?

I’m not sure… It’s hard for me imagine a shape I cannot percieve. But I do know that if I need a 3D cylinder to bend a 2D map horizontally, I need a 4D cylinder to bend a 2D plane both horizontally and vertically. I created a 4D perlin space by pulling on 16 4D vectors in perlin space. So there would be a x,y,z,w coordinates that I would interpolate between each other and the noise would be what the elevation of the terrain would be. Here is the final result:

2D Perlin Noise Map Wrapped in 4D Space
2D Perlin Noise Map Wrapped in 4D Space
If you are interested in looking at the code or improving it (please do), you can download it here

Leave a Reply

Your email address will not be published. Required fields are marked *