Skip to content

Smoothing a smoothed camera can cause jitter #15

Description

@Erfa

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions