Advanced physics interpolation
Even with physics interpolation active, there may be some local situations where you would benefit from disabling automatic interpolation for a (or branch of the SceneTree), and have the finer control of performing interpolation manually.
This is possible using the property which is present in all Nodes. If you for example, turn off interpolation for a Node, the children will recursively also be affected (as they default to inheriting the parent setting). This means you can easily disable interpolation for an entire subscene.
The most common situation where you may want to perform your own interpolation is Cameras.
Cameras
In many cases, a can use automatic interpolation just like any other node. However, for best results, especially at low physics tick rates, it is recommended that you take a manual approach to Camera interpolation.
This is because viewers are very sensitive to Camera movement. For instance, a Camera that realigns slightly every 1/10th of a second (at 10tps tick rate) will often be noticeable. You can get a much smoother result by moving the Camera each frame in , and following an interpolated target manually.
Manual Camera interpolation
Ensure the Camera is using global coordinate space
The very first step when performing manual Camera interpolation is to make sure the Camera transform is specified in global space rather than inheriting the transform of a moving parent. This is because feedback can occur between the movement of a parent node of a Camera and the movement of the Camera Node itself, which can mess up the interpolation.
There are two ways of doing this:
- Call and set this to
true
, which will make the Camera ignore the transform of its parent.
But there is a problem. If we use the traditional get_global_transform()
on a Camera “target” Node, this transform will only focus the Camera on the target at the current physics tick. This is not what we want, as the Camera will jump about on each physics tick as the target moves. Even though the Camera may be updated each frame, this does not help give smooth motion if the target is only changing each physics tick.
get_global_transform_interpolated()
What we really want to focus the Camera on, is not the position of the target on the physics tick, but the interpolated position, i.e. the position at which the target will be rendered.
We can do this using the Spatial.get_global_transform_interpolated function. This acts exactly like getting but it gives you the interpolated transform (during a _process()
call).
Important
should only be used once or twice for special cases such as Cameras. It should not be used all over the place in your code (both for performance reasons, and to give correct gameplay).
Note
Aside from exceptions like the Camera, in most cases, your game logic should be in _physics_process()
. In game logic you should be calling get_global_transform()
or , which will give the current physics transform (in global or local space respectively), which is usually what you will want for gameplay code.
Example manual Camera script
Here is an example of a simple fixed Camera which follows an interpolated target:
Mouse look is a very common way of controlling Cameras. But there is a problem. Unlike keyboard input which can be sampled periodically on the physics tick, mouse move events can come in continuously. The Camera will be expected to react and follow these mouse movements on the next frame, rather than waiting until the next physics tick.
Sometimes, especially with Cameras, you will want to use a combination of interpolation and non-interpolation:
A first person camera may position the camera at a player location (perhaps using Spatial.get_global_transform_interpolated), but control the Camera rotation from mouse look without interpolation.
A third person camera may similarly determine the look at (target location) of the camera using , but position the camera using mouse look without interpolation.
There are many permutations and variations of Camera types, but it should be clear that in many cases, disabling automatic physics interpolation and handling this yourself can give a better result.
Disabling interpolation on other nodes
Although Cameras are the most common example, there are a number of cases when you may wish other nodes to control their own interpolation, or be non-interpolated. Consider for example, a player in a top view game whose rotation is controlled by mouse look. Disabling physics rotation allows the player rotation to match the mouse in real-time.
MultiMeshes
Although most visual Nodes follow the single Node single visual instance paradigm, MultiMeshes can control several instances from the same Node. Therefore, they have some extra functions for controlling interpolation functionality on a per-instance basis. You should explore these functions if you are using interpolated MultiMeshes.
Full details are in the documentation.