Frame skipping issue when using dt
Posted: Mon Apr 28, 2014 4:08 am
I finished my Ludum Dare submission tonight and posted it without realizing there was a nasty bug in the code.
https://www.dropbox.com/s/qh9gq8b4kc4n63h/ld29.love
The code is pretty messy but the problem lies in charge.lua
Essentially I'm throwing bombs up into the air, and they fall into the water. When they hit hte water their vertical velocity should decrease. That last line accomplishes that but I forgot to adjust it for deltatime. On my machine 0.96 is perfect. When adjusting it for delta time I got up around 200 * dt instead of 0.96:
and that seems to be about the right speed, the problem is that now it doesn't fall at a constant speed. It speeds up when other bombs explode and I can't find any correlation no matter how hard I try. Is this a common problem? Is there a reason that as soon as I add delta time to the equation the movement speed becomes varied?
Thanks
https://www.dropbox.com/s/qh9gq8b4kc4n63h/ld29.love
The code is pretty messy but the problem lies in charge.lua
Code: Select all
function charge:update(dt)
self.x = self.x + self.xVel * self.direction * dt
self.y = self.y + self.yVel * dt
if self.xVel >= 0 then self.xVel = self.xVel - self.friction * dt end
self.yVel = self.yVel + self.gravity * dt
if self.y > waterSurface then self.yVel = self.yVel * 0.96 end
end
Code: Select all
if self.y > waterSurface then self.yVel = self.yVel * 200 * dt end
Thanks