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

Hmm, what if you made the RenderStepped run before the camera

run:BindToRenderStep("SmoothCam", Enum.RenderPriority.Camera.Value-1, 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 works better than the other ones but it is very glitchy

1 Like

Alright, how about setting the roblox sensitvity to 0, then implementing my custom smooth camera

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 clamp = math.clamp

local current = Vector2.zero
local targetX, targetY = 0, 0

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

uis.MouseDeltaSensitivity = 0
cam.CameraType = Enum.CameraType.Custom

run:BindToRenderStep("SmoothCam", Enum.RenderPriority.Camera.Value-1, 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)
	cam.CFrame = CFrame.Angles(0,current.X/mult,0)*CFrame.Angles(current.Y/mult,0,0)
end)

now it wont rotate at all :pensive:

roblox wont let me send unless i have more chars so just typing this to reach the limit

We solved this through dms, here is the final code for anyone who needs help too.

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

local cam = workspace.Camera
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local rad = 180/math.pi
local clamp = math.clamp

local current = Vector2.zero
local targetX, targetY = 0, 0

local speed = 10 -- Speed of the animation
local sensitivity = 1 -- Sensitivity of the rotation
local releaseSpeed = 0.5 -- How much speed remains when you release

uis.MouseDeltaSensitivity = 0.01
cam.CameraType = Enum.CameraType.Custom

run:BindToRenderStep("SmoothCam", Enum.RenderPriority.Camera.Value-1, function(dt)
	local delta = uis:GetMouseDelta()*sensitivity*100
	targetX -= delta.X
	targetY = clamp(targetY-delta.Y,-89,89)
	current = current:Lerp(Vector2.new(targetX,targetY), dt*speed)
	cam.CFrame = CFrame.fromOrientation(current.Y/rad,current.X/rad,0)
end)
mouse.Button2Up:Connect(function()
	local new = current:Lerp(Vector2.new(targetX,targetY), releaseSpeed)
	targetX = new.X
	targetY = new.Y
end)
22 Likes

I see 1 issue with it is that for me it’s inverted.

1 Like

do this

cam.CFrame = CFrame.fromOrientation(-current.Y/-mult,current.X/mult,0)```

why this inverted???

i can rotation with smooth camera but when i unclick b/c im use tweensv camera not working to my mind, Can you help me?(sorry grammar)
script smooth camera:
repeat wait() until game:IsLoaded()
local plr = game.Players.LocalPlayer
local chr = plr.Character
local part = Instance.new(‘Part’,chr)
local hrp = chr:WaitForChild(‘HumanoidRootPart’)
part.Name = ‘Camera’
part.Anchored=true
part.CanCollide=false
part.Transparency=1
local RotationCamera=chr:WaitForChild(‘RotationCamera’)
local uis=game:GetService(‘UserInputService’)
local runsv = game:GetService(‘RunService’)
local tweensv = game:GetService(‘TweenService’)
local camera = workspace.CurrentCamera
local mouse = plr:GetMouse()
runsv.RenderStepped:Connect(function()
if not RotationCamera.Value then
camera.CFrame=part.CFrame
game:GetService(‘TweenService’):Create(part,TweenInfo.new(2,Enum.EasingStyle.Back),{CFrame=hrp.CFrame*CFrame.new(0,2,12) }):Play()
end
end)
YourScript(i was rewrite):
repeat wait() until game:IsLoaded()
local uis = game:GetService’UserInputService’
local cam = workspace.Camera
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local click=Instance.new(‘BoolValue’,plr.Character)
click.Name=“RotationCamera”
click.Value=false
local mult = 180/math.pi
local clamp = math.clamp

local current = Vector2.zero
local targetX, targetY = 0, 0

local speed = 2 – Set the speed of the animation
local sensitivity = 2 – Set the sensitivity of the rotation
local releaseDecel = .5 – Set how much it slows down when you release

uis.MouseDeltaSensitivity = 0.01
cam.CameraType = Enum.CameraType.Custom

game:GetService(‘RunService’):BindToRenderStep(“SmoothCam”, Enum.RenderPriority.Camera.Value-1, function(dt)
if click.Value then
local delta = uis:GetMouseDelta()sensitivity100
targetX += delta.X
targetY = clamp(targetY+delta.Y,-90,90)
current = current:Lerp(Vector2.new(targetX,targetY), dt*speed)
cam.CFrame = CFrame.fromOrientation(current.Y/mult,current.X/mult,0)
end
end)
uis.InputBegan:Connect(function(key,prg)
if prg then return end
if key.UserInputType==Enum.UserInputType.MouseButton2 then
click.Value=true
local new = Vector2.new(targetX,targetY):Lerp(current, releaseDecel)
targetX = new.X
targetY = new.Y
end
end)
uis.InputEnded:Connect(function(key,prg)
if prg then return end
if key.UserInputType==Enum.UserInputType.MouseButton2 then
click.Value=false
end
end)

How can I make this toggle able?

If the camera is inverted, try changing code lines 23 and 24 with this

targetX += -delta.X
targetY = clamp(targetY-delta.Y,-90,90)

at least it works for me

1 Like

Not sure why, but script breaks when you sit inside of vehicle seat

targetX += -delta.X
targetY = clamp(targetY-delta.Y,-80,80)

this prevents weird glitches when you look directly above, or below your character

1 Like