Bezier curves module

Hello devs!
I made a simple in use bezier curves module without any restrictions in amount of points.
Here is it: BezierCurve - Roblox
So its very eazy to use in 2d and 3d.
Here example of using it in 3d: 3d_2PointsBezier.rbxl (30.4 КБ)
For now it has 2 functions:
Calculate(Start position of your curve, End position of your curve, “Step”-it means how much line you need to have(as you have more lines you have smoother bezier but your pc need to calculate more(50 lines is good amount)), Poses-its the points of bezier.)
basicly calculate all curve,
CalculatePointStart position of your curve, End position of your curve, Poses-its the points of bezier, Time(value from 0-1 basicly its follows your curve))
basicly its just calculate point in your curve by time value

As you can see in simulation this thing calculates smooth bezier by this small code:

local s = workspace.START
local e = workspace.END
local p1 = workspace.POINT1
local p2 = workspace.POINT2
local bc = require(script.BezierCurve)
game:GetService("RunService").RenderStepped:Connect(function()
	workspace.curveParts:ClearAllChildren()
	local lp = nil
	workspace.point.Position = bc:CalculatePoint(s.Position,e.Position,{p1.Position,p2.Position},0.25)
	for ind,pos in pairs(bc:Calculate(s.Position,e.Position,20,{p1.Position,p2.Position})) do
		local cp = Instance.new("Part")
		cp.Parent = workspace.curveParts
		cp.Anchored = true
		cp.CanCollide = false
		if lp then
			cp.Size = Vector3.new(0.2,0.2,(lp-pos).Magnitude)
			cp.CFrame = CFrame.new((lp+pos)/2,pos)
		else
			cp.Size = Vector3.new(0.2,0.2,(s.Position-pos).Magnitude)
			cp.CFrame = CFrame.new((s.Position+pos)/2,pos)
		end
		lp = pos
	end
end)

Also i have a 2d bezier thing: Bézier curves showcase - Roblox
Thanks for reading, also sorry for my english its quite bad i think

9 Likes

This is a really cool feature, nice work ! :smiley:

I am not sure if you have included this, but let me give you an idea for an extra feature you could add. Directions. You return a Position (the interpolation between the 2 points) but you can also return a direction using the first derivative of the Bezier formula (Derivatives of a Bézier Curve) so that if someone wants to animate an arrow for example, they can set its CFrame orientation.

I think i need to make so you can get the position by the only time value so you can add like 0.02 to time and then get the vector so developer can get vector between points how he want to

Just wanted to point out that there is a useful resource on the Developer Hub for this as well, and they have their own module you can try too.

Bézier Curves (roblox.com)

1 Like

I know but i working on cool feature for this module which i dont found anywhere and n this tutorial too.
Its make bezier curve builds not jst regards some points but it will go trough them!

Great stuff,Good job.Time to make a 100000 degree curve

Oh! Okay, I see what you are trying to do now. That’s pretty clever.

ServerScriptService.BezierCurve:26: invalid argument #1 to ‘pairs’ (table expected, got number)

can you show the code that you writed

Its solved,now,By putting self at front of everything

One quick note of feedback, I would always reccomend using RunService.Heartbeat over RunService.RenderStepped unless it’s necessary for said function to run before physics calculations, like character movement or camera modules.

1 Like

I never used .Hearbeat because dont needed it really but i have that image so i know what you mean
s1200

RenderStepped is a unique event. All RenderStepped events must be completed in order for the engine to continue. This is a big reason why functions tied to it should never yield, and why only necessary functions run on it.

Heartbeat works almost identical to this, but it runs in parallel and all hartbeat functions don’t need to end in order for the next frame to render. The dev hub would give you this same exact warning, as it can really lag out a player if misused.