when I move my camera2D using a tween, its children lag behind
Asked Answered
D

5

0

I'm developing a minigame with Godot 4.0.3 where I move the camera2D using a tween:

var tween = get_tree().create_tween()
	tween.tween_property(_camera, "position", Vector2(0,-60), 0.2).as_relative().set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_OUT)

The camera2D is the parent of the UI nodes, so the UI should move with the camera. However, when I play this tween, the camera movement leaves the UI behind for a moment, and I don't know why.

I have tested the idea puting the UI as the children of another node and applying this tween to that node, and doing that the UI moves with it's parent like it should. So I don't know why the camera acts different. I checked that the process callback is set on iddle, as the tween and everything else, so it should be syncronized but that's not the case for some reason.

Can you guess what could be causing this? Thanks for reading!

Dessiatine answered 1/6, 2023 at 22:40 Comment(0)
D
0

Aristotelianism It's disabled.

The problem I have seems to be this bug: https://github.com/godotengine/godot/issues/74203

There is a workarround using force_update_scroll() but it only solves the issue with lerping, not with tweens.
Edit: using force_update_scroll() works if the tween is over a method instead of a property as explained in the github comments.

Dessiatine answered 3/6, 2023 at 22:11 Comment(0)
A
0

You shouldn't place children on the camera. You can use a CanvasLayer if you need a static UI.

Aristotelianism answered 1/6, 2023 at 22:45 Comment(0)
D
0

Aristotelianism Yeah that sounds like a better approach. But I don't understand why this worked on Godot 3.5 but not in G4. Maybe a bug?

Dessiatine answered 2/6, 2023 at 7:17 Comment(0)
D
0

Aristotelianism I tried your solution. Moved the UI to a CanvasLayer outside of the camera node and now the tween moves a Node that has the camera2D and a sprite2D as its children, but the problem is the same. The movement keeps being out of sync. The camera moves slightly but clearly later than the sprite.

I notice I made this post at a bad hour and dind't get much attention. It's okay to post it again at a better hour?

Dessiatine answered 3/6, 2023 at 16:55 Comment(0)
A
0

The camera has a smoothing option. Maybe try that instead. There may be some interference.

Aristotelianism answered 3/6, 2023 at 17:10 Comment(0)
D
0

Aristotelianism It's disabled.

The problem I have seems to be this bug: https://github.com/godotengine/godot/issues/74203

There is a workarround using force_update_scroll() but it only solves the issue with lerping, not with tweens.
Edit: using force_update_scroll() works if the tween is over a method instead of a property as explained in the github comments.

Dessiatine answered 3/6, 2023 at 22:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.