You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
i want to check how sharp of a turn the next road is (or make the gaps not visible) -
What is the issue? Include screenshots / videos if possible!
when doing abnormally sharp turns, it may cause visible gaps
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried to fill in the gaps but that seems impossible with script (for me)
the current code:
local RunService = game:GetService("RunService")
function lerp(a, b, t)
return a + (b - a) * t
end
function quadraticBezier(t, p0, p1, p2)
local l1 = lerp(p0, p1, t)
local l2 = lerp(p1, p2, t)
local quad = lerp(l1, l2, t)
return quad
end
local smoothness = .01
local offset = .11
local curvatureLimit = 45
local index = 0
local function generate()
local p0 = Vector3.zero
local p1 = workspace.p1.Position
local p2 = workspace.p2.Position
index = 0
for i = 0, 1-smoothness*2, smoothness do
local pos = quadraticBezier(i, p0, p1, p2)
local nextPos = quadraticBezier(i + smoothness, p0, p1, p2)
local clone = workspace.Roads:FindFirstChild(tostring(index)) or script.Parent.Road:Clone()
local dist = (nextPos-pos).Magnitude
local currentCF = CFrame.new(pos, nextPos) * CFrame.new(0, 0, -dist/2)
for _, v in pairs(clone:GetChildren()) do
if not v:IsA('BasePart') then continue end
v.Size = Vector3.new(v.Size.X, v.Size.Y, dist + offset)
end
clone.Name = tostring(index)
clone:PivotTo(currentCF)
clone.Parent = workspace.Roads
index += 1
end
end
RunService.Heartbeat:Connect(function(dt)
workspace.p1.Position = workspace.p1.Position * Vector3.new(1, 0, 1)
workspace.p2.Position = workspace.p2.Position * Vector3.new(1, 0, 1)
generate()
end)