Alright so let me explain, in a laggy game depending on the Player’s FPS I have analyzed that if your FPS is very low, Projectiles and lets say for an example a Part sizing in a For loop, they will lag & take a slow process to complete, rather with high FPS they run buttery smooth and they finish at their maximum speed. I’m wondering if there’s a way to speed up projectiles or stuff sizing based on the player’s FPS? Please leave any questions below if you have them!
You could check the players FPS based on the game physics (LocalScript) using GetRealPhysicsFPS.
Example:
while wait(1) do
if Workspace:GetRealPhysicsFPS() > 65 then
-- Speed up projectiles locally.
end
end
First things first; are you appropriately managing the network ownership of the projectiles or rendering them solely on the client?
If you aren’t handling network ownership properly, you’ll see that the projectiles appear choppy but not anything else. This is due to switch in network ownership. The server and each individual client can simulate projectile physics at different FPS rates.
If you’re rendering them on the client and they appear laggy, this is either a performance issue on your behalf or the bottleneck to physically simulated projectiles, the client’s machine, stepping in. That’s where your question becomes valid, which then I recommend looking to the RunService for it’s functions that allow you to run code per frame.
As far as RunService goes, I recommend any of the functions that allow you to get the delta time between each frame, wherein you can calculate a position using that value as an offset. A code example is available right on the RunService page itself.
All you need here is to use the delta time. It is the time elapsed since the last frame.
How would you implement this ideology into your code?
My method to making projectiles was to fire a event to the server that tells all of the clients to make a Visual bullet that does nothing other than destroying / doing effects whenever it’s hit something, however that’s not the case with the Client who fired the Projectile, instead the Client checks if the projectile hits something, if it did a Remote Event is fired to the server to validate if the hit detection if legit or not, if it is Damage is applied to the opposing player. I am also using Body Velocities for Projectiles. So basically what I’m saying is depending on all of the client’s FPS, the Bullet can be laggy and slow. I’m sure many people have seen laggy stuff sizing or laggy stuff moving due to FPS.
Well it’s simple math and logic. https://youtu.be/c4b9lCfSDQM
If you have a number that tells you how many seconds it’s been since the last frame, you can calculate the appropriate increments.
Let’s say you have a projectile going straight.
It’s velocity is (1,0,0). For every frame you would add velocity*DeltaT to the position.
How do I get the DeltaT though, I’m pretty confused.
DeltaT is passed to a function of RunService or what gets returned if you call RunService.FrameMethod:Wait(). You’ll have to check the functions parameters for the latter in case you use the wrong one or need the other return values.