GUI.Create.MouseButton1Click:Connect(function()
if #game.Selection:Get() >= 3 then
local selection = game.Selection:Get()
local NewBezier = Bezier.new(selection[1], selection[2], selection[3],selection[4],selection[5],selection[6])
local newmodel = Instance.new("Model",game.Workspace)
local Lines = {}
local NumPoints = tonumber(GUI.Amount.Text)
for i = 1, NumPoints - 1 do
local TargetPart = game.ServerStorage.Road:Clone()
TargetPart.Parent = newmodel
TargetPart.Anchored = true
table.insert(Lines, TargetPart)
end
game:GetService("RunService").Heartbeat:Connect(function()
for i = 1, #Lines do
local t = (i - 1) / (#Lines - 1)
local position = NewBezier:CalculatePositionAt(t)
local derivative = NewBezier:CalculateDerivativeAt(t)
local line = Lines[i]
--local p1, p2 = Lines[i].Position
--line.Size = Vector3.new(line.Size.X, line.Size.Y, (p2 - p1).Magnitude)
Lines[i].CFrame = CFrame.new(position, position + derivative)
end
end)
--[[for i = 1, #Lines do
local line = Lines[i]
local p1, p2 = Lines[i].Position, Lines[i + 1].Position
--line.Size = Vector3.new(line.Size.X, line.Size.Y, (p2 - p1).Magnitude)
line.CFrame = CFrame.new(0.5 * (p1 + p2), p2)
viewmodel:Destroy()
end]]
end
end)
This script is for a plugin that takes the six parts you have selected and creates a bezier curve out of it. It then projects a Road Model across this bezier curve. The problem is as shown in the picture, the road gets offset a bit. Me and my friend have been trying for a long time to fix this, referring to Stravant’s resizealign plugin, but we want to implement it into the plugin and are unsure how to attack this problem.
Here is the bezier curve module we are using in the NewBezier
module: Bhristt's Bezier Curve Module (Tween support)
Any ideas how to implement code to align them?