So I have somewhat of a understanding of Bezier curves. I created the path of the Bezier but now I’m trying to tween a parts position to follow the path but I have no idea on how to do this.
The neon parts is the path that was created using the Bezier function. The monkey is basically the part that I am trying to tween.
Here is my code:
function lerp(a, b, t)
return a + (b - a) * t
end
function cubicBezier(t, p0, p1, p2, p3)
local l1 = lerp(p0, p1, t)
local l2 = lerp(p1, p2, t)
local l3 = lerp(p2, p3, t)
local a = lerp(l1, l2, t)
local b = lerp(l2, l3, t)
local cubic = lerp(a, b, t)
return cubic
end
function cubicBezierTangent(t, p0, p1, p2, p3)
return
3 * (1 - t)^2 * (p1 - p0)
+ 6 * (1 - t) * t * (p2 - p1)
+ 3 * t^2 * (p3 - p2)
end
local p0, p1, p2, p3 = workspace.Eren.HumanoidRootPart.Position,Vector3.new(0, 20, 0),Vector3.new(20, 10, 0),workspace.Mo.HumanoidRootPart.Position
local TweenService = game:GetService("TweenService")
for t = 0, 1, 1/50 do
local p = Instance.new("Part")
p.Anchored = true
p.Size = Vector3.new(3, 3, 3) * 0.1
p.CFrame = CFrame.new( cubicBezier(t, p0, p1, p2, p3) )
p.Color = Color3.fromRGB(255, 0, 0)
p.Parent = game.Workspace
p.Material = Enum.Material.Neon
local NextPos = cubicBezier(t, p0, p1, p2, p3)
TweenService:Create(workspace.Monkey, TweenInfo.new(0.1, Enum.EasingStyle.Linear), {Position = NextPos}):Play()
local tangent = p:Clone()
tangent.Size = Vector3.new(0, 0, .5)
tangent.CFrame = CFrame.new( p.Position, p.Position + cubicBezierTangent(t, p0, p1, p2, p3) )
tangent.CFrame += tangent.CFrame.LookVector * tangent.Size.Z * 0.5
tangent.Color = Color3.fromRGB(0, 55, 255)
p.Material = Enum.Material.Neon
tangent.Parent = game.Workspace
end