I want to understand how to make a bezier curve, but I can’t seem to understand one thing. In this image, point A is the starting spot, point B is the ending spot and point C is the spot that the moving object passes through. How would I calculate point D, which according to a few tutorials in youtube and the dev hub you need to create bezier curves?

Sorry if I wasn’t clear, this should be much easier to understand.

If it’s that you want the curve to pass through point C, then all you need to do is pick any value of t (the alpha) and equate the curve’s equation to the point to pass through:

B(t) = C
-- below is the equation for a quadratic bezier curve:
(1-t)^2*A + 2(1-t)*t*D + t^2*B = C

It can pass through point C at any value of t, so you can work with 0.5 as t. Then it’s just solving for P1 / D:

B(0.5) = C
C = 0.25 * A + 0.5 * D + 0.25 * B
D = (C - 0.25 * A - 0.25 * B) / 0.5

We’ve solved for D, now it’s just plugging it into roblox:

local Point_D = (Point_C - 0.25 * A - 0.25 * B) / 0.5
-- Point_D can be used as the 2nd control point for the quadratic bezier curve
2 Likes

Thanks, this worked nicely along with a piece of code I found here in the dev forum. In case anybody needs the code I used, I’m pasting it here.

wait(5)
local bezierStart = workspace.bezierStart.Position
local bezierEnding = workspace.bezierEnd.Position
local bezierPassing = (workspace.bezierMiddle.Position - 0.25 * bezierStart - 0.25 * bezierEnding) / 0.5

return (1 - currentTime) ^ 2 * pointA + 2 * (1 - currentTime) * currentTime * pointD + currentTime ^ 2 * pointB
end

for currentTime = 1, 100 do
local newPos = quadraticBezier(currentTime / 100, bezierStart, bezierPassing, bezierEnding)
local redNeon = Instance.new("Part", workspace)
redNeon.Anchored = true
redNeon.Color = Color3.new(1, 0, 0)
redNeon.Material = Enum.Material.Neon
redNeon.Size = Vector3.new(1, 1, 1)
redNeon.Shape = Enum.PartType.Ball
redNeon.Position = newPos
wait(0.1)
end
1 Like