Godot Version
4.3
Question
Since nobody was able to help me in my last topic I trying to dig deeper to understand source of my issues. So I want to understand what sync_to_physics
does. Not what it is meant to be used for, but what it really does under the hood. I tried to read the source code but it was hard to get anything out of it without any context.
Docs says this about sync_to_physics
:
If true, the body’s movement will be synchronized to the physics frame. This is useful when animating movement via AnimationPlayer, for example on moving platforms.
So what I can get from this and some testing is that it magically “fixes” moving platforms. But it does not really explain how it achieve it. And moreover it does it at great cost of making platform be delayed by a frame leading to some other potential issues.
Here’s my origin issue for more context: AnimatableBody2D moved by RemoteTransform2D out of sync - #2 by Wajsia
Well, this is kinda an explanation:
If true, the body’s movement will be synchronized to the physics frame.
So I want to understand what this sentence really means. Because I don’t.
How anything can be not “synchronized to the physics frame” at first place if my game is single-threaded? My current understanding is that in single-threaded games with both - FPS and physics ticks per second set to be equal 60, the main game loop should be more or less equivalent to this:
while (true) {
_physics_process(delta)
// Not relevant for games without Rigid Bodies
// _integrate_forces()
// _PhysicsEngine2D.run_tick()
_process(delta)
render_frame()
}
So where is the place for anything being out of sync and what sync_to_physics
changes in the way how AnimatableBody2D
works in this loop? How is that that sync_to_physics
make body delayed but also make it work at all in such a straightforward game loop? I does something very important because without it a player character can even easily penetrate through platforms which is not the case when sync_to_physics
is set to true
.
I feel like I’m missing something very fundamental.
I find it a drawback of Godot that the docs quite often don’t go into to much details and just tells you for what you are supposed to use something instead of explaining what it actually does. It makes it a little less friendly for advanced usage.
There’s also this in docs:
Do not use together with PhysicsBody2D.move_and_collide.
Would be nice to say few works why. Does this rule still apply if you use move_and_collide
with test_only=true
?