Physics framerate VS graphics framerate

So the physics engine runs at a specific speed (60 fps i think, by default), while the graphics run as fast as they can.



My problem is that I have the camera attached to a physics controller, and other things in the game are happening every time the game renders a frame. This is really messy, and it also makes for wierd artifacts. Things seem to jitter, because the camera position will get updated 60 times a second, and ~3 frames will get rendered during that time, during which some objects will move across that frame. It’s noticable when the camera object is chasing another object, for example.



I tried adding a physics pre-tick listener, and moving my “update entities” loop into it, but then i get errors for editting the scene while it’s rendering.



I could think of a lot of ways to go about fixing this, but I was wondering if there is a standard way of dealing with this problem, so I can do things “the jmonkey way”.

Yeah, turn on vsync.



If your monitor is only showing 60 FPS then there is no reason that the GPU should be rendering faster.



The alternative is to have the rendering frame interpolate between the known physics frames (and render one physics frame behind which is really more than fine) but I don’t think the built in physics controls are really setup for that.

I tried that, but I still get jittering. Is there a way to force the physics tick to happen in between frames, rather than asynchronously?

Rather, I tried the vsync settings.



What is the most sound way to approach this problem? I assume that it’s pretty common in any game that uses physics, right?

You misunderstand some things. The physics is stepped in the update loop. Actually each frame, to get interpolated values for the physics locations, its that th update only happens with 60fps, so only some frames do actualy alculatins apart from interpolation. The issue you have is most probably being caused by you enabling parallel phyiscs, which runs the phyiscs update in parallel to rendering (which means you should NOT manipulate spatials during the physics update). Set the execution to sequential if you don’t know how to circumvent the threading issues.