My attempt at making terrain generation

Since I just recently looked into terrain generation, I thought I’d share what I’ve made with it.

Perlin Noise has given me a fair bit of trouble when trying to implement it. Not sure what exactly I was doing wrong, but it was still kinda weird. I ended up discovering a more simple method of generating natural terrain at this site, however the method I originally thought up looks just as smooth in my opinion.

I started off width a 2D array of 1’s (or some other starting number). Then I used a function that raises the values surrounding inputs (x, y) inside of the 2D array; the closer it is to (x, y), the more the terrain is raised, and vice versa. Call this function multiple times at random (x, y) locations, and I have the height map to generate the terrain. I later found a smoothing function that I used for more smooth looking hills.

I used this to generate a Minecraft terrain (which is free to take), and it worked pretty well. Obviously takes a long time to generate, since it’s creating a couple ten thousand parts, but since only the top layers are being added into workspace it goes a lot faster than one would expect.

A large overview of the Minecraft Terrain generated. Not exactly meant for looking from a distance, but still cool.

External Media

A close up image of the terrain.

External Media

Below the grass is a layer of dirt. Makes for a cool effect c:

External Media

As I said, the map is hollow, but since the information is still stored in a script, you are capable of digging into the map. Just delete the part you click, and make the surrounding parts (if not deleted) visible.

External Media

Then I put a layer of bedrock on the bottom surface.

External Media

I also dabbled in using triangles to generate terrain. I figured I would use the method mentioned above for this, and it looked pretty neat.

I also made a basic version of what I did in the Minecraft generation (without any smoothing) after somebody asked me how to make terrain. It doesn’t look as neat, but it can be a useful reference (especially since I made some comments on the code as well).

Tell me what you think :­O

2 Likes

Very cool! I’ve been experimenting with terrain generation as well, but I can’t seem to make a good pseudo random number generator, and math.randomseed() has a very… small effect.

What if you tried this: math.randomseed(os.time())

What if you tried this: math.randomseed(os.time())[/quote]
I can’t tell if superfighter used math.randomseed() literally, without tick() or os.time() in its brackets. Just thought I’d pitch in 'cause you never know

What if you tried this: math.randomseed(os.time())[/quote]

The thing is, I’m not going for a massive number like that. I need it to be constant, so I have to use a more predictable number that can be accessed and any time. I can do this, but it always acts a bit odd. I’ve tried using just sin and cosine with pseudo random algorithms as well.

If you go here and join the map “Nova” then you can see one of my random terrain generators:

What I do is create a “flat” heightmap in a 2D array and then repeatedly “hill” and “crater” it. It ends up with some really nice looking hills and snaky island-type-things.

What if you tried this: math.randomseed(os.time())[/quote]
[/spoiler]
The thing is, I’m not going for a massive number like that. I need it to be constant, so I have to use a more predictable number that can be accessed and any time. I can do this, but it always acts a bit odd. I’ve tried using just sin and cosine with pseudo random algorithms as well.[/quote]

Kind of confused on what you’re going for here. I’m assuming you want a way to generate the same random numbers given one or more variables? In that case, you could always create a table that stores the random numbers created. That way, if you call a number with the same variables, it’ll check to see if the table exists, and if so, return that number (this is what I did). Otherwise, I found that math.randomseed() works just fine. It’s terrain generation after all, not cryptography :o

[spoiler][code]
math.randomseed(tick()) --Or tick()%7919 if you want a random seed between 1 and 7919 for some reason
local SEED = math.random(1,1000000)
local MAX_X = 100 --In the case of two variables, you’d want to define the highest the first variable can go.

function Random_1Var(x)
math.randomseed(SEED+x)
return math.random()
end

function Random_2Var(x,y)
math.randomseed(SEED+x+y*MAX_X)
return math.random()
end
[/code][/spoiler]

Davidii,
So basically the same thing I did in the Minecraft generation. And to think I thought I was being rather original with that method, haha.

I’ll just leave this here. I love this terrain so much, especially the ocean-type ones; dynamic lighting makes it darker as you go down! :smiley:

Note: StreamingEnabled makes it look weird.

I don’t know why it’s been 7 years since this topic has been discussed. This has been very helpful, thank you!

2 Likes