I've achieved making this go smoothly in the X axis, with no problems, but when you add the Y axis, it doesn't go as smooth as the X axis. Any help on making it look smoother like the X axis?
local cameraHeight = 12 local cameraZOffset = 20 local cameraXChase = 10 local cameraYChase = 20 local cameraSpeed = .25 local camera = game.Workspace.CurrentCamera local player = game.Players.LocalPlayer local RunService = game:GetService('RunService') local function setupCamera() camera.CoordinateFrame = CFrame.new(Vector3.new(0,cameraHeight,cameraZOffset), Vector3.new(0,cameraHeight,0)) end setupCamera() player.CharacterAdded:connect(setupCamera) local function onUpdate() if player.Character and player.Character:FindFirstChild('Torso') then local playerX = player.Character.Torso.Position.X local playerY = player.Character.Torso.Position.Y local cameraX = camera.CoordinateFrame.p.X local cameraY = camera.CoordinateFrame.p.Y if cameraY - cameraYChase < playerY then camera.CoordinateFrame = camera.CoordinateFrame + Vector3.new(0, cameraSpeed, 0) end if cameraX - cameraXChase < playerX then camera.CoordinateFrame = camera.CoordinateFrame + Vector3.new(cameraSpeed, 0, 0) end end end RunService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, onUpdate)
The camera jitters in the Y-axis whenever the player climbs a slope because the rate in which the Y changes is too slow (especially if the slope isn't steep). If the player jumps, you won't notice the jitter in the camera because the change in Y is big.
Instead of moving the camera at a fixed increment, try making it so that it goes part of the way (20%, for example) every frame.
I've also refactored and documented your script, which should take care of movement in all axes.
-- the offset of the camera in relation to the player. It is 10 studs to the left, 20 studs above, and 20 studs away from the player local CamOffset = Vector3.new(10, 20, 20) -- the direction in which the camera looks at. z = -1 means that it looks towards the player. local CamLookDirection = Vector3.new(0, 0, -1) local camera = game.Workspace.CurrentCamera local player = game.Players.LocalPlayer local RunService = game:GetService('RunService') local function setupCamera() -- constructs the CFrame for the camera. You should probably check if HumanoidRootPart exists yet. camera.CoordinateFrame = CFrame.new(player.Character.HumanoidRootPart.Position + CamOffset, player.Character.HumanoidRootPart.Position + CamOffset + CamLookDirection) end player.CharacterAdded:connect(setupCamera) local function onUpdate() if player.Character and player.Character:FindFirstChild('HumanoidRootPart') then -- lerps (linearly interpolates) the camera every frame. Each frame, it is 20% closer to its destination(0.2 == 20%). camera.CoordinateFrame = camera.CoordinateFrame:lerp( CFrame.new(player.Character.HumanoidRootPart.Position + CamOffset, player.Character.HumanoidRootPart.Position + CamOffset + CamLookDirection), 0.2 ) end end RunService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, onUpdate)
Why not use interpolation? It's a method which allows smooth movement of the camera.
Here's the wiki article