godot icon indicating copy to clipboard operation
godot copied to clipboard

Physics 2D Interpolation does not work on Parallax2D.

Open TrieBr opened this issue 1 year ago • 1 comments

Tested versions

Godot v4.3.dev6.mono - macOS 14.4.1 - GLES3 (Compatibility) - Apple M2 Max - Apple M2 Max (12 Threads)

System information

Godot v4.3.dev6.mono - macOS 14.4.1 - GLES3 (Compatibility) - Apple M2 Max - Apple M2 Max (12 Threads)

Issue description

Spawned from https://github.com/godotengine/godot-proposals/issues/2753#issuecomment-2094912482.

Parallax2D object does not seem to support physics interpolation. ParallaxBackground and ParallaxLayers do work. With a small physics rate (like 15hz), Parallax 2D is visibly choppy and is not interpolation.

Steps to reproduce

  1. Set Physics Step to a low value like 15hz
  2. Add a Parallax2D and Sprite2D node to the root scene node.
  3. Add a 2D Camera which follows an object.
  4. Observe that the Parallax2D is not smooth.

Minimal repro here: https://github.com/TrieBr/GodotParallax2DInterpolation

Observe the differences between Parallax2D and ParallaxBackground/ParallaxLayer by toggling visibility on both and testing.

Minimal reproduction project (MRP)

Minimal repro here: https://github.com/TrieBr/GodotParallax2DInterpolation

TrieBr avatar May 06 '24 16:05 TrieBr

This is interesting! I've been playing with it a bit, and see that just like ParallaxLayer it doesn't move until enough distance has been covered, but rather than sliding forward to the new position, it jumps ahead and slides back to the new position.

markdibarry avatar May 06 '24 19:05 markdibarry

Here is the MRP ported to GDScript (i.e. more minimal): GodotParallax2DInterpolation.zip

I haven't found the source of the bug yet.

rburing avatar May 07 '24 08:05 rburing

@rburing I took your project and stripped down some of the odd settings and things not necessary to reproduce. Should be easier to debug, and the update is happening in the _camera_moved() method. I'm trying to find time to take a closer look on why it's sliding in reverse, but I've got a busy week at work, so looking in my spare time. Sorry! Let me know if you find something before I do. GodotParallax2DInterpolation.zip

markdibarry avatar May 07 '24 19:05 markdibarry

The bug is in Camera2D's _update_scroll here:

https://github.com/godotengine/godot/blob/17a81260cb92a321a0d752e369ef911055178c7b/scene/2d/camera_2d.cpp#L57-L71

Without interpolation, the value of camera_screen_center is current, as it was updated by get_camera_transform().

With interpolation, the value of camera_screen_center is stale, causing the issue.

(The whole get_camera_transform() having side-effects is pretty hacky.)

So minimally we need a way to re-calculate (the value of) camera_screen_center based on a given (interpolated) transform.

rburing avatar May 08 '24 09:05 rburing