Make speed constant no matter the FPS

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
HolyMolly
Prole
Posts: 1
Joined: Wed Dec 20, 2017 10:28 pm

Make speed constant no matter the FPS

Post by HolyMolly » Wed Dec 20, 2017 10:33 pm

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?

User avatar
Nixola
Inner party member
Posts: 1918
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Make speed constant no matter the FPS

Post by Nixola » Wed Dec 20, 2017 11:12 pm

You could show us some actual code, or even better upload a working .love file that showcases your issue; the snippet itself looks fine.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

User avatar
zorg
Party member
Posts: 2284
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Make speed constant no matter the FPS

Post by zorg » Thu Dec 21, 2017 12:15 am

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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

User avatar
Jasoco
Inner party member
Posts: 3619
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Make speed constant no matter the FPS

Post by Jasoco » Mon Dec 25, 2017 6:05 pm

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.

User avatar
SirRanjid
Prole
Posts: 28
Joined: Sun Nov 19, 2017 1:44 pm
Contact:

Re: Make speed constant no matter the FPS

Post by SirRanjid » Tue Dec 26, 2017 12:48 pm

My guess would be you're using the dt of the update function inside the draw.

User avatar
Jasoco
Inner party member
Posts: 3619
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Make speed constant no matter the FPS

Post by Jasoco » Wed Dec 27, 2017 5:51 pm

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.

Post Reply

Who is online

Users browsing this forum: pgimeno and 8 guests