cak3_lover
cak3_lover

Reputation: 1928

Effects of increasing physics frame rate?

Initially when I was using _physics_process() to control my KinematicBody2D
I was getting some minute but noticeable (and really irritating) jittering so I increased the physics fps to 144:

enter image description here

and this fixed the jittering ( Finally inner peace! )

However my pc is fairly high end and my monitor being 144hz
but would the game work the same (or at all) on lower end pcs with lower frame rate monitors? like what would be the overall effect of increasing the fps?

Also is it possible to change this property during runtime so if the user does have a lower end pc they can adjust the fps in the game accordingly?

Upvotes: 1

Views: 1773

Answers (1)

Theraot
Theraot

Reputation: 40075

A high physics rate in a lower PC could mean wasted effort. Because a lot of the CPU time goes into motion that is not shown. And yes, that could be a performance problem for lower end PCs.


The recommended approach is to use Physics Interpolation which sadly Godot only has for 3D.

If you want to roll your own physics interpolation the idea is simple:

  • Move your graphic nodes in _process.
  • Move your physics nodes in _physics_process.

There two ways to do that:

  • Graphic nodes continue the physics motion (i.e keep their velocity). But this can lead to object visibly intersecting because they are moving without physics. And then you still have sudden motion when physics happens. Don't do this.
  • Graphic nodes interpolate the physics motion. Do this, it is in the name. But that means that motion has an slight delay of at most a physics frame.

As you know, we usually parent the graphic nodes to the physics nodes. If we want to move them independently we need to break that relationship. To do that you can use set_as_toplevel.


If you want to have control over the physics rate see Engine.iterations_per_second and Engine.target_fps. I have not experimented setting these in runtime.

And, of course, correct use of delta would be even more important. Consider if you need to use Verlet integration to apply accelerations.

Upvotes: 1

Related Questions