Iāve recently watched a couple videos on Bezier curves and read some articles. I canāt really āexplainā since Iām very awful at math, like I legitimately hate it, but anyways, hereās what I can tell you
This is the formula for a Quadratic Bezier curve:
B(t) = (1-t) Bp0,p1(t) + t Bp1,p2(t)
--A Quadratic Bezier has 3 control points
--t being the interval, a float between 0 and 1
--p0 being Point0 (mostly the start point)
--p1 being the 'curve' point (this is the point which the curvature is based off)
--p2 being point2 (the end point)
--[[
Since vector3 values can be multiplied, added, subtracted etc.
you can just toss baseparts positions into the formula
Imagine we have 3 parts in workspace, "PartA", "PartB" and "PartC"
Let's setup the quadric bezier function
]]
local function QuadraticBezier(t,p0,p1,p2)
return (1-t)^2*p0+2*(1-t)*t*p1+t^2*p2; --<Very simple :D
end;
local Part0 = workspace.Part0;--<Start point
local Part1 = workspace.Part1;--<'Curve' Point
local Part2 = workspace.Part2;--<End Point
local inter_PART = Instance.new("Part", workspace);--<Part To Move
--Now to call the bezier function, we can just wrap it in a for loop
for t = 0,1,0.01 do
local TargetPosition = QuadraticBezier(t , Part0.Position, Part1.Position, Part2.Position);
inter_PART.Position = TargetPosition;
end;
Thereās also other Bezier types
local function CubicBezier(t, p0, p1, p2, p3)
return (1-t)^3*p0+3*(1-t)^2*t*p1+3*(1-t)^2*p2+t^3*p3
end;
--> EDIT ^^ should be (1-t) * t^2 * p2. Fix available below.
--> Left old incorrect formula just incase someone was previously using this as a reference.
-- FIX:
local function CubicBezier(t, p0, p1, p2, p3)
return (1 - t) ^ 3 * p0 + 3 * (1 - t) ^ 2 * t * p1 + 3 * (1 - t) * t ^ 2 * p2 + t ^ 3 * p3
end;
Hope this helped, sorry for any errors