How would I make the player's camera smoothly rotate, instead of it being instant?

I am trying to get the camera to tween to the correct rotation (when you right click to rotate the camera) but I can’t figure out how to do it.

I’ve looked through quite a few DevForum threads but none of them seem to have what I want to do.

Any help is greatly appreciated!

This game has the kind of camera I’d like to do: ACF - APOLLO - Roblox

4 Likes

I assume that you are setting the CFrame for the camera. This will cause the camera to teleport instantly. You can use TweenService instead to move the CFrame smoothly

1 Like

I’m not setting the CFrame, I mean like, making the default Roblox camera smooth when you rotate it

1 Like

you mean like when you rotate you camera in studio example?
but what do you mean [instead of it being instant?]

3 Likes

Yep.

In game, there isn’t any animation for when you rotate the camera, it just follows your mouse or whatever and you can just spin around really fast.

I want the camera to just move smoothly when you rotate the camera instead of it being quite fast and having no animation

For example, there is this plugin which does it in studio, Smooth Cam - Roblox

(I want it in 3rd person as well, not 1st person)

1 Like

can you try this. Put it in a local script

local run = game:GetService'RunService'
local uis = game:GetService'UserInputService'

local cam = workspace.Camera
local plr = game.Players.LocalPlayer
local mult = 180/math.pi

local current = Vector2.zero
local target = current

local speed = 2 -- Set the speed of the animation
local sensitivity = 1 -- Set the sensitivity of the rotation

cam.CameraType = Enum.CameraType.Scriptable

run.RenderStepped:Connect(function(dt)
	target += uis:GetMouseDelta()*sensitivity
	current = current:Lerp(target, dt*speed)
	cam.CFrame = CFrame.Angles(0,current.X*mult,0)*CFrame.Angles(current.Y*mult,0,0)
end)
1 Like

It makes my camera go crazy whenever I try moving & the camera is not facing my character

1 Like

Try changing this part, to this

cam.CameraType = Enum.CameraType.Custom
1 Like

The same thing still happens.

I believe it could be due to the CFrames position being 0,Y,0?

1 Like

Can you try this, put it under StarterCharacterScripts.

local run = game:GetService'RunService'
local uis = game:GetService'UserInputService'

local cam = workspace.Camera
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character
local head = char:WaitForChild'Head'

local current = Vector2.zero
local targetX, targetY = 0, 0
local zoom = 10
local targetZoom = zoom

local asin = math.asin
local clamp = math.clamp
local pi = math.pi
local mult = 180/pi

local minZoom, maxZoom = 0.5, 50 -- Set zoom limits
local speed = 2 -- Set the speed of the animation
local sensitivity = 1 -- Set the sensitivity of the rotation

local function lerp(a,b,t)
	return a + (b - a) * t
end

cam.CameraType = Enum.CameraType.Scriptable

run.RenderStepped:Connect(function(dt)
	local delta = uis:GetMouseDelta()*sensitivity
	targetX += delta.X
	targetY = clamp(targetY + delta.Y,-90,90)
	current = current:Lerp(Vector2.new(targetX,targetY), dt*speed)
	zoom = lerp(zoom,targetZoom, dt*speed)
	cam.CFrame = CFrame.Angles(0,current.X*mult,0)*CFrame.Angles(current.Y*mult,0,0)*CFrame.new(0,0,zoom)+head.Position
end)

mouse.WheelForward:Connect(function()
	targetZoom = targetZoom - 3 < minZoom and minZoom or targetZoom - 3
end)
mouse.WheelBackward:Connect(function()
	targetZoom = targetZoom + 3 > maxZoom and maxZoom or targetZoom + 3
end)

I know there is a much better way to do this. I don’t even think this will work

The zoom works but it won’t rotate anymore & it breaks CloneTrooper1019’s Realism script

Oh, about the not rotating part, I forgot to add this at the bottom.

mouse.Button2Down:Connect(function()
	uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end)
mouse.Button2Up:Connect(function()
	uis.MouseBehavior = Enum.MouseBehavior.Default
end)

About the Realism script, I’m not really sure.

The camera still goes crazy whenever I try to rotate it

Not exactly what you need, but I use animations on a CameraPart and change its CFrame to the CamPart until it’s finished playing.

It’s neat for cutscenes.

Also post your code.

Oh wait, replace this part (if you can find it)

cam.CFrame = CFrame.Angles(0,current.X*mult,0)*CFrame.Angles(current.Y*mult,0,0)*CFrame.new(0,0,zoom)+head.Position

with this

cam.CFrame = CFrame.Angles(0,current.X/mult,0)*CFrame.Angles(current.Y/mult,0,0)*CFrame.new(0,0,zoom)+head.Position

Yep this works pretty well!

Thank you!

Ok, um, is the realism script still broken? Can you try this?

local run = game:GetService'RunService'
local uis = game:GetService'UserInputService'

local cam = workspace.Camera
local plr = game.Players.LocalPlayer
local mult = 180/math.pi

local current = Vector2.zero
local target = current

local speed = 2 -- Set the speed of the animation
local sensitivity = 1 -- Set the sensitivity of the rotation

cam.CameraType = Enum.CameraType.Scriptable

run.RenderStepped:Connect(function(dt)
	target += uis:GetMouseDelta()*sensitivity/2
	current = current:Lerp(target, dt*speed)
	cam.CFrame = CFrame.Angles(0,current.X/mult,0)*CFrame.Angles(current.Y/mult,0,0)
end)

This is the first script I gave you but modified to not make the camera go crazy

This one doesn’t seem to work at al

1 Like

I’m sorry if I’m replying too much. I just want to see which script works with the realism script.
Can you try this

local run = game:GetService'RunService'
local uis = game:GetService'UserInputService'

local cam = workspace.Camera
local plr = game.Players.LocalPlayer
local mult = 180/math.pi

local current = Vector2.zero
local target = current

local speed = 2 -- Set the speed of the animation
local sensitivity = 1 -- Set the sensitivity of the rotation

cam.CameraType = Enum.CameraType.Custom

run.RenderStepped:Connect(function(dt)
	target += uis:GetMouseDelta()*sensitivity/2
	current = current:Lerp(target, dt*speed)
	cam.CFrame = CFrame.Angles(0,current.X/mult,0)*CFrame.Angles(current.Y/mult,0,0)
end)

It seems to be rotating fine but the camera position is not working