To make a straightforward generation you first need to think of what you need. Let's strip down the problem to the base problem: we need to generate a blocky-like landscape. You can later implement biomes and types of blocks.
Reviewing your current code: there are some problems in it.
First of all you are looping over "blocks", a table which only has one member. That means that it will run it's code only once. I wouldn't do that, I would loop over an x and z range (the positions). To chose a block you can always use math.random to get a random block from the list.
Second: you are assigning Size to a Name. Size is a Vector3 and Name is a string. This will always conflict. I take that script.Parent.Grass
is a brick: why not clone it?
The simplest terrain generator will just loop over all x and z positions and will assign a random height to it. You will see that the terrain will be extremely "peaky". If you run the code you will see what I mean. It is better to study random "noise" generators - I would suggest Perlin Noise.
01 | local block = script.Parent.Grass |
02 | local function GetBlock() |
05 | local function GetSize() |
09 | local x_min, x_max = - 100 , 100 |
10 | local z_min, z_max = - 100 , 100 |
11 | local y_min, y_max = 1 , 10 |
12 | for x = x_min, x_max, GetSize() do |
13 | for z = z_min, z_max, GetSize() do |
14 | local height = math.random(y_min, y_max) |
15 | for y = GetSize()/ 2 , GetSize() * (height + 0.5 ), GetSize() do |
16 | local block = GetBlock() |
17 | block.CFrame = CFrame.new(x,y,z) |
18 | block.Parent = game.Workspace |
Locked by JesseSong
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?