How do I make my HUD track with a moving Camera2D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Solid_Turner

I’ve been pulling my hair out and searching everywhere to try to figure this out, and I just can’t find what I’m looking for.

I’m finally getting the hang of control nodes in Godot, but I cannot figure out how to make them track with my moving Camera2D. I have a separate scene for my HUD, whose root node is just a simple control, and then all the HUD elements are set up inside of it. The root control is set to “Full Rect” in layout. This works out fine when I run the HUD scene by itself - it resizes perfectly with the game window.

I have a separate “game” scene, whose root is just a Node, and the hierarchy looks like this:

> Player

The camera is a child of the player because I would like it to track the player’s movement. I cannot for the life of me figure out where to put my HUD scene in this hierarchy so that it adjusts to the viewport that the camera displays on. No matter where I put it, it might as well just be a bunch of sprites I placed in the scene.

:bust_in_silhouette: Reply From: timothybrentwood

Create a CanvasLayer node as a child to your Node node and add your HUD as a child to that. The CanvasLayer node should follow the camera around on screen.

Awesome, thank you so much. I knew I was just missing something simple.

Solid_Turner | 2021-05-05 13:34

I registered just to tell you that you are a hero. I don´t care how old this post is, I just learned something important.

TrueChampignon | 2022-04-20 18:15