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
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