Ball sometimes flies across the screen inhumanly fast
joebobmiles opened this issue · 1 comments
joebobmiles commented
I'm sure this is something to do with applying force to the ball during game load. Requires research and/or the intervention of someone more knowledgeable at LÖVE than I.
joebobmiles commented
Well, turns out that the ball speed has everything to do with the dt
passed to world:update()
. The hack in place right now is to just set the dt
for the first world:update()
call to approximately the average dt
for the subsequent calls.
Why it works
The reason this works is because, from what I can discern, Box2D (or LÖVE) uses thedt
to compute the new position of the ball. Because we're using applyForce()
to set the ball in motion (instead of the admittedly more sensible usage of setLinearVelocity()
), and the initial dt
can vary between very big and very small (depending on how long LÖVE takes to load), the force is applied either over a very small amount of time or a very long amount of time. This equates to small dt
s leading to slow balls and long dt
s leading to very, very fast balls.