How can I stop this slowing/speeding up when fps changes

RotateForce.AngularVelocity = Vector3.new(0, math.clamp( (-mouseDelta.X / 35) / dt , -5, 5)  ,0)

this is running on renderstepped
Ive been stuck on this for a while

when the fps is capped at 60fps, it goes faster
when the fps is capped at 240fps it goes slower

Ive tried using deltaTime but I cant get it working

What youre going to need to do is use our wonderful deltatime! deltatime is basically the time since the last frame, and by multiplying it by whatever you’re doing it’ll end up running the exact same no matter the frame rate.

How do we get deltatime? well RenderStep gives it to us as an argument or parameter (I cant remember which one its called :sob: )

RS.RenderStepped:Connect(function(DeltaTime)

end)

heres an example, lets say we have this code here:

local TimePassed = 0

RS.RenderStepped:Connect(function(DeltaTime)
    TimePassed += 1
end)

What this would do is add 1 to TimePassed every frame, which isnt exactly what I want if I want to count by seconds.
If I have like 60 fps, then by the end of a second the number will be 60 instead of just 1.

so what we can do is multiply the 1 second by delta time!

(In this case since the number is 1 you could just add DeltaTime, but this is an example)

local TimePassed = 0

RS.RenderStepped:Connect(function(DeltaTime)
    TimePassed += 1 * DeltaTime
end)

Im not really going to go into the math of everything, but basically what this does is that after one second has passed, no matter my fps, the TimePassed will be around 1 second.

so ye, hope this helps!

2 Likes

hi Thanks for responding
I still dont really understand, i thought thats what I was doing

RotateForce.AngularVelocity = Vector3.new(0, math.clamp( (-mouseDelta.X / 35) / dt , -5, 5)  ,0)

Im dividing it by dt (deltatime) and changing it to multiply does the same thing

You should be multiplying by dt after clamping the value:

RotateForce.AngularVelocity = Vector3.new(0, math.clamp(-mouseDelta.X / 35 , -5, 5) * dt, 0)

You may need to multiply the dt by a large constant.
Your other numbers like 35, -5, and 5 may also need to be changed as these numbers will be based per frame now.

If this doesn’t work, please send me the original code including your calculations for mouseDelta.

1 Like

Hi thanks for responding
I think I did it wrong

	postSimulationConnec = renderstepped:Connect(function(dt)
		
		local mouseDelta  = uis:GetMouseDelta()
		RotateForce.AngularVelocity = Vector3.new(0, math.clamp( (-mouseDelta.X ) , -5, 5) * dt * 100  ,0)

	end)

1 Like

Can you try this instead:

postSimulationConnec = renderstepped:Connect(function(dt)
	local mouseDelta  = uis:GetMouseDelta()
	local angularSpeed = (-mouseDelta.X / dt) * 30
	RotateForce.AngularVelocity = Vector3.new(0, math.clamp(angularSpeed, -5, 5), 0)
end)

I realized that since mouseDelta isn’t based off dt, the calculation will need to be done on it first.

1 Like

you are meant to multiply by deltaTime, not divide

local dividedMouseDelta = (-mouseDelta.X / 35)
local clampedValue = math.clamp(dividedMouseDelta * dt, -5, 5)
local angularVelocity = Vector3.new(0, clampedValue, 0)
1 Like

Same thing happening

	postSimulationConnec = renderstepped:Connect(function(dt)

		local mouseDelta  = uis:GetMouseDelta()
		local angularSpeed = (-mouseDelta.X / dt) * 1
		
		RotateForce.AngularVelocity = Vector3.new(0, math.clamp( (angularSpeed ) , -5, 5)  ,0)

	end)

You are still dividing dT.

In order to properly compensate for framerate, you must define a desired speed (which is a function of distance over time), then multiply it by delta time ((distance / time) * time), which will give you the distance.

1 Like

inshallah you are going to be lobotomized

7 Likes

I tried multiplying like yours and got same result

Please show your code with the multiplication.

1 Like
	postSimulationConnec = renderstepped:Connect(function(dt)

		
		local mouseDelta  = uis:GetMouseDelta()
		local angularSpeed = (-mouseDelta.X / dt) * 1
		
		local dividedMouseDelta = (-mouseDelta.X / 1)
		local clampedValue = math.clamp(dividedMouseDelta * dt, -5, 5)
		local angularVelocity = Vector3.new(0, clampedValue, 0)
		
		RotateForce.AngularVelocity = angularVelocity

		camera.CFrame = CameraPart.WorldCFrame 
	end)

You are dividing here, you can just remove this as you are already compensating for it in clampedValue.

1 Like

That was unused variable sorry, same thing happens

	postSimulationConnec = renderstepped:Connect(function(dt)
		
		local mouseDelta  = uis:GetMouseDelta()
		
		local dividedMouseDelta = (-mouseDelta.X / 1)
		local clampedValue = math.clamp(dividedMouseDelta * dt, -5, 5)
		local angularVelocity = Vector3.new(0, clampedValue, 0)
		
		RotateForce.AngularVelocity = angularVelocity

		camera.CFrame = CameraPart.WorldCFrame 
	end)

oh

local elapsed = 0
-- your logic

local clampedValue = math.clamp((dividedMouseDelta * elapsed) * dt), -5, 5)

elapsed += dt -- increment elapsed at the end
1 Like

You’re using AngularVelocity which applies an angular velocity onto the assembly it’s connected to.

The physics engine already compensates for lag and mouse delta changes according to framerate, so you shouldn’t be compensating for delta time in the first place.

1 Like


removing DT this happens still
i think it has something to do with renderstepped and mouseDelta but im not sure

Can you please show your current code?

1 Like
	postSimulationConnec = renderstepped:Connect(function(dt)

		
		local mouseDelta  = uis:GetMouseDelta()
		
		
		local dividedMouseDelta = (-mouseDelta.X / 1)
		local clampedValue = math.clamp(dividedMouseDelta , -5, 5)
		local angularVelocity = Vector3.new(0, clampedValue, 0)
		
		RotateForce.AngularVelocity = angularVelocity


		camera.CFrame = CameraPart.WorldCFrame 
	end)