You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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:
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).
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:
smoothing-addon/addons/smoothing/smoothing_2d.gd
Line 83 in be07d49
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
The text was updated successfully, but these errors were encountered: