Hello, I’m currently working on a custom terrain generation system which uses triangles to create smooth terrain as shown below (all scripts are client side):
The system uses points to calculate what size and rotation to place the triangles based on their surrounding points. However, I’m experiencing an issue with the terrain loading in all locations as for an unknown reason, it will not load triangles in some regions as shown below (only the red area has triangles created):
Here is the code for generating the triangles in the terrain:
for i, Point in pairs(NewPoints) do -- Loops through the created points
if Point.Color == Color3.fromRGB(255, 255, 255) then -- Checks the points need to load triangles (I tried removing this and nothing changed)
local Pos = Point.Position+GridOff -- Offsets the grid to get an accurate position
local PosName = Vector3.new(Pos.X, 0, Pos.Z) -- Gets the triangle's name from the position and cancels out the Y axis
local PointA = Point
local PointB = Triangles:FindFirstChild(tostring(PosName-Vector3.new(1*Spacing, 0, 0))) -- Gets neighbouring points from the position and offset based off of the spacing of the points (2 studs)
local PointC = Triangles:FindFirstChild(tostring(PosName-Vector3.new(0, 0, -1*Spacing)))
local PointD = Triangles:FindFirstChild(tostring(PosName-Vector3.new(1*Spacing, 0, 0)))
local PointE = Triangles:FindFirstChild(tostring(PosName-Vector3.new(1*Spacing, 0, -1*Spacing)))
local Parts = {} -- Used to check all parts of the triangle loaded
if PointA and PointB and PointC then
local PartA, PartB = Triangle.create(ThePos, PointA.Position, PointB.Position, PointC.Position, {PointA, PointB, PointC})-- Module script to create triangle
if PartA and PartB then
table.insert(Parts, PartA) -- Registers triangle parts
table.insert(Parts, PartB)
end
else
print("Missing Point")
end
if PointD and PointE and PointC then
local PartA, PartB = Triangle.create(ThePos, PointD.Position, PointE.Position, PointC.Position, {PointD, PointE, PointC}) -- Module script to create triangle
if PartA and PartB then
table.insert(Parts, PartA) -- Registers triangle parts
table.insert(Parts, PartB)
end
else
print("Missing Point")
end
if #Parts == 4 and PointA and PointB and PointC and PointD and PointE then -- Checks if both triangles loaded
Point.Color = Color3.fromRGB(255, 0, 0)
else
print(PointA, PointB, PointC, PointD, PointE)
end
end
end
I don’t think the issue is in the script to generate triangles as that script only checks for the players character and the issue occurs when the character has loaded into the game.
If you have any ideas or solutions please let me know
Thanks
Edit:
I realised it only loaded when travelling along the x or z axis when travelling in a posotive direction in the x axis and a negative direction on the z axis and if I walked the oposite direction it would only load in lines: