Projectile gravity broken when fps is unlocked

Hello everyone, I’ve been working on a game where you collect snow by shooting a ball projectile, and I’ve ran into a problem. I’m using FastCast and when I test in studio, everything’s perfect, the projectile goes in the right direction and its synced with the client. However, if i test it with fps unlocker in game the gravity applies faster, which is a problem since its not getting synced. I don’t really know how I could sync it, one way of doing it I thought is i could use another function to apply gravity which would run for 60 frames per second so that fps unlocker isnt impacting the gravity, but i don’t know how to do that.

1 Like

I’m not really sure how FastCast works and I would generally recommend against using modules. With that said, it sounds like that module or your code us tied to framerate in some way. You should look through and try to find anything that may contain RenderStepped, then replace it with something independent from render framerate like Heartbeat.

1 Like

Heartbeat seems to be doing the same thing since when i replaced it nothing changed

1 Like

That’s a bit odd, alternatively you can use task.wait(1/60) in a loop, but there are better ways to sync with a framerate. Is it using an event or is it using a loop?

1 Like

I’m using FastCast LengthChanged to change the position of the projectile

1 Like

You’d have to look into the module to see how it handles that. If it’s using an event, you can try something like:

local lastFrame = os.clock()
game:GetService('RunService').Heartbeat:Connect(function()
	local currentFrame = os.clock()
	if currentFrame-lastFrame >= 1/60 then
		lastFrame = currentFrame
		-- run other code
	end
	currentFrame = nil
end)

This will only execute an update once every 1/60th of a second, which is the default framerate.

1 Like

Didn’t work, i also tried while task.wait(1/60) do and while task.wait() do

1 Like

All of those do work on their own, so I’m not sure what the issue with your code is. This is why I would recommend not using modules so that you fully understand what’s going on with your code, as modules can end up being like a sort of “black box” if you don’t read through it and understand how it works.

1 Like

What I ended up doing is adding delta argument to SendLengthChanged function so that it sends delta from the function, I then do local scale = delta * 60 and then i multiple the Y velocity by it, so it works now

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