I have a mechanic in a game I am working on where, when the user object moves, the camera tilts in the direction the object is moving. My only problem is, sometimes, when both the left and right key are held down one after the other, and then released one after the other, the camera will not reorient itself fully upright. Is there any way for me to do this?
Here is what I have:
local UserInputService = game:GetService("UserInputService")
local camera = game.Workspace.CurrentCamera
UserInputService.InputBegan:Connect(function(InputObject, Processed)
if InputObject.KeyCode == Enum.KeyCode.A or InputObject.KeyCode == Enum.KeyCode.Left then
leftdown = true
if rightdown == false then camera.CFrame = camera.CFrame * CFrame.Angles(0,0,math.rad(-1)) end
else if InputObject.KeyCode == Enum.KeyCode.D or InputObject.KeyCode == Enum.KeyCode.Right then
rightdown = true
if leftdown == false then camera.CFrame = camera.CFrame * CFrame.Angles(0,0,math.rad(1)) end
end
end
end)
UserInputService.InputEnded:Connect(function(InputObject, Processed)
if InputObject.KeyCode == Enum.KeyCode.A or InputObject.KeyCode == Enum.KeyCode.Left then
if rightdown == false then camera.CFrame = camera.CFrame * CFrame.Angles(0,0,math.rad(1)) end
leftdown = false
else if InputObject.KeyCode == Enum.KeyCode.D or InputObject.KeyCode == Enum.KeyCode.Right then
if leftdown == false then camera.CFrame = camera.CFrame * CFrame.Angles(0,0,math.rad(-1)) end
rightdown = false
end
end
end)