Can't make UI "stick" to the screen when using position smoothing on camera

godot-4

Hey everyone, I’m new here, just starting using Godot (absolutely love it).
I’m making a mobile tycoon game. The main game area is a long horizontal rectangle divided into screens I’m making the camera snap to. I wrote a simple script to detect horizontal swipes and move to the next screen accordingly by simply changing the position.x attribute of the Camera2D node. The script itself works perfectly. I’m of course using position smoothing to not make it look horrible.
The problem arises when I attach UI to the Camera2D node as a child. With position smoothing on the UI “teleports” to the final position, while the camera lags behind due to the smoothing. I’d like for the UI to stay glued to the screen during motion. Should I not use Camera2D as a parent for the UI?
I’m assuming this is due to position smoothing not being “real” movement as far as the engine is concerned. Is there an easy way to get what I want or should I just rewrite the code making the camera actually move instead of just jumping to position.x and then smoothing it?

Should I not use Camera2D as a parent for the UI?

Bingo, you want UI to be not a child of node2d but instead a child of a Control, viewport or separate canvas item I think.

Check out the UI demos they might show you how to set things up godot-demo-projects/gui at master · godotengine/godot-demo-projects · GitHub

Also read up on canvaslayers CanvasLayer — Godot Engine (stable) documentation in English

2 Likes

Awesome, thanks for your help!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.