BézierTweening | Simple tweening along bezier curves

Introduction

BezierTweening is a library made to easily make a part follow along a bezier curve. BezierTweening was made with simplicity in mind and is designed to mimic TweenService’s functions.

Roblox library

How to use

The most basic way to create a bezier tween would be this.

local BezierTween = require(ServerScriptService.BezierTween)
local Waypoints = BezierTween.Waypoints
local P0, P1, P2, P3 = workspace.P0, workspace.P1, workspace.P2, workspace.P3

waypoints = Waypoints.new(P0, P1, P2, P3)
local Part = game.Workspace.Part

local Tween = BezierTween.Create(Part, {
    Waypoints = waypoints,
    EasingStyle = Enum.EasingStyle.Sine,
    EasingDirection = Enum.EasingDirection.In,
    Time = 5,
})
Tween:Play()

Extra Features

Functions
  • Tween:Play() – Plays the tween
  • Tween:Pause() – Pauses the tween
  • Tween:Resume() – Resumes the tween
  • Tween:Cancel() – Cancels the tween
Events
  • Tween.Played – Fires when the tween has played for the first time or is resumed
  • Tween.Completed – Fires when the tween is completely finished
  • Tween.Paused – Fires when the tween is paused
  • Tween.Resumed – Fires when the tween is resumed
  • Tween.Ended – Fires when the tween has completed or been cancelled
  • Tween.Cancelled – Fires when the tween is cancelled

Important notes

Easing styles Elastic and Back aren’t supported with bezier tweens.

82 Likes

Bezier curves can have 2 anchor points and infinite amount of control points. Also, quadratic and cubic bezier curves get their name not from the amount points but the amount of linear interpolations that take place. Amazing use of linear interpolation, great work!

5 Likes

Thanks for bringing this to my attention, I’ve updated the library and it now supports any amount of points above 1.

6 Likes

This is an extremely useful module. Thank you so much for making it. I did notice some spelling mistakes on your example code, but other than that I love it. Thanks again! :grinning:

Man, this is Just VERY cool, Easy to use, and dont needs to know hard math

1 Like

Any chance this could be used or updated to tween movement of the attach1 CFrame being tweened to move foward on the Z axis? Similar to a charge up bow and arrow system where the arc updates/tweens over time accurately with the attach1 of the beam being tweened forward at the same time?

1 Like

you should probably use body movers for this

1 Like

Hey, sorry to bump

There’s a big issue I run into where higher framerate causes tweens to complete far sooner than specified in the function.

How do I make the part look at the next position it’s gonna be? I don’t know where to change it’s orientation to make it look at it’s next position. Help would be appreciated

I feel silly for asking this, but can you provide an example of a Tween.Completed event? Great script by the way.

Just do:

local BezierTween = require(ServerScriptService.BezierTween)
local Waypoints = BezierTween.Waypoints
local P0, P1, P2, P3 = workspace.P0, workspace.P1, workspace.P2, workspace.P3
local Part = workspace.Part

local Tween = BezierTween.Create(Part, {
    Waypoints = Waypoints.new(P0, P1, P2, P3),
    EasingStyle = Enum.EasingStyle.Sine,
    EasingDirection = Enum.EasingDirection.In,
    Time = 5,
})

Tween.Completed:Connect(function()
     print('Completed!')
end)
2 Likes

…and the answer was silly simple, thank you.

How would I use this to tween the camera? I’m trying to create a spectate system using this library
I have this code right now but it errors:


local Bez = require(script.Parent.BezierTweens)
local Waypoints = Bez.Waypoints

script.Parent.MainFrame.TextButton.MouseButton1Down:Connect(function()
	local CameraPart = Instance.new('Part', workspace)
	CameraPart.CFrame = workspace.CurrentCamera.CFrame
	
	local OtherPlayer
	for i, v in pairs(game.Players:GetPlayers()) do
		if v ~= game.Players.LocalPlayer then
			OtherPlayer = v
		end
	end
	
	local waypoints = Waypoints.new(CameraPart, OtherPlayer.Character.Head)
	
	local tween = Bez.Create(workspace.CurrentCamera, {
		Waypoints = waypoints,
		EasingStyle = Enum.EasingStyle.Quad,
		EasingDirection = Enum.EasingDirection.Out,
		Time = 1,
	})
	
	tween:Play()
end)

Error:
Position is not a valid member of Camera "Workspace.Camera"

Does anyone know how to properly tween the camera with this library? Any help would be appreaciated

Camera doesn’t use Position, it only operates with CFrame.
I could be wrong but I think the best way to do this is attaching the camera to a part or attachment, then maneuver the part

No support for GUI tweening?

4 Likes

Please add support for things like orientation and custom properties like fov so I can animate the camera, it would be helpful

2 Likes

Why are the Client-Side and Server-Side positions not equal…?

Is it possible to use positions or CFrames instead of parts for p0, p1, p2 and p3?

Says it needs to be a BasePart. I am sure you could modify the Module to accept Udim2