A small bezier curve library that supports around 12 points per bezier container with efficient tween.
Sources : github
A few days ago I met few bezier curve modules, and I wasn’t pleasant with their structure and perfomance. Yes, they’re more than alright to use, and this library is more likely to not be used by traditional OOP fans and this was made purely to simplify the bezier curves code as much without losing it’s usability, but it offers a perfomance boost by ~2 times on my PC. And it can use technique of method caching that is popularly used in the Lua.
Bezier-curve-library
An efficient bezier curve library that supports around 12 points.
Assumingly, the user of the library is not an idiot and built in errors are enough, so I deleted type checks for a slight perfomance increase.
module.NewbezierContainer
A function that takes any amount of vector arguments (which’ll create points from them)
Returns a table that stores all of the points in it.
module.GetPosAtTime
A function that takes a bezier container and a t as a number.
Returns a vector object that represents position at given t.
module.RunTween
A function that takes a bezier container, time as a number and a target that is a BasePart.
After that, it creates a connection (if it’s not present) to LOOP function that’ll make the tween.
If there’s nothing to tween, the connection will terminate itself.
returns nothing, so be aware that you won’t be able to stop this tween.
Examples
It can be used in any movement TD system game, or anywhere else where bezier curves are needed (it’s up to you to decide if they’re needed). Although I won’t recommend using the tween function I made since it’s linear and uncontrollable for outside scripts.
Notes
This can achieve a multithreading by changing code (but it doesn’t have strong side imo).
To create new point in bezier container, you shall use table.insert(container,point), where container is a bezier container and point is a vector object.