Bezier Curves Module

I’ve had a fascination with bezier curves recently, so I decided I would make a module to support 3 types of bezier curves and release it to RbxDev! Get the module here!

Also, if anybody wants to help me implement higher order curves, let me know. The module may not give 100% accurate tweening. The end result is sometimes off by a few decimals. Edit Added check to fix the decimal offset. End result is 100% accurate now.

This supports Linear, Quadratic, and Cubic bezier curves and even has contains a function to interpolate the curves!

Documentation (Documentation also contained inside of module)

	This is a bezierCurve module that will perform the Bezier Curve algorithm on any data type that
	supports basic arithmetic operations.
	
	This documentation will describe each bezierCurve function then will explain the interpolation function.
	
	--BezierCurve.Linear--
	This is the equivalent of Linear interpolation.
	Percent = Percentage to completion. (0%-100%)
	Ins = The instance you are performing the formula on.
	Property = The property of the instance you are wanting to change.
	P0 = Start Value
	P1 = End Value
	
	--Example of Linear--
	local curve = require(workspace.BezierCurves)
	curve.Linear(50,workspace.Part,"Position",workspace.Part.Position,Vector3.new(0,100,0))
	
	--BezierCurve.Quadratic--
	This uses a control point to affect the interpolation between the start and end point.
	This is the equivalent of Linear interpolation.
	Percent = Percentage to completion. (0%-100%)
	Ins = The instance you are performing the formula on.
	Property = The property of the instance you are wanting to change.
	P0 = Start Value
	P1 = Control Value
	P2 = End Value
	
	--Example of Quadratic--
	local curve = require(workspace.BezierCurves)
	curve.Quadratic(50,workspace.Part,"Position",workspace.Part.Position,Vector3.new(0,100,0),Vector3.new(10,10,10))
	
	--BezierCurve.Cubic--
	This uses two control points to affect the interpolation between start and end point.
	Percent = Percentage to completion. (0%-100%)
	Ins = The instance you are performing the formula on.
	Property = The property of the instance you are wanting to change.
	P0 = Start Value
	P1 = Control Value
	P2 = Control Value
	P3 = End Value
	
	--Example of Cubic--
	local curve = require(workspace.BezierCurves)
	curve.Cubic(50,workspace.Part,"Position",workspace.Part.Position,Vector3.new(0,100,0),Vector3.new(50,0,25),Vector3.new(10,10,10))
	
	*Note*
	Using the BezierCurve formulas in this module will result in an instant change.
	Use BezierCurve.Interpolate for a smooth tween to the percentage.
	
	--BezierCurve.Interpolate--
	This will smoothly interpolate/tween from a start percentage to the desired percentage of the formula.
	Method = Desired type of curve to perform. (Linear, Quadratic, or Cubic)
	StartPercent = Percent of the tween to start at. (0%-100%)
	EndPercent = Percent of the tween to end at. (0%-100%)
	Duration = Time it takes to complete the tween in seconds.
	Callback = function that will be called when the tween is over.
	... = Once you supply the arguments for the interpolate function, supply the arguments for the
	tween function. Ex Cubic (Percent,Ins,Property,P0,P1,P2,P3)
	
	--Example of Interpolate--
	local curve = require(workspace.BezierCurves)
	function TweenFinished()
		print("Finished")
	end
	curve.Interpolate("Cubic",0,100,5,TweenFinished,workspace.Part,"Position",workspace.Part.Position,Vector3.new(0,100,0),Vector3.new(50,0,25),Vector3.new(10,10,10))

MP4 of cubic interpolation here

Using Vector3.new(0,0,0) as start, Vector3.new(0,100,0) as Control Point 1 Vector3.new(50,0,25) as control Point 2 and Vector3.new(10,10,10) as end point.

6 Likes

Seems really interesting! Mind posting the source of pastebin real quick so I can take a look? I’m on mobile most of the time :frowning:

There you go.

There you go.[/quote]
This is pretty cool, nice job

There you go.[/quote]
This is pretty cool, nice job[/quote]

Thanks ^-^