I’ve noticed something weird about this when testing a game I’m working on the actual server and not studio. Since I use an FPS unlocker for roblox, whenever I go into a game, the recoil amount that is supposed to be given is significantly higher than it is on the studio. Heres the code I am using
local CFANG = CFrame.Angles
local RAD = math.rad
local COS = math.cos
CamShake.Recoil = function(recoilamount)
cam.CFrame = cam.CFrame*CFANG(RAD(COS(recoilamount)*5),0,0)
end
I connect this function to BindToRenderStep then unbind it quickly after so it simulates recoil.
(This may look a little weird to those who actually know what they are doing with math in roblox, but this was the best I could do, its also in a module script). When testing it in studio where the max fps is 60, the recoil is normal, its the amount I want it to be. When I test the game in a roblox server where my FPS unlocker is enabled, the recoil is significantly higher. Then when I turn off my FPS unlocker, it is at the amount it is in studio. Is there a work around or are people that use FPS unlockers in the game going to be stuck like this?
yea the moment you say BindToRenderStep I already saw a problem
RenderService is used for stuff that runs every frame
higher the frame obv the higher the recoil amount
The function that you connect will be passed a “delta” parameter which is the time since the last frame. When your fps is higher, delta will be smaller, and vice versa.
On 60 fps, the delta time should be around 1 / 60, or ~0.016667 seconds. On 120 fps it should be twice as small, 1 / 120, or around 0.008333 seconds. You can use this delta time to account for varying frame rates.
For example, you would probably want to make the recoil-per-frame smaller with higher framerates (since RenderStepped will run more times in a second with a higher framerate)
Something like this would probably work:
RunService:BindToRenderStep("Recoil", 1000, function(Delta)
local RecoilAmount = 3
-- in this case, Delta * 60 would average at
-- about 1 at 60 fps, 2 at 120 fps, etc.
-- so basically, if the framerate is 120,
-- then the recoil would be twice as small
CamShake.Recoil(RecoilAmount / (Delta * 60))
end)
srry for late response but I tried this rn and it didnt work. Idk if i did anything wrong but what happens is that sometimes when testing on the roblox server it gives me the correct amount of recoil, sometimes too little, and sometimes too much.
local function shootRecoil(waittime)
rs:BindToRenderStep("Recoil",Enum.RenderPriority.Camera.Value,function(dt)
camShake.Recoil(10/(dt*60))
end)
wait(waittime)
rs:UnbindFromRenderStep("Recoil")
end
My bad, I think you should multiply by (dt * 60) instead of divide since dt will be less with higher fps. Also the dt isn’t always super accurate, it fluctuates but it should be pretty close. The wait(waittime) might affect it too maybe if it’s really short?