local currentTween
local ts = game:GetService("TweenService")
workspace.CurrentCamera:GetPropertyChangedSignal("Orientation"):Connect(function()
local camOrientation = workspace.CurrentCamera.Orientation
if currentTween then currentTween:Stop() end
currentTween = ts:Create(workspace.RotCenter, TweenInfo.new(3, 3), {CFrame = CFrame.new(workspace.RotCenter.Position)*camOrientation})
currentTween:Play()
end)
I remember theres like a equation that calculates or something, and it slows down as it reaches the target, creating a fast to slow effect (not a actual tween), do you guys know how to do that?
You might be thinking of Lerp, but it’s similar performance-wise to Tweens. Also Tweens itself doesn’t hurt performance, if it is deleted after usage then it’s completely fine. Other than Lerp and Tweens, there probably is no other way to make it smooth. (move the TweenInfo out of the function by the way)
Lerp is much more complicated than Tween and is implemented through a loop. You can do this by using alpha (yeah…)
local timeToTake = 1 -- the amount of time to take
local alpha = 0 -- what the alpha starts at
local startCFrame = workspace.RotCenter.CFrame
local goalCFrame = CFrame.new(game.Workspace.RotCenter.Position)*camOrientation
while alpha < 1 do
workspace.RotCenter.CFrame = startCFrame:Lerp(goalCFrame, alpha)
-- increment alpha based on how long wait() takes so that it'll be 1
alpha = alpha + (wait() / timeToTake)
end
local co
workspace.CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(function()
if co then coroutine.yield(co) coroutine.close(co) co = nil end
co = coroutine.create(function()
local increment = 0.1
local camOrientation = workspace.CurrentCamera.CFrame-workspace.CurrentCamera.CFrame.Position
for i = 0, 1, increment do
increment += 0.1
increment = math.clamp(increment, 0, 1)
workspace.RotCenter.CFrame:Lerp(CFrame.new(workspace.RotCenter.Position)*camOrientation, i)
task.wait()
end
end)
coroutine.resume(co)
end)