Filling in gaps between segments of a curved road

  1. What was achieved?
    I was able to make a curved road by creating Bézier Curves (cubic) and placing segments on the points through code.

  2. What is the issue? Include screenshots / videos if possible!
    Whenever a curve is created, there are noticeable gaps between the segments. I want to fill in these gaps so the road looks smoother.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried changing the pivot point of the segment, but the curve still has gaps between them whenever the curve direction alternates.

Here’s the current pivot point of the segment model:

Here’s part of the code that places the segments:

	local segments = 35
	local curve = workspace.Folder
	local model = workspace.RoadSegment
	local a = p1.Position -- start
	local b = c1.Position -- control point 1
	local c = c2.Position -- control point 2
	local d = p2.Position -- end

	local lastPos
	for t = 0,1,1/segments do
		local bezierPos = cubicBezier(a,b,c,d,t)

		if lastPos then
			local posDist = (bezierPos - lastPos).Magnitude

			local clone = model:Clone()
			for _,v in pairs(clone:GetChildren()) do
				if v:IsA("BasePart") then
					-- Primary part has to be scaled from the Z axis
					if v == clone.PrimaryPart then
						v.Size = Vector3.new(v.Size.X,v.Size.Y,posDist)
					else
						v.Size = Vector3.new(posDist,v.Size.Y,v.Size.Z)
					end
				end
			end
			clone:PivotTo(CFrame.lookAt(bezierPos,lastPos))
			clone.Parent = curve
		end
		lastPos = bezierPos
	end

btw I want to fill in these gaps with code, not by plugin (GapFill).

1 Like

I suggest you keep a pivot at one end, then track whether the road is curving left or, for each part. You’ll create a part starting from the other end of the part, going to the parallel end of the very next part, then extending all the way to the other end. In other words, you gott place parts wide the same as the road, but that extend from one corner to another of the parts, where the gap is present. Since you know the pivot, you can also get the other corner. Just gotta calculate the orientation, but after all it’s perpendicular to the line connecting the 2 corners, whereas the size simply is the difference in coordinates of the 2 corners. Would be better, I think, if you used wedges, with probably less polygons to render. I don’t know, you see and try.