Lerping 3 point bezier curves

I’m aiming to make a soft curved zigzagging projectile, so far it zigzags but its sharp points like this:

image

I’m using a part with a trail effect and lerping it, I saw this article about bezier curves but I’m confused on how to actually lerp it. If anyone knows any alternative methods to get a smooth curve please reply.

The code in the documentation provides the solution for you:

local part = Instance.new('Part', game.Workspace)

function lerp(a, b, c)
	return a + (b - a) * c
end

function quadBezier(t, p0, p1, p2)
	local l1 = lerp(p0, p1, t)
	local l2 = lerp(p1, p2, t)
	local quad = lerp(l1, l2, t)
	return quad
end

local a, b, c = Vector3.new(0, 10, 0), Vector3.new(10, 10, 0), Vector3.new(-10, 10, 10)
for i = 0, 1, 0.03 do
	wait()
	part.Position = quadBezier(i, a, b, c)
end

For every bezier you have, repeat the interpolation

5 Likes