How to make the Health bar (ProgressBar) be visible on the First-person viewport?

TudorTudor Posts: 40Member
edited September 1 in 3D

Hello! I want to make a Health bar (ProgressBar node) to be visible on the First-person viewport, like in the image below (I drew the healthbar on the screenshot):

It would also be good if this health bar would be visible only for the player.

In order to bring the health bar in the 3d scene, I tried the following steps:

  • I created the hierarchy: Sprite3D -> Viewport -> ProgressBar
  • I made the Viewport size to be similar to the Progress bar size.
  • I attached a script at the Sprite3D node, with the following code:

    extends Sprite3D

    func _ready():
    texture = $Viewport.get_texture()

But, no progress bar appears in the scene.

How should I do this?

Best Answers

  • MegalomaniakMegalomaniak Posts: 2,898
    Accepted Answer

    You don't need the Sprite 3D, also instead have the progress par and the rest of the hud in a canvaslayer instead of the viewport. Just use the 2D nodes like you normally would, they should get drawn over the 3D viewport as a 2D layer just fine.

  • TudorTudor Posts: 40
    Accepted Answer

    Actually, I see the Health bar, but only when I run the game.

    I don't know if this is the optimal, but it is definetely the desired result. :)

    Thank you very much!

Answers

  • MegalomaniakMegalomaniak Posts: 2,898Admin
    Accepted Answer

    You don't need the Sprite 3D, also instead have the progress par and the rest of the hud in a canvaslayer instead of the viewport. Just use the 2D nodes like you normally would, they should get drawn over the 3D viewport as a 2D layer just fine.

  • TudorTudor Posts: 40Member

    I tried the next hierarchy, which I made the child of the Camera node:
    CanvasLayer -> ProgressBar

    And it didn't work:

    I also tried to make the hierarchy the child of other 3D nodes, and still it didn't work.

    This is the ProgressBar that should appear in 3D:

  • TudorTudor Posts: 40Member
    Accepted Answer

    Actually, I see the Health bar, but only when I run the game.

    I don't know if this is the optimal, but it is definetely the desired result. :)

    Thank you very much!

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file