local LastRoad = workspace.Part
function placeRoad(dir)
local Part = Instance.new("Part")
if dir == "forward" then
Part.Size = Vector3.new(4, 0.2, 2)
Part.Position = LastRoad.Position + Vector3.new(Part.Size.X, 0, 0)
end
if dir == "left" then
Part.Size = Vector3.new(2, 0.2, 4)
Part.Position = LastRoad.Position + Vector3.new(Part.Size.X + 1, 0, -1)
end
if dir == "right" then
Part.Size = Vector3.new(2, 0.2, 4)
Part.Position = LastRoad.Position + Vector3.new(Part.Size.X + 1, 0, 1)
end
Part.Anchored = true
Part.CanCollide = true
Part.Parent = workspace
LastRoad = Part
end
while wait(0.5) do
local c = math.random(1, 3)
if c == 1 then
placeRoad("forward")
end
if c == 2 then
placeRoad("left")
end
if c == 3 then
placeRoad("right")
end
end
--placeRoad("right")
I didn’t start the generation part at all, I just made completely random placing script, since I was testing
you could make a generator where each part will see the possible outcomes of the path while keeping sure of collision and correct road types to prevent the path intercepting each other, or the roads becoming detached like in your photo.
1 - Get the magnitude from the current point to the next point local Distance = (NextPoint.Position-CurrentPoint.Position).magnitude
2 - Get the halfway position between those 2, you can use local Pos = CurrentPoint.Position:Lerp(NextPoint.Position, 0.5)
3 - Create the road part
local Part = Instance.new("Part")
Part.Size = Vector3.new(1,1,Distance)
Part.CFrame = CFrame.new(Pos, NextPoint.Position) -- In the middle of the 2 points and looking at the nextPoint.
Part.Parent = workspace.Roads -- Better storing your parts in a folder
So simply you’re going to do this in a loop. getting the CurrentPoint and NextPoint until there is no NextPoint
Maybe try to resize the part slightly bigger than the distance?
if you want a smoother and better result. you’ll need to use some triangles and math and of course more parts to generate some kind of mesh.
But i can’t really help you with such thing since i never expermented with it enough. I bet there is better people to help you with generating such thing. Good luck!