So I decided to try my hand at making a simple air hockey game that implements the last game loop described in the dewitters article here: http://dewitters.koonsolo.com/gameloop.html (The loop titled Constant Game Speed independent of Variable FPS). However my results were disappointing because my game runs at different speeds on different computers and sometimes on the same computer, despite my update method seemingly running 25 times per second consistently (maybe my method for checking this is wrong). Anyway, here is the code in question: https://gist.github.com/2997312 Please let me know if you have questions and thanks in advance for your help.

I call the checkCollisions() method on line 30 which is outside of the update method and update loop. This method checks for collisions between either of the two paddles and the puck. I did this because, in the update method, the puck would just move through the paddle and the collision wouldn't be detected. Would checkCollisions() cause the speed variation?

What you do want, however, is keeping all your logic in your update method. Moving any logic outside it, effectively coupling it to the framerate, will make your game non-deterministic, and might result in the problems you're having, but again, I don't know.

If the puck has varying speed when not colliding with anything, then you probably have (even more) logic in your render method.

Hi, appreciate more people! Σ ♥ = ¾Learn how to award medals... and work your way up the social rankings!

Well, if your physics are not accurate enough at 25Hz, why don't you increase the update-rate to 50 or maybe even 100?

If you really want low tick-rates and high velocity collisions, you need more advanced physics-calculations, like working with swept circles, or calculating (either projecting or backtracking) where exactly the collision occurs, bounce right there, and advance movement from there.

Simplest solution really would be to ramp up the update-rate drastically.

Hi, appreciate more people! Σ ♥ = ¾Learn how to award medals... and work your way up the social rankings!

So i fixed the string object issue, moved all of the logic to the update method and changed the updates per second to 100. That solved the collision issues I was having, but I still experience game speed slowdowns and speed-ups. Could it be my interpolate methods? I'm not sure I handled them right. Here is the code for the puck's interpolation: https://gist.github.com/3012973 I handled the other rendered objects in a similar manner. Thanks to Riven and tberthel for your help so far.

I was under the impression that the interpolation value (in the case of a game loop) was the ratio between the set time between each update (in the case of 25 updates per second each update should take 40ms) and the actual amount of time that has passed. In other words if each update should take 40ms and it has been 20ms since the last update, then your interpolation value would be 0.5. Is that incorrect?

I was under the impression that the interpolation value (in the case of a game loop) was the ratio between the set time between each update (in the case of 25 updates per second each update should take 40ms) and the actual amount of time that has passed. In other words if each update should take 40ms and it has been 20ms since the last update, then your interpolation value would be 0.5. Is that incorrect?

that is correct, but if you call pick.interpolate(0.5f) three times, it should set all fields to the same values each time.

Well my render method is only called once. I call three different interpolate methods for the three objects that move on screen. Each of these methods is similar to the one i posted earlier and calculate the new position of the object based on the interpolation value. Then the render method is called and everything is rendered at the interpolated location. Is this incorrect? I can see how the interpolate methods could cause slowdown...can they be placed in the update loop? I don't see how that would work.

I gave you the example of calling interpolate 3 times, on the same object. Whether or not you do that is irrelevant, and that there are 3 moving objects in your case is pure coincidence. I'm just describing how your interpolate code should behave, when called multiple times with the same argument.

So how does one keep calculating the interpolation value consistently? It can't be run with the update method because the interpolation needs to be calculated between updates and right before each render. I'm sorry if I'm missing something here. I'm trying my best to wrap my head around this. My interpolation is calculated and applied outside of both my render method and update loop.

My interpolation is calculated and applied outside of both my render method and update loop.

Whether you run your 'interpolation code' inside the update or render method doesn't matter. You're calling it every time you are about to call your render method, so that means that that code is executed at render-time.

Hi, appreciate more people! Σ ♥ = ¾Learn how to award medals... and work your way up the social rankings!

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org