Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Physics 2D Interpolation does not work on Parallax2D. #91625

Open
TrieBr opened this issue May 6, 2024 · 4 comments · May be fixed by #91706
Open

Physics 2D Interpolation does not work on Parallax2D. #91625

TrieBr opened this issue May 6, 2024 · 4 comments · May be fixed by #91706

Comments

@TrieBr
Copy link

TrieBr commented May 6, 2024

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 godotengine/godot-proposals#2753 (comment).

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

@markdibarry
Copy link
Contributor

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.

@rburing
Copy link
Member

rburing commented May 7, 2024

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

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

@markdibarry
Copy link
Contributor

markdibarry commented May 7, 2024

@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

@rburing
Copy link
Member

rburing commented May 8, 2024

The bug is in Camera2D's _update_scroll here:

Transform2D xform;
if (is_physics_interpolated_and_enabled()) {
xform = _interpolation_data.xform_prev.interpolate_with(_interpolation_data.xform_curr, Engine::get_singleton()->get_physics_interpolation_fraction());
} else {
xform = get_camera_transform();
}
viewport->set_canvas_transform(xform);
Size2 screen_size = _get_camera_screen_size();
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5) : Point2());
Point2 adj_screen_pos = camera_screen_center - (screen_size * 0.5);
// TODO: Remove xform and screen_offset when ParallaxBackground/ParallaxLayer is removed.
get_tree()->call_group(group_name, SNAME("_camera_moved"), xform, screen_offset, adj_screen_pos);

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 rburing linked a pull request May 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants