Hopelessly lost on Bezier curves

I’m trying to learn how to code Bezier curves to make better vfx, I understand the concept but I have no idea how to code it, if anyone would like to teach me or could point me to some helpful guides that’d be great. I’ve been staring at the dev wiki for a while now and it’s not clicking.

3 Likes

Yes there is an article on the DevHub specifically for Bezier curves. However I suggest you look elsewhere. Bezier curves are curves with arbitrary points and so fine tuning them is annoying.

Well it depends on which type of bezier curve you want to use, but I’ll be using quadratic beziers as they’re the ones that are used the most.

First of all, you need the formula for the bezier you want to create. You can find them all here.
[Bézier Curves | Roblox Creator Documentation]

For quadratic beziers the formula is

function QuadraticBezier(t,p0,p1,p2)
	return (1-t)^2*p0+2*(1-t)*t*p1+t^2*p2
end

What that does is it returns a point depending on the arguments inserted.(t is kind of like a percentage of where the point drawn by the function is in the curve. p0 is the starting position, p1 is a position that will influence the curve and p2 is the end position)

Code example:

function QuadraticBezier(t,p0,p1,p2)
	return (1-t)^2*p0+2*(1-t)*t*p1+t^2*p2
end

local movingPart = workspace.MovingPart
local p0 = workspace.p0
local  p1 = workspace.p1
local p2 = workspace.p2

for i = 0, 1, 0.01 do
	wait(0.05)
	local pos = QuadraticBezier(i , p0.Position, p1.Position, p2.Position)
	movingPart.Position = pos
end

In the code above, a position is generated every 0.05 seconds and movingPart’s position is set to the position generated by the QuadraticBezier function.

Hope this helped you.

1 Like

Your explanation is exactly what I needed to clear up the confusion, thank you very much for taking the time to help me. :smiley: I was mostly confused on what t meant. The dev wiki was very confusing for me.

No problem and I’m glad it helped you.