This is actually from @okeanskiy 's video on perlin noise & terrain generation. I’ve went ahead and wrote out the code fully to the point where it works, I understand everything except for this part.
water.Position = Vector3.new((maximumX + 1) * 5 / 2, -5, (maximumZ + 1) * 5 / 2) + Vector3.new(0, 50, 0)
Why are we adding 1 to maximumX and maximumZ? I get that otherwise the waterpart is somewhat off, but where does this 1 come from?
Full code:
local maximumX = 100
local maximumZ = 100
local gridLayout = {}
for x = 1, maximumX do
gridLayout[x] = {}
for z = 1, maximumZ do
gridLayout[x][z] = math.noise(x/10, z/10) * 15
end
end
for x = 1, maximumX do
for z = 1, maximumZ do
local part = Instance.new("Part", workspace)
part.Size = Vector3.new(5,30,5)
part.Position = Vector3.new(x*5, gridLayout[x][z], z*5) + Vector3.new(0, 50, 0)
part.Anchored = true
end
end
local water = Instance.new("Part", workspace)
water.Anchored = true
water.Size = Vector3.new(maximumX * 5, 30, maximumZ * 5)
water.Position = Vector3.new((maximumX + 1) * 5 / 2, -5, (maximumZ + 1) * 5 / 2) + Vector3.new(0, 50, 0)
water.Transparency = 0.6