function love.update(dt)
[...]
if love.keyboard.isDown("w") then
dTotal = dTotal + dt
meow.y = meow.y - (meow.gravity *25* dt)
if (meow.gravity > 2.1) then meow.gravity = meow.gravity - 0.8 end
if (meow.gravity < 2) then meow.gravity = 1 end
end
[...]
end
where meow.y is the Y value of the sprite and meow.gravity is initially 50.
However, if I have multiple windows or something going on in the background, my character jumps a LOT higher that its supposed to. I read the wiki and it seems like dt is just the amount of time from the previous frame update, so how should I program this jump so that it lasts for the same amount of time on all machines?
dt is the most common shorthand for delta-time, which is usually passed through love.update to represent the amount of time which has passed since it was last called. It is in seconds, but because of the speed of modern processors is usually smaller than 1 (values like 0.01 are common).
Maybe you should just hard-code it?
Edit: or put some boundaries on it, so if dt is different from what is expected, your game would use fixed value?
if love.keyboard.isDown("w") then
dTotal = dTotal + dt
meow.y = meow.y - (meow.gravity *25* dt)
if (meow.gravity > 2.1) then
meow.gravity = meow.gravity - 0.8 * 60 * dt
end
if (meow.gravity < 2) then
meow.gravity = 1
end
end
This makes the behavior almost independent from dt and should be enough for your purposes. If you need an even higher accuracy, then have a look at higher order integration scheme, for example here.
And a small side-note: What you call gravity in your code, is in fact velocity. I suggest you rename all occurrences of "gravity" to "velocity". The number you subtract from velocity (here 0.8) is gravity.