Physics max velocity tied to framerate

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Bobble68
Party member
Posts: 156
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Physics max velocity tied to framerate

Post 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.
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: Physics max velocity tied to framerate

Post 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
User avatar
Bobble68
Party member
Posts: 156
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Physics max velocity tied to framerate

Post 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?
Last edited by Bobble68 on Wed Nov 30, 2022 11:44 pm, edited 1 time in total.
Dragon
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Physics max velocity tied to framerate

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 47 guests