Smoothly rotating camera

How do i smoothly rotate the players camera left and right?

Currently i’m cframing the rotation but it isn’t very smooth and this affects the turning of my custom movement script…

I’ve tried using tweenservice but it just ending up being a mess

camera.CFrame = camera.CFrame * CFrame.Angles(0,math.rad(.1),0)

this is what i’m currently using, if you know a way to make it smooth please help me out!

2 Likes

Multiple the angle by the frame time.

camera.CFrame = camera.CFrame * CFrame.Angles(0, math.rad(30) * dt, 0)

You can get the frame time (dt) from the parameters passed to RenderStepped or Stepped or Heartbeat, or from the return value of task.wait()/wait(), whatever you’re using.

1 Like

dont really understand the dt bit, sorry

If you post more of your code I would be able to help more.

	camera.CFrame = camera.CFrame * CFrame.Angles(0, math.rad(-.1) 20, 0)
	end
	function rightEnd()
		
		end```
that is pretty much the entire right bit (its constantly fired when the player presses d)

What does this mean? Can you share the code?

	if (humanoid.MoveDirection:Dot(camera.CFrame.RightVector) > 0.37) or (humanoid.MoveDirection:Dot(camera.CFrame.RightVector) > 0.85) then
		--	print("we're going right")
		right()
	elseif not isleftdown then
		isRightdown = false
		rightEnd()
	end
	if (humanoid.MoveDirection:Dot(camera.CFrame.RightVector) <- 0.37)  or (humanoid.MoveDirection:Dot(camera.CFrame.RightVector) <- 0.85) then
		--	print("we're going left")
		left()
	elseif not isRightdown then
		isleftdown = false
		leftEnd()
	end
	doforwarding()
end```

But what is actually calling this code? What event are you hooked into?

Just what ive shown, theres nothing else calling it besides that

Please copy and paste all of your code here.

Most of its unrelated and has no need, nothing else in the script has to do with it

As @nicemike40 suggested, dt would be a reasonable approach. dt stands for delta-time, it’s a return variable of Heartbeat, Stepped, & RenderStepped. dt tells you how many fractions of a second have elapsed since the previous frame.

If you hook your CFrame rotation to a RenderStepped function you could easily implement this like so:

local RS = game:GetService("RunService")

local rotationRate = 15

RS.RenderStepped:Connect(function(dt)
    camera.CFrame *= CFrame.Angles(0, math.rad(rotationRate) * dt, 0)
end)
3 Likes

This works, thank you! sadly theres some unwanted bumpiness would you know how to fix this? other-than that its perfect. https://gyazo.com/5e7ab74f1e53568b8dabe9e1c71c2c32

If you want to remove the bumpiness I would recommend using the lerp function that accompanies the CFrame instance.

local RS = game:GetService("RunService")

local cam = workspace.CurrentCamera

local rotationRate = 15

RS.RenderStepped:Connect(function(dt)
	local cf = cam.CFrame * CFrame.Angles(0, math.rad(rotationRate) * dt, 0)
	cam.CFrame = cam.CFrame:Lerp(cf,.5)
end)

Let me know if this removes the bumpiness or not! :slight_smile:

2 Likes

Nope sadly the annoying camera offset still happens.
it so far: https://gyazo.com/4714a16fc84f86564a02d4d511eb95fe
and this is an example of how it should be https://gyazo.com/5d8403871a38cd48e0e1584667fb596f
(the arrow keys)

Sorry for the late response, have you tried turning off autorotate?
Humanoid | Roblox Creator Documentation.

Yeah, its off doesn’t seem too be an issue with the character, just the camera