Introducing a new module for convenient and advanced tweening instances in Roblox.
Features:
- Simple tweening
- Predefined functions to tween CFrame/Position
- Custom EasingStyle
- PreProcessing and PostProcessing functions
- Supports Bezier Curves
- Animation of objects in 1 line (rotation in a circle, changing CFrame)
Example #1:
-- Default Color Tween
task.wait(1)
local CustomTweenService = require(script.Parent.CustomTweenService)
local Part = workspace.TestPart
local Info = CustomTweenService.Info(3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local Tween = CustomTweenService:Create(Part, Info, {Color = Color3.fromRGB(255, 0, 0)})
Tween:Play()
CustomTweenService.Info() arguments:
CustomTweenService.Info(Duration, EasingStyle, EasingDirection, PreProcessing, PostProcessing)`
--[[
Duration - the duration of Tween
EasingStyle - EasingStyle of Tween, accepts Enum.EasingStyle, CustomTweenService.EasingStyles
or function that returns time from given time and EasingDirection.
EasingDirection - default roblox EasingDirection: Enum.EasingDirection
PreProcess - function that returns time from given time and EasingDirection,
called after EasingStyle function
PostProcess - function that returns value from given value, time, EasingDirection
More information below
]]
CustomTweenService:Create() arguments:
local Tween = CustomTweenService:Create(instance, InfoOrTime, Properties)
--[[
instance - the Instance whose properties will be changed
InfoOrTime - CustomTweenService.Info() or just duration of Tween
Properties - the table of properties that will be changed on the Instance.
]]
Example #2:
-- Fast Part Tween with Sine EasingStyle
task.wait(1)
local CustomTweenService = require(script.Parent.CustomTweenService)
local Part = game.Workspace.TestPart
local EndCFrame = Part.CFrame + Vector3.new(25, 25, 0)
local Info = CustomTweenService.Info(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
CustomTweenService:TweenPivot(Part, EndCFrame, Info)
CustomTweenService:TweenPivot() arguments:
CustomTweenService:TweenPivot(instance, EndCFrame, InfoOrTime)
--[[
instance - the BasePart/Model/Camera that will be moved
EndCFrame - end CFrame of Instance
InfoOrTime - CustomTweenService.Info() or time (duration of Tween)
]]
Example #3:
-- Create a permanent rotating part (3 degree per frame)
task.wait(1)
local CustomTweenService = require(script.Parent.CustomTweenService)
local Part = workspace.TestPart
CustomTweenService:PermanentAxis(Part, CFrame.Angles(0, math.rad(3), 0))
CustomTweenService.PermanentAxis() arguments:
CustomTweenService:PermanentAxis(instance, axis)
--[[
instance - the BasePart/Model/Camera whose CFrame will be changed.
axis - CFrame which will be multiplied every frame
]]
Example #4:
-- Custom Easing Styles
task.wait(1)
local CustomTweenService = require(script.Parent.CustomTweenService)
local Part = workspace.TestPart
function laggy(t: number, direction: Enum.EasingDirection)
return math.round(t * 50) / 50
end
local Info = CustomTweenService.Info(5, laggy, Enum.EasingDirection.In)
local Tween = CustomTweenService:Create(Part, Info, {Position = Part.Position + Vector3.new(0, 30, 0)})
Tween:Play()
-- You can provide a function instead of Enum.EasingStyle
Example #5:
-- Part moving upwards along a sinusoid using PostProcess function
task.wait(1)
local CustomTweenService = require(script.Parent.CustomTweenService)
local Part = workspace.TestPart
function postProcess(value: CFrame, t: number, direction: Enum.EasingDirection)
return value * CFrame.new( (math.sin(t * 20 * math.pi)), 0, 0 )
end
local Info = CustomTweenService.Info(6, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, nil, postProcess)
CustomTweenService:TweenPivot(Part, Part.CFrame + Vector3.new(0, 40, 0), Info)
Example #6:
-- Part moving along a circle facing to the center
task.wait(1)
local CustomTweenService = require(script.Parent.CustomTweenService)
local Part = workspace.TestPart
local Center = Part.CFrame
CustomTweenService:PermanentCircle(Part, 4, Center, 20, {FaceCenter = true})
Example #7:
-- Bezier Curves
task.wait(1)
local CustomTweenService = require(script.Parent.CustomTweenService)
local Part = workspace.TestPart
local Points = {}
for i = 1, #workspace.BezierCurveParts:GetChildren() do
local IPart: BasePart = workspace.BezierCurveParts:FindFirstChild("N"..i)
table.insert(Points, IPart.CFrame)
end
CustomTweenService:TweenBezierPivot(Part, CustomTweenService.Info(3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), Points)
CustomTweenService:TweenBezierPivot() arguments:
CustomTweenService:TweenBezierPivot(instance, InfoOrTime, Points)
--[[
instance - BasePart/Model/Camera that will be moved along the curve
InfoOrTime - CustomTweenService.Info() or Time(duration of tween)
Points - points of Bezier Curve, where first point is the start,
last point is the end
]]
If you find errors - write.
This module will be updated in the future.