I am trying to make a dungeon themed camera, and I kind of achieved what I was going for. The problem is that the camera subtly jitters/lags and I don’t know whats wrong. You can also help me organize my code or tell me how I should do things instead. I looked on the devforum for answers but I couldn’t find any topics describing the same problem. If you happen to find one, send me link. Keep in mind I also want feedback on how I organize my code/hierarchy.
Screenshots will not help because this is a motion problem. You can test the game for yourself.
Code
local tweenService = game:GetService("TweenService")
local part = game.ReplicatedStorage.CameraObject.CameraPart
local players = game.Players
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild('HumanoidRootPart')
local camera = workspace.Camera
local folder = workspace.CameraFolder
camera.CameraType = Enum.CameraType.Scriptable
local cameraPart = part:Clone()
cameraPart.Parent = folder
camera.CameraSubject = cameraPart
local tweenInfo = TweenInfo.new(
0.1,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut,
0,
false,
0
)
cameraPart.Position = rootPart.Position + Vector3.new(20,25,20)
camera.CFrame = cameraPart.CFrame + Vector3.new(-1,1,-1)
wait(1)
while wait() do
cameraPart.Position = rootPart.Position + Vector3.new(20,25,20)
tween = tweenService:Create(camera, tweenInfo, {CFrame = cameraPart.CFrame + Vector3.new(-1,1,-1)})
tween:Play()
end
Use RunService.Heartbeat instead of a wait() loop. That should make it feel a lot smoother!
Also, it seems that you are using Quad easingstyle, which means that whenever you call tween:Play(), it will “reset” the momentum of the camera and hence cause a small jitter as well. You should try a different tween (like linear, which always has constant velocity), or write your own camera tween script that can maintain velocity.
Heya! I would like to agree with @sayhisam1, the momentum of the camera will reset while using the Quad easing style, but in addition I decided to go ahead and add some adjustments to your code with my preference, notable lerp I believe in lerping the camera or using a harmonic motion equation rather than tweening it.
hopefully this helps solve your issue!
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild('HumanoidRootPart')
local camera = workspace.Camera
local folder = workspace.CameraFolder
camera.CameraType = Enum.CameraType.Scriptable
local cameraPart = part:Clone()
cameraPart.Parent = folder
camera.CameraSubject = cameraPart
cameraPart.Position = rootPart.Position + Vector3.new(20,25,20)
camera.CFrame = cameraPart.CFrame + Vector3.new(-1,1,-1)
game["Run Service"].Heartbeat:Connect(function()
cameraPart.Position = rootPart.Position + Vector3.new(20,25,20)
camera.CFrame = camera.CFrame:Lerp(cameraPart.CFrame + Vector3.new(-1,1,-1), 0.5)
end)