Players are getting different camera shakes when they play at around 60 FPS or more

  1. What do you want to achieve?
    Because of Roblox FPS unlocker, I want to lock the camera shake for all the Players who are playing at around 60 FPS or more.

  2. What is the issue?
    I ran the camera script with using Roblox Fps Unlocker and the Intensity of the Bobbing is much more Stronger.

Video of script running at around 240 FPS

But when I cap the script at 60 FPS, the intensity is more weaker. The higher the FPS, the more stronger the intensity gets.

Video of script running at 60 FPS

Is there a way to lock the bobbing effect when Players are playing around 60 FPS or more?

Any help is appreciated, thanks!

The Script
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local camera = workspace.CurrentCamera

local speed = 3
local intensity = 0.08
local smoothness = 0.2

RunService.RenderStepped:Connect(function()


	local t = tick()
	local x = math.cos(t * speed) * intensity 
	local y = math.sin(t * speed) * intensity
	local z = -10
		
	if Sprinting == true and hum.MoveDirection.Magnitude > 0 then 
		intensity = 0.5
		speed = 10
	else
		speed = 3
		intensity = 0.08
	end		

	local cf = CFrame.new(Vector3.new(x, y, 0), Vector3.new(x*0.95, y*0.95, z)) + camera.CFrame.Position
	camera.CFrame = camera.CFrame:Lerp(cf * camera.CFrame.Rotation, smoothness)
end)

1 Like

.RenderStepped is based on fps, try using .Stepped

Same Results here!
Replacing .Renderstepped with .Stepped didn’t changed anything at all.

Have you tried just a while loop?

If your shaking the camera using RenderStepped (which you are) you will receive a different result. This would be the same on lower end devices that get lower fps. The shake would be alot more janky and would have less shakes making it less smooth. If a player has FPS unlocker they will have a quicker camera shake. Camera shakes are better off with manual/controllable loops.

while true do
	local t = tick()
	local x = math.cos(t * speed) * intensity 
	local y = math.sin(t * speed) * intensity
	local z = -10
		
	if Sprinting == true and hum.MoveDirection.Magnitude > 0 then 
		intensity = 0.5
		speed = 10
	else
		speed = 3
		intensity = 0.08
	end		

	local cf = CFrame.new(Vector3.new(x, y, 0), Vector3.new(x*0.95, y*0.95, z)) + camera.CFrame.Position
	camera.CFrame = camera.CFrame:Lerp(cf * camera.CFrame.Rotation, smoothness)
task.wait(0)
end

Although many scripters may disagree with your code i reformatted, i use this on all camera shakes and have seen the same results on all devices with different fps.
To control this use a loop like this

for _ = 1,100,1 do
task.wait(0)
end

The frequency at which the .RenderStepped event is fired is equal to the the client’s framerate, which is an important fact your script doesn’t seem to be taking into account. In order to to achieve a constant intensity of camera movement under all circumstances, you can read the dt (deltaTime) parameter of the RenderStepped event and multiply that with the smoothness variable that you’re using in your lerp function. Additionally, you should clamp the alpha argument of the lerp function to values less than or equal to 1. Under the assumption that the game is normally running at 60 FPS, your script could look like this:

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local camera = workspace.CurrentCamera

local speed = 3
local intensity = 0.08
local smoothness = 0.2

RunService.RenderStepped:Connect(function(deltaTime)

	local t = tick()
	local x = math.cos(t * speed) * intensity 
	local y = math.sin(t * speed) * intensity
	local z = -10
		
	if Sprinting == true and hum.MoveDirection.Magnitude > 0 then 
		intensity = 0.5
		speed = 10
	else
		speed = 3
		intensity = 0.08
	end		

	local cf = CFrame.new(Vector3.new(x, y, 0), Vector3.new(x*0.95, y*0.95, z)) + camera.CFrame.Position
	camera.CFrame = camera.CFrame:Lerp(cf * camera.CFrame.Rotation, math.clamp(smoothness * deltaTime * 60, 0, 1))
end)
2 Likes

Sorry for the long wait!
I marked the topic as solved.
Thank you guys so much for your patience, explaining and for helping me out :slightly_smiling_face:! @shadowmaster940 , @VisuallyFX , @Tix1511.