Bezier curves use three points to calculate a curve
Point 1 - The origin
Point 2 - The Curve Influence
Point 3 - The End Location
There’s more to it but that’s the base concept of it (I usually put the API page at the top of my scripts, use that to see more.)
They can be a pain so I made a function I can use.
Heres what I did at one point to make curves:
--https://developer.roblox.com/en-us/articles/Bezier-curves
-- T is a decimal below 1, 1 means curve is completed
--So smaller intervals means more points and smoother creation
--P1 Is midpoint
--P0 and P2 are the start and finish
--Uses Pythag and current position + %Complete
--V1
function lerp(a,b,c)
return a + (b - a) * c
end
--Lerps All the points
function CurvePoint(p0,p1,p2,t)
t = t
--LERP X
Xl1 = lerp(p0.X, p1.X, t)
Xl2 = lerp(p1.X, p2.X, t)
XLerp = lerp(Xl1, Xl2, t)
--LERP Y
Yl1 = lerp(p0.Y, p1.Y, t)
Yl2 = lerp(p1.Y, p2.Y, t)
YLerp = lerp(Yl1, Yl2, t)
--LERP Z
Zl1 = lerp(p0.Z, p1.Z, t)
Zl2 = lerp(p1.Z, p2.Z, t)
ZLerp = lerp(Zl1, Zl2, t)
Pos = Vector3.new(XLerp,YLerp,ZLerp)
return Pos
end
-- Simplify Curve
-- T should usually be 0
function CreateCurve(p0,p1,p2,t,Inc)
Points = {}
t = t
LoopCount = 0
while t < 0.99 do
CurvePoint(p0,p1,p2,t)
Points[LoopCount] = CurvePoint(p0,p1,p2,t)
--Keeps Track Of Progress
LoopCount = LoopCount + 1
t = LoopCount * Inc
end
return Points
end