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

Fix Camera 2D position not updating correctly #63083

Merged
merged 3 commits into from
Jul 18, 2022

Conversation

madmiraal
Copy link
Contributor

Currently, SceneTree's initial physics_process_time and process_time are set to 1 second. So early calls to get_process_delta_time() or get_physics_process_delta_time() return unreasonably large values, which causes incorrect calculations. Most notably in Camera2D's initial position when smoothing is enabled:

if (smoothing_enabled && !Engine::get_singleton()->is_editor_hint()) {
real_t c = smoothing * (process_callback == CAMERA2D_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time());
smoothed_camera_pos = ((camera_pos - smoothed_camera_pos) * c) + smoothed_camera_pos;
ret_camera_pos = smoothed_camera_pos;

In addition, when a Camera2D's limits are updated, the camera's position is not updated. This is requiring users to unnecessarily, manually call the hidden _update_scroll() method.

This PR fixes both these issues by setting SceneTree's initial process times to 0 and calling _update_scroll() when setting limits. It also fixes scene_tree.h's clang formatting, required to make changes to scene_tree.h and a TestEdit test that depends on SceneTree's initial process times being arbitrarily greater than 0.

Fixes #56336
Fixes #56913

scene/main/scene_tree.h Outdated Show resolved Hide resolved
scene/main/scene_tree.h Outdated Show resolved Hide resolved
@akien-mga akien-mga merged commit 168ee3e into godotengine:master Jul 18, 2022
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment