Snapping to 3 stud grid in height with math.noise

I am currently attempting to create a random terrain generating script, with the terrain made of 3x3x3 parts. Currently I have it kind’ve working with a script I found and changed a tiny bit.

``````for x = 1,10 do
for z = 1,10 do
local p = Instance.new("Part",workspace)
p.Anchored = true
p.Size = Vector3.new(3,3,3)
local height = (math.noise(x / 20, 3, z / 20) + 2) * 50
p.Position = Vector3.new(3*x,height/2,3*z)
end
end
``````

This is what it will do:

However I want the height of the parts to be on a 3 stud grid, if that makes any sense. Like this:

Also, how would I implement a random “seed” to this, to determine how the terrain is generated?

You would want to make one of the arguments in math.noise() random.

To make it snap to a three stud grid, you can use modulo to find the how much you need to subtract to make it snap to the three stud grid, and then subtract it.

``````local seed = math.random()
for x = 1,10 do
for z = 1,10 do
local p = Instance.new"Part"
p.Anchored = true
p.Size = Vector3.new(3,3,3)
local height = (math.noise(x/20,z/20,seed)+2)*25
p.Position = Vector3.new(3*x,height-height%3,3*z)
p.Parent = workspace
end
end
``````
1 Like

Just another question, how could I generate terrain as the player walks around?