I was researching how to implement camera tilt and both through practice and research found mixed information on the topic. I experimented a little with regular implementations of tweening but the problem is that the camera position does not update. The camera position is stuck in the tween as the camera pans.
I want the character’s camera to follow its normal course with a correction on the orientation every frame instead of tweening in place.
I might need to do some sort of slight tween that plays every frame. If that’s the case is there’s a good way to go about it?
Here is my code:
function CameraTilt(Side)
local camera = workspace.CurrentCamera
if Side == "Right" then
print("Right camera tilt")
local x,y,z = camera.CFrame:ToEulerAnglesXYZ()
local goal = {}
goal.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(15))
local tweenInfo = TweenInfo.new(1)
local tween = game:GetService("TweenService"):Create(camera, tweenInfo, goal)
tween:Play()
elseif Side == "Left" then
print("Left camera tilt")
local x,y,z = camera.CFrame:ToEulerAnglesXYZ()
local goal = {}
goal.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(-15))
local tweenInfo = TweenInfo.new(1)
local tween = game:GetService("TweenService"):Create(camera, tweenInfo, goal)
tween:Play()
else
local x,y,z = camera.CFrame:ToEulerAnglesXYZ()
local goal = {}
goal.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,0)
local tweenInfo = TweenInfo.new(0.5)
local tween = game:GetService("TweenService"):Create(camera, tweenInfo, goal)
tween:Play()
camera.CFrame = camera.CFrame * CFrame.Angles(0,0,0)
end
end
In case anyone needs a video I can supply that as well.