Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Questionable stutter after fixed time step + interpolation - LibGDX  (Read 1043 times)
0 Members and 1 Guest are viewing this topic.
Offline VoidBuffer

Junior Devvie


Medals: 4
Exp: 2 years



« Posted 2016-12-15 06:02:49 »

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?

Offline bmanmcfly
« Reply #1 - Posted 2016-12-15 15:51:21 »

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.
Offline VoidBuffer

Junior Devvie


Medals: 4
Exp: 2 years



« Reply #2 - Posted 2016-12-15 17:28:47 »

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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline VoidBuffer

Junior Devvie


Medals: 4
Exp: 2 years



« Reply #3 - Posted 2016-12-16 02:31:25 »

This almost have have something to do with the interpolation, because it happens every ~5 seconds.
Offline ndnwarrior15
« Reply #4 - Posted 2016-12-16 02:58:31 »

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?

Offline VoidBuffer

Junior Devvie


Medals: 4
Exp: 2 years



« Reply #5 - Posted 2016-12-16 05:41:23 »

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:

1  
2  
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:

1  
2  
orthocamera.position.set(drawX, drawY, 0);
orthocamera.update();
Offline ndnwarrior15
« Reply #6 - Posted 2016-12-16 19:51:32 »

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.

Offline VoidBuffer

Junior Devvie


Medals: 4
Exp: 2 years



« Reply #7 - Posted 2016-12-24 20:45:03 »

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.
Offline ndnwarrior15
« Reply #8 - Posted 2016-12-26 18:33:56 »

Niiiiice!

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

Pages: [1]
  ignore  |  Print  
 
 

 
numerical (74 views)
2017-02-21 07:32:16

numerical (75 views)
2017-02-21 07:31:46

theagentd (180 views)
2017-02-18 13:42:33

theagentd (182 views)
2017-02-18 13:35:16

h.pernpeintner (1345 views)
2017-01-24 22:39:11

h.pernpeintner (1333 views)
2017-01-24 22:38:32

Galdo (1894 views)
2017-01-12 13:44:09

Archive (1983 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2519 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2310 views)
2016-12-15 21:50:57
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!