Page 1 of 1

Make speed constant no matter the FPS

Posted: Wed Dec 20, 2017 10:33 pm
by HolyMolly
In most languages/engines/frameworks, I could just write the movement code like this:

x = x + (speed * dt)

And it would work fine. But in Love2D, the dt changes nothing. If it's at 60FPS, it will move at a certain speed. If it's 20FPS, it will be much slower. What can I do?

Re: Make speed constant no matter the FPS

Posted: Wed Dec 20, 2017 11:12 pm
by Nixola
You could show us some actual code, or even better upload a working .love file that showcases your issue; the snippet itself looks fine.

Re: Make speed constant no matter the FPS

Posted: Thu Dec 21, 2017 12:15 am
by zorg
if you put dt as a parameter into the love.update callback (or whatever function you put that code in, while passing love.update's dt into it) it should work. As Nixola said, post a bit more code.

Re: Make speed constant no matter the FPS

Posted: Mon Dec 25, 2017 6:05 pm
by Jasoco
In my experience, dt has always worked as it should. As was said, provide an example that gives us the result you're seeing and we'll tell you if anything is wrong.

Also maybe your system specs.

Re: Make speed constant no matter the FPS

Posted: Tue Dec 26, 2017 12:48 pm
by SirRanjid
My guess would be you're using the dt of the update function inside the draw.

Re: Make speed constant no matter the FPS

Posted: Wed Dec 27, 2017 5:51 pm
by Jasoco
As has been mentioned, as long as you pass dt into every function you place in update that has anything to do with movement or speed or whatever, it should work fine. And don't try to use it in love.draw as it won't work, but you can make it work if you absolutely have to by either calling love.timer.getDelta() manually or rewriting love.run to pass dt into love.draw as well and treating it the same. If you have to.