Help with Camera Manipulation Performance

Problem

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

I will admit now, I am a noob coder :laughing:

Hierarchy

image|181x60,
image
image


Play the game for yourself:

Any help is appreciated. Thanks for reading!

2 Likes

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.

1 Like

Hey, exchange of making a part, and a moving a camera, why don’t you just Tween camera, so, what I mean is

local tweenService = game:GetService("TweenService")

local camera = workspace.CurrentCamera

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(1,1,1)
tweenService:Create(camera, TweenInfo.new(3), {CFrame = CFrame.new(12,12,12)}):Play()
1 Like

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)
2 Likes

Thanks for these solutions, but I want to keep the Quad effect. Changing the easing style to Linear did not seem to help.

I also tried @Syharaa’s method, it still seemed to jitter.

I was sort of going for a camera like this:

The jittering could possibly be solved with my method by lowering the alpha unit on the lerp method, maybe to 0.2

1 Like