Creating a curved road

I have made a system where i create a table of positions, and then generate parts from the positions to create a road curve

this is my code for creating the parts:

local prevPos = nil
		
		for _,pos in path do
			
			if prevPos then
			local part = Instance.new("Part")
				part.Size = Vector3.new(4,.1,(pos - prevPos).Magnitude)
				part.Anchored = true
				part.CanCollide = false
				part.Color = Color3.new(0.352941, 0.352941, 0.352941)
				part.CFrame = CFrame.new((pos + prevPos) / 2) * CFrame.lookAt(pos,prevPos).Rotation
				part.Parent = workspace
			end
			prevPos = pos
			
		end

this is how the generated road looks like:


The green parts are positions from the Table

how can i make it so the parts are perfectly connected and not with holes like in the image? Thanks

You don’t have to write a code for this, you can use a plugin “Archimedes”.

1 Like

i am making a citybuilder game so the player needs to create these roads ingame

You can try to adjust the size of each part to cover the entire distance between the current position (pos ) and the previous position (prevPos ). Also, you can use the lookVector of the CFrame to properly orient the parts. Here’s an updated version of your code:

local prevPos = nil

for _, pos in ipairs(path) do
if prevPos then
local part = Instance.new(“Part”)
part.Size = Vector3.new(4, 0.1, (pos - prevPos).Magnitude)
part.Anchored = true
part.CanCollide = false
part.Color = Color3.new(0.352941, 0.352941, 0.352941)

    -- Calculate the orientation using the lookVector
    local lookVector = (pos - prevPos).Unit
    local rotation = CFrame.new(Vector3.new(), lookVector)

    -- Set the CFrame of the part
    part.CFrame = CFrame.new(prevPos, pos) * rotation

    part.Parent = workspace
end
prevPos = pos

end

the generated road looks still the same as in the image above

I changed a couple of things in my previous reply. If this doesn’t work then I don’t know how to help.