Weapon recoil increasing the higher the FPS

So ever since the new FPS selector got added into roblox’s settings. I’ve noticed that my gun’s recoil would multiply the higher the frames you were running.

I did a ton of research and came to a conclusion of using RenderStepped DeltaTime to make the recoil caluculations parallel to the clients frames.

I’ve tried every way i could like, dividing the recoil or multiply the recoil but nothings working. This is just very exhausting for me and im losing motivation to keep trying to fix this.

Any fixes or idea’s on how to implement deltaTime would be greatly appreciated.

local function RecoilCamera()
	if Module.CameraRecoilingEnabled then
		
		RunService.RenderStepped:Connect(function(DeltaTime)
			
		-- I put in delta time  here ^^^^
			
		local Recoil = AddressTableValue(Module.ChargeAlterTable.Recoil, Module.Recoil)
		local CurrentRecoil = Recoil * (AimDown and 1 - Module.RecoilRedution or 1)
		local RecoilX = math.rad(CurrentRecoil * Math.Randomize2(Module.AngleX_Min, Module.AngleX_Max, Module.Accuracy))
		local RecoilY = math.rad(CurrentRecoil * Math.Randomize2(Module.AngleY_Min, Module.AngleY_Max, Module.Accuracy))
		local RecoilZ = math.rad(CurrentRecoil * Math.Randomize2(Module.AngleZ_Min, Module.AngleZ_Max, Module.Accuracy))
		
		Knockback:Accelerate(Vector3.new(-RecoilX * Module.ScopeKnockbackMultiplier, - RecoilY * Module.ScopeKnockbackMultiplier, 0))
		CameraSpring:Accelerate(Vector3.new(RecoilX, RecoilY, RecoilZ))
		CameraSpring:Accelerate(Vector3.new(RecoilX , RecoilY, -RecoilZ))
		
-- THIS IS THE MODULES SETTINGS JUST INCASE YOU NEED REFERENCE
		--[[
			CameraRecoilingEnabled = true;
	Recoil = 100;
	AngleX_Min = 1.13; --In degree
	AngleX_Max = 1.13; --In degree
	AngleY_Min = -0.12; --In degree
	AngleY_Max = 0.12; --In degree
	AngleZ_Min = -1; --In degree
	AngleZ_Max = 1; --In degree
	Accuracy = 0.2; --In percent. For example: 0.5 is 50%
	RecoilSpeed = 55; 
	RecoilDamper = 0.50;
	RecoilRedution = 0.5; --In percent.
	]]
		end)
	end
end

Try changing from RenderStepped to Heartbeat

multiplying by deltatime is the way to do it. if it’s not working then it’s a problem with your implementation.

2 Likes

You’ll need to implement deltaTime. Heartbeat, RenderStepped etc all pass it as a parameter. I’m not gonna give you code you could copy-paste, but I’ll give you a general idea.

Consider we have this code, that moves a part forward every frame.

local speed = 5
RunService.Heartbeat:Connect(function()
    part.Position += Vector3.new(0, 0, 0.01 * speed)
end)

But, if our fps was higher, the function would run more often, thus resulting in faster movement. If we however add deltaTime

local speed = 5
RunService.Heartbeat:Connect(function(deltaTime) -- deltaTime is the time since the last frame to the current one
    part.Position += Vector3.new(0, 0, speed * deltaTime)
end)

then the part actually moves at a constant speed, even when fps changes

Okay so ive implemented it like this and its just flinging my camera upwards, sorry im just very confused

RunService.Heartbeat:Connect(function(DeltaTime)
			
			local speed = 5
		
			Knockback:Accelerate(Vector3.new(-RecoilX * Module.ScopeKnockbackMultiplier, - RecoilY * Module.ScopeKnockbackMultiplier, 0))
			CameraSpring:Accelerate(Vector3.new(RecoilX, RecoilY, RecoilZ * speed))
			CameraSpring:Accelerate(Vector3.new(RecoilX , RecoilY, -RecoilZ * speed))

My main trouble is implementing it…

You also need to multiply the speed by deltatime

i’ve done that and its just constantly moving my camera upwards, or launching my camera upwards
@hannes213