Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Code Wont Make The Block Snap To Grid While Generating Terrain?

Asked by 3 years ago
local X = 50
local Z = 50
local Y = 1

local grid = {}

for x = 1, X do
    grid[x] = {}
    for y = 1, Y do
        grid[x][y] = {}
        for z = 1, Z do
            grid[x][y][z] = math.noise(x/10, z/10) * 15
        end
    end
end

for x = 1, X do
    for z = 1, Z do
        for y = 1,Y do
            local yPos = grid[x][y][z]
            local part = Instance.new("Part")
            part.Anchored = true
            part.Material = Enum.Material.Grass
            part.BrickColor = BrickColor.new("Earth green")
            part.Position = Vector3.new(x*3, yPos, z*3) -- Makes The Block Not Snap To Grid The yPos Is The Problem I Think
            part.Size = Vector3.new(3, 3, 3)
            part.Parent = workspace.TerrainFolder
        end
    end
end

1 answer

Log in to vote
0
Answered by 3 years ago

Answered

local X = 30
local Z = 30
local Y = 5

local function STG(X)
    return math.floor(X / 3 + 0.5) * 3
end

local grid = {}

for x = 1, X do
    grid[x] = {}
    for y = 1, Y do
        grid[x][y] = {}
        for z = 1, Z do
            grid[x][y][z] = math.noise(x/10 ,y/10,z/10) * 15
        end
    end
end

for x = 1, X do
    for z = 1, Z do
        for y = 1,Y do
            local yPos = grid[x][y][z]
            local part = Instance.new("Part")
            part.Anchored = true
            part.Material = Enum.Material.Grass
            part.BrickColor = BrickColor.new("Earth green")
            part.Position = Vector3.new(x*3, STG(yPos), z*3) 
            part.Size = Vector3.new(3, 3, 3)
            part.Parent = workspace.Twerrain
        end
    end
end
Ad

Answer this question