Making .renderStepped independent on FPS

  1. I want to achieve that the sway system is independent on fps so its not too wiggly for other user or too stiff

  2. The issue is that the sway looks different on 60 fps 30 fps and 120 fps and more

  3. I tried looking on the devforum if someone had the same issue but i didnt really find out how to fix my problem

game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
	mouseDelta = game:GetService("UserInputService"):GetMouseDelta()
	local intensityX = mouseDelta.X/700
	local intensityY = mouseDelta.Y/500
	local sensitivity = 0.1
	local DeadZone = 0.07
	if mouseDelta.X <= sensitivity and Equipped then
		UnlockedOffsetCFrame = Vector3.new(UnlockedOffsetCFrame.X,UnlockedOffsetCFrame.Y - intensityX,0)
		---------------------------------------------
	elseif mouseDelta.X >= sensitivity and Equipped then
		UnlockedOffsetCFrame = Vector3.new(UnlockedOffsetCFrame.X,UnlockedOffsetCFrame.Y - intensityX,0)
		---------------------------------------------
	end
	if mouseDelta.Y <= sensitivity and Equipped then
		UnlockedOffsetCFrame = Vector3.new(UnlockedOffsetCFrame.X - intensityY,UnlockedOffsetCFrame.Y,0)
		---------------------------------------------
	elseif mouseDelta.Y >= sensitivity and Equipped then
		UnlockedOffsetCFrame = Vector3.new(UnlockedOffsetCFrame.X - intensityY,UnlockedOffsetCFrame.Y,0)
		---------------------------------------------
	end
	UnlockedOffsetCFrame = Vector3.new(
		math.clamp(UnlockedOffsetCFrame.X,-0.05,0.05),
		math.clamp(UnlockedOffsetCFrame.Y,-DeadZone,DeadZone),
		math.clamp(UnlockedOffsetCFrame.Z,-DeadZone,DeadZone)
	)
	if Aiming then
		UnlockedOffsetCFrame = Vector3.new(0,0,0)
	end
	mouseDelta = Vector2.new(math.clamp(mouseDelta.X,-10,10),math.clamp(mouseDelta.Y,-10,10))
	unlok:shove(UnlockedOffsetCFrame)
	unlocked = unlok:update(deltaTime)
	sway1:shove(Vector3.new(mouseDelta.x / 200,mouseDelta.y / 200))
	statusSway:shove(Vector3.new(mouseDelta.x / 5000,mouseDelta.y / 5000))
	strafe:shove(strafeCFrame)
	walking:shove(WalkCFrame)

	sway = sway1:update(deltaTime)
	swayTs = statusSway:update(deltaTime)
	strafing = strafe:update(deltaTime)
	walk = walking:update(deltaTime)
	jumps = jumpSpring:update(deltaTime)
end)

Thank you.

You get dT which means you can do something like this:

local refreshRate = 1/60
local timeElapsed = 0
game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
	timeElapsed += deltaTime
	if timeElapsed < refreshRate then return end -- Only update ever X seconds
	timeElapsed = 0
	mouseDelta = game:GetService("UserInputService"):GetMouseDelta()
	... -- Rest of the code
end)
1 Like

You can use deltaTime returned by the RenderStepped function to make values look similiar on different framerates, an example would look like this:

RunService.RenderStepped:Connect(function(dT)
    Part.Position += Vector3.new(dT, 0, 0)
end)

Since deltaTime is usually a very small number, we should also multiply deltaTime by a number so the “speed” is correct.

local m = 5

Part.Position += Vector3.new(dT * m, 0, 0)

If it’s still too slow or fast, then you can keep adjusting the m until you get what you want.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.