Page 1 of 1

Physics max velocity tied to framerate

Posted: Wed Nov 30, 2022 9:31 pm
by Bobble68
Hi there!

I've been making a game with some flight simulation in it, and I decided to use love's inbuilt physics engine. However, I noticed some weird behaviour in my game. Occasionally, it would just slow you down randomly, as well as there being a max velocity.

I had a hunch, so I added a sleep into the update function, and sure enough, the maximum velocity was significantly reduced.

It seems weird to me that max speed should be tied to framerate, so does anyone know if there's a way to satisfyingly fix this? I did find online that changing the meter sort of changed the max speed, but this feels like something that there should be a simple solution to.

Re: Physics max velocity tied to framerate

Posted: Wed Nov 30, 2022 11:16 pm
by GVovkiv
If i understand it correct, physics tied to framerate so it will be easy to debug it.
From box2d manual https://box2d.org/documentation/md__d_1 ... totoc_md24
A variable time step produces variable results, which makes it difficult to debug. So don't tie the time step to your frame rate (unless you really, really have to). Without further ado, here is the time step.
You probably can pass dt to physics, but i'm not sure if it will be good idea

Re: Physics max velocity tied to framerate

Posted: Wed Nov 30, 2022 11:34 pm
by Bobble68
Ideally I'd like a way to bypass the max speed altogether, though I'm starting to think that may not be possible.

This is my first time using love's physics, so I based the code off of the tutorial for it. How would I go about untying it from the framerate?

Re: Physics max velocity tied to framerate

Posted: Wed Nov 30, 2022 11:43 pm
by MrFariator
The default love.run will basically call love.update as often it can (well, to a degree). This will affect your physics simulation, particularly if the delta time between update ticks is not stable. Like how GVovkiv posted, box2d instead expects a fixed tick rate for physics steps - and this is where we get to fixed timesteps. Here's an article that gets posted every so often on these forums on this topic. It's not the only way to handle the issue with variable delta times, but basically you want to find a way to update your physics in a stable manner.