What i want to do is have trees and eventualy other objects spawn all over the game.
But currently, the trees spawn, But not the right position (They seem to be in a diagonal line of sorts?)
Ive tried addind an offset but that only made it worse. Here is the code:
function makeChunk(chunkX, chunkZ)
local rootPosition = Vector3.new(chunkX * CHUNK_SCALE, 0, chunkZ * CHUNK_SCALE)
chunks[chunkX][chunkZ] = true -- Acknowledge the chunk's existance.
for x = 0, CHUNK_SCALE - 1 do
for z = 0, CHUNK_SCALE - 1 do
local cx = (chunkX * CHUNK_SCALE) + x
local cz = (chunkZ * CHUNK_SCALE) + z
--Main Terrain & Variables for cy--
local Mountains = math.noise(GENERATION_SEED, cx / 200, cz / 200) * 3
local Hills = math.noise(GENERATION_SEED, cx / X_SCALE, cz / Z_SCALE)
local Pebbles = math.noise(GENERATION_SEED, cx / 5, cz / 5)
local Dirt = math.noise(GENERATION_SEED * 2, cx / 45, cz / 45)
local cy = Mountains + Hills * BASE_HEIGHT - Pebbles
if math.clamp(Dirt, 0.4, 0.5) <= 0.5 and math.clamp(Dirt, 0.4, 0.5) >= 0.41 then
local randomizer = math.random(1,3)
if randomizer == 1 then
mountLayer(cx, cy, cz, Enum.Material.Limestone)
elseif randomizer == 2 then
mountLayer(cx, cy, cz, Enum.Material.Grass)
elseif randomizer == 3 then
mountLayer(cx, cy, cz, Enum.Material.LeafyGrass)
end
else
mountLayer(cx, cy, cz, Enum.Material.Grass)
end
--Objects--
local TreeMap = math.noise(GENERATION_SEED * 0.5, cx / 100, cz /100)
if math.clamp(TreeMap, 0.4, 0.5) <= 0.5 and math.clamp(Dirt, 0.4, 0.5) >= 0.41 then
local density = math.random(1, DENSITY)
if density == DENSITY then
local treeoff = math.random(1, OFFSET)
local Tree = game.ReplicatedStorage.Objects.Trees.Tree1:Clone()
local cf = CFrame.new(cx + treeoff, cy, cz + treeoff)
Tree:SetPrimaryPartCFrame(cf)
Tree.Parent = workspace.Objects
end
else
--Nothing
end
end
end
end