Questionable stutter after fixed time step + interpolation - LibGDX

The game I’m working on has an entity that moves on a 2D plane with a parallax background. I’ve been following this thread in order to implement fixed time step and interpolation into my game, where my implementation closely mirrors the OP’s version: http://www.java-gaming.org/index.php?topic=24220.0

I’m using lwjgl3, full screen mode, updating entities at 60 Hz, rendering at 60 Hz, vsync is true.

It has been a success so far and I have applied interpolation to my main player entity as well as my background – I have very smooth movement. Now my problem is that everything else such as stationary objects that do not have their positions change(only relative to the camera) seem to stutter every now and then. My player and parallax backgrounds don’t stutter and I don’t have a drop in fps, however entities that don’t have interpolation applied to them look like they skip a few frames sometimes, even though they’re not changing x/y positions. With that being said, time for some silly questions:

  • Is there a way to apply interpolation to stationary entities in order to smooth movement out while my camera is panning?

  • Is it advised to update and render at the same frequency? Do people typically leave vsync on?

Not sure if it’s exactly the same, but when I added interpolation I noticed the same thing.

For me, the solution was to make sure to update and draw the interpolated frame, and the stutter stopped. Hope it’s that easy for your case.

Could you give me an example of what you mean?

If we have a generic fixed time step with interpolation setup(world/render), when we’re passing in the interpolation value into our render method, shouldn’t we already be expecting it to draw the interpolated frame? Right now I’m applying interpolation to my character in which a camera is fixed on, my parallax background, projectile entities, and basically anything else that moves.

I’m a little confused on what happens to the stationary entities. When I see these small spikes, it’s only the stationary entities that jump a little bit. Apply interpolation to moving entities makes sense since you can apply interpolation to their position using a previous position and current position. Stationary entities always have the same x/y positions though :persecutioncomplex:

This almost have have something to do with the interpolation, because it happens every ~5 seconds.

I wouldn’t interpolate if I’m going to update at 60 fps AND draw at the same frequency. For my games I settle around 25 to 30 fps to update and shoot for the magical 60fps rendering.

Are you interpolating the camera position?

I’ve identified that using fixed time + interpolation makes stationary entities jump every 5 seconds. If I take out fixed time and interpolation, my game runs fine. I’m not entirely sure but I think what I’m experiencing is called temporal aliasing.

@ndnwarrior15 - Good point! Looking through the articles you sent me in my other post, they typically use 30/60 for their updates. Regardless even if I update at 30 and draw at 60, I still get that same stutter every 5 seconds. To answer you second question, in my draw method I calculated the players interpolated position first:


drawX = ((player.getPosition().x - player.getLastX()) * interpolation + player.getLastX() - player.getWidth() / 2f);
drawY = ((player.getPosition().y - player.getLastY()) * interpolation + player.getLastY() - player.getHeight() / 2f);

I use drawX/Y to render my player, as well as the parallax background. I apply the same drawX/Y to the camera position:


orthocamera.position.set(drawX, drawY, 0);
orthocamera.update();

If it’s running fine by getting rid of the fixed time step plus interpolation seems to me there’s something wrong with the implementation/structure of interpolating or the math. Maybe both.

I guess it boils down to choosing to try and fix or continue onwards without the fixed time step.

What ended up happening was I gave up on the issue and moved on, hoping it was specific to my hardware. I started implementing other features and eventually found out that I was interpolating incorrectly. The crucial step boiled down to how I was storing my players previous position.

I noticed that my players previous position was always my current position, so basically my order of operations are incorrect. After I fixed that and correctly stored my players previous position, I used that correct data as part of interpolating my players coordinates, and everything was fixed.

Niiiiice!

Glad you figured it out, when my game stuttered it always freaked me out.