Skip to content

Add object position interpolation between physics frames #671

Description

@AndreaCatania

Describe the problem or limitation you are having in your project:
Usually the rendering is much faster than the physics frames and 144hz monitors are cheap enough to be a standard device for gaming PCs nowadays.

In Godot, the physics updates the position of almost anything, usually at fixed rate of 60Hz, this mean that no matter how faster your machine is to process a frame the object rendered will change at fixed rate of 60 frame per seconds.

In other words, even with high frame rate, the new rendered frame will be the same of the previous until the next physics frame change object positions (computation waste).

The result is that high frame rate monitors are useless and the rendering is not fluid as you would expect.

However, you may want to lower the physics frame rate from 60 to 30, because your game doesn't need such precision and so to unload the CPU; doing so you will notice that the game is not fluid and you are forced to keep using 60 frames per seconds.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
This limitation can be solved by integrating the position interpolation between the frames.

We know that the physics produces a new position at a rate of 60 frames per second and between those frames the renderer produces other three identical frames. The idea is to interpolate between the old position produced by the physics engine and the new so that the intermediate frames are different each other. The problem with such approach is that we need to know the rendering speed beforehand and since this is not always stable we need a way to determine it.

The idea is to count the amount of intermediate rendering frames between the old physics update and the current one, and spread the interpolation delta between those; so even during the phases where the frame rate is not perfectly stable we are able to interpolate the position in a plausible manner.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

Interpolation

Without interpolation

Interpolation_2

With interpolation

Interpolation_3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions