I had a problem where my AI moved extreme at the first frame and then normal after that. I then figured out it was my delta. It's about 0.016 seconds (60 fps), but the first frame was about 19000 seconds, which is obviously impossible. Does anybody know what might be happening? Also the delta later on likes to oscillate from 0.01 to 0.03.
long time = Sys.getTime() * 1000 / Sys.getTimerResolution();
float delta = (time - lastFrame) / 1000f;
lastFrame = time;
return delta;
That's the delta code.
EDIT: Wow, you guys really like to take the fun out of composing a question with all your editing.
lastFrame
on your first frame? ifSys.getTime()
normally returns some large value andlastFrame
is initialized to0
then you'll have a large delta. Usually you need to ensurelastFrame
is initialized to the current time just before the start of your game loop. \$\endgroup\$ – Sean Middleditch Oct 24 '13 at 17:43