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

Smoothing a smoothed camera can cause jitter #15

Open
Erfa opened this issue Oct 25, 2021 · 2 comments
Open

Smoothing a smoothed camera can cause jitter #15

Erfa opened this issue Oct 25, 2021 · 2 comments

Comments

@Erfa
Copy link

Erfa commented Oct 25, 2021

I have the following setup, a Sprite wrapped in a Smoothing2D that targets a KinematicBody2D. I also have a Camera2D with smoothing enabled, that follows the character. It is a child of the Sprite. This all works fine.

But I noticed issues when you also want to have something that follows the Camera2D rather than the player. In my case I wanted to have a Light2D right in the center of the screen, so I first tried setting this as a child of the Camera2D. Turns out the Camera2D doesn't actually update its position during smoothing, but I managed to work around that by attaching a script to my Light2D that compensates with the actual camera position that you can get in get_camera_screen_center().

This seems to work, but I noticed that the when the character quickly changes movement direction, the light seems to lag behind one frame. Here's a video of it in action

double_smooth.mp4

I figured the reason is probably that my script on the Light2D was updating before the camera smoothing and therefore using the old position, so I increased the process priority to ensure that it happened after, but nothing happened. It wasn't until I tried setting it to a ridiculously high value of 100 where suddenly - the issue was gone.

Turns out the reason is this line, which sets the process priority to an arbitrarily high value of 100, just like I did:

set_process_priority(100)

I'm not sure if there's a good fix for this. In my case, I realized that a better solution is probably to just place the Camera2D under the KinematicBody2D instead. It means that the camera smoothing will be completely separate from my character smoothing, but in my case that looks pretty good, maybe even better. And the Light2D follows at the center of the screen as expected.

Hopefully just by reporting this, someone might find this issue and be able to find a solution faster than I did. I have also attached a minimal project to test this.

camera2d-smoothing-demo.zip

@lawnjelly
Copy link
Owner

Yeah processing order is something you have to be aware of in general in Godot in these situations (regardless of using the addon), and especially with interactions with Cameras.

You may be getting feedback as a result of trying to place the Light2D as a child of the Camera2D. Another option to try is placing the Light2D on a separate branch of the scene tree rather than making it a child of the Camera2D. This feedback is the reason why the smoothing addon uses this separate approach.

I tried this and this seems to solve your problem too:

ErfaCameraSmoothingIssue.zip

@andrejp88
Copy link

Thank you for the tip about process priority. I have been dealing with a similar problem, although in my case the Camera itself was lagging slightly behind its parent Smoothing node. I ended up needing to do two things to fix the problem: one was to set the process priority as you mentioned, and the other was to call force_update_scroll() in the camera's _process callback. Not really sure why that one is necessary but only after doing both did the camera's center line up perfectly with the Sprite's center (which is under the same Smoothing2D node).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants