Hello Dev-Forum!
I was messing around with the lerp function, and I noticed something odd whenever I lerped the camera. Usually it’s smooth, but when lerping the camera it moving in a, well, linear fashion. I don’t know if there’s a work-around to this or not, but if anyone knows one please let me know! Thank you!
Code:
--lean is set to CFrame.Angles(0,0,math.rad(90))
for i = 0,1,.01 do
game:GetService("RunService").RenderStepped:Wait()
game.Workspace.CurrentCamera.CFrame = game.Workspace.CurrentCamera.CFrame:Lerp(game.Workspace.CurrentCamera.CFrame * lean,i)
end
game:GetService("RunService").RenderStepped:Connect(function()
game.Workspace.CurrentCamera.CFrame = game.Workspace.CurrentCamera.CFrame * lean
end)
Lerp offers a linear method when adjusting CFrame to another in your case. If you haven’t yet, you can try using TweenService and experimenting with the different easing styles and directions for smoother movement.
I tried using TweenService, but the camera was left behind the player. I tried putting my tween into a loop, but nothing happened until the loop finished and the RenderStepped function began running.
I somehow forgot to put :Play() after my tween. That sadly didn’t fix the issue though
Now that I think about it, I should have been more specific. I want to keep the player’s camera locked in first person while rotating it smoothly and having it still keep up with the player.
TweenService:GetValue() takes a given alpha value and returns a new one generated from a chosen easing style/direction, essentially allowing you to apply the convenient TweenService preset styles to a lerp.
Something like this is what I presume you’re looking for?:
local lean = CFrame.Angles(0,0,math.rad(90))
local tweenService = game:GetService("TweenService")
for i = 0,1, .01 do
game:GetService("RunService").RenderStepped:Wait()
local alpha = tweenService:GetValue(i, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
print(alpha)
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame:Lerp(workspace.CurrentCamera.CFrame*lean, alpha)
end
game:GetService("RunService").RenderStepped:Connect(function()
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame*lean
end)