I am making a new island, and completely rewrote the code with the help of a few people, but I need help making a falloff island.
Island code:
local X, Z = 300, 300
local tile_size = 2
local seed = Random.new():NextNumber(1, 100000) -- seed
_G.GlobalSeed = seed -- defines global seed for tree generator
local wedge = Instance.new("WedgePart");
wedge.Name = "Part"
wedge.Anchored = true;
wedge.TopSurface = Enum.SurfaceType.Smooth;
wedge.BottomSurface = Enum.SurfaceType.Smooth;
wedge.BrickColor = BrickColor.new("Forest green")
wedge.Material = Enum.Material.Grass
-- Make some variables or a table for your colors
local TerrainColors = {
Grass = BrickColor.new("Forest green").Color,
Sand = BrickColor.new("Cool yellow").Color
}
-- getColorGradient(colors : table, gradientPos : float)
function getColorGradient(colors, gradientPos)
-- Calculates the R, G, B values based on position in the gradient
local R = colors[1].R + (colors[2].R - colors[1].R) * gradientPos
local G = colors[1].G + (colors[2].G - colors[1].G) * gradientPos
local B = colors[1].B + (colors[2].B - colors[1].B) * gradientPos
return Color3.fromRGB(R * 255, G * 255, B * 255) -- Reformats the values and converts them into a Color3
end
-- getGradientPosition(wedgeHeight: int, height : int, spread : int)
function getGradientPosition(wedgeHeight, height, spread)
spread = spread or 1
local startHeight = (height + spread)
local endHeight = (height - spread)
return math.clamp((wedgeHeight - endHeight)/ (startHeight - endHeight), 0, 1)
end
local function draw3dTriangle(a, b, c)
local ab, ac, bc = b - a, c - a, c - b;
local abd, acd, bcd = ab:Dot(ab), ac:Dot(ac), bc:Dot(bc);
if (abd > acd and abd > bcd) then
c, a = a, c;
elseif (acd > bcd and acd > abd) then
a, b = b, a;
end
ab, ac, bc = b - a, c - a, c - b;
local right = ac:Cross(ab).unit;
local up = bc:Cross(right).unit;
local back = bc.unit;
local height = math.abs(ab:Dot(up));
local w1 = wedge:Clone();
w1.Size = Vector3.new(0, height, math.abs(ab:Dot(back)));
w1.CFrame = CFrame.fromMatrix((a + b)/2, right, up, back);
w1.Parent = game.Workspace.Island.Terrain;
local w2 = wedge:Clone();
w2.Size = Vector3.new(0, height, math.abs(ac:Dot(back)));
w2.CFrame = CFrame.fromMatrix((a + c)/2, -right, up, -back);
w2.Parent = game.Workspace.Island.Terrain;
local w2height, w1height = w2.Position.Y, w1.Position.Y
local sandHeight = -4
if w2height <= sandHeight and w1height <= sandHeight then
-- Sets the color to the returned color gradient (based on the Gradient Position) for each wedge
w1.Color = getColorGradient({TerrainColors.Sand, TerrainColors.Grass}, getGradientPosition(w1height, sandHeight, 1))
w2.Color = getColorGradient({TerrainColors.Sand, TerrainColors.Grass}, getGradientPosition(w2height, sandHeight, 1))
w1.Material = Enum.Material.Concrete
w2.Material = Enum.Material.Concrete
end
return w1, w2;
end
local positionGrid = {}
for x = 0, X do
positionGrid[x] = {}
for z = 0, Z do
positionGrid[x][z] = Vector3.new(x*tile_size, math.noise(seed, x/100, z/100) * 35, z*tile_size)
end
end
for x = 0, X-1 do
for z = 0, Z-1 do
local a = positionGrid[x][z]
local b = positionGrid[x+1][z]
local c = positionGrid[x][z+1]
local d = positionGrid[x+1][z+1]
draw3dTriangle(a, b, c)
draw3dTriangle(b, c, d)
end
end