How to change pivot offset of progress bar?

Godot Version

<stable4.2>

Question

<I’m trying to set pivot of progress bar at the center of it and position it at marker 2d. However, progress bar is always positioned at top left. Right now, progress bar is a child of enemy node and is set as top level. anchor preset is set to custom and x value of pivot offset is set to 50 which makes it to position at the center of progress bar.

progress_bar.start = true
progress_bar.position = $Marker2D.global_position

what I want:

what I get:

progress bar setting:

show how you add_child the progress bar?
did you change the position before adding it as a child of the marker?

also since you are tying to add a control base type node (progress bar), it’s better to use container such as center container and add child the progress bar in it, not marker2d

I simply added under the characrterbody2d (enemy) by instantiating it. I did not change the position. only the pivot offset.

yes i need to see the code for this
i didnt mean to ask for where the progressbar be added, i meant in the script code, how the add_child being added/written

you can be doing something like

progress_bar.position=$Marker2D.global_position
add_child(progress_bar)

also i just noticed, you are trying to use marker2d’s global position as the position of progress_bar
should

progress_bar.global_position=$Marker2D.global_position

be a fix for you

スクリーンショット 2024-05-07 232930

grab_meter is the progress bar

so it’s pre instantiated-add_child progress bar…
so the

should be make it look right

grab_meter.global_position = $GrabMeterPoint.global_position

unfortunately this did not solve the problem, and it still positioned at top left

this is Local tab, right?

im sorry but what is local tab?

Local Tab is the current not during Runtime’s scene tree, the most basic one

Remote tab’s Scene tree is the scenes list of nodes the current running game is using

so it’s a local tab then, then why do you need to change the progress bar position from code? if you can set the progress bar position right now from editor scene

it is set as top level in order to avoid scale.x proble. like when enemy flip progress bar also flip which i dont want.

i just tested, the pivot of progressbar wont be used to move the progress bar pivot position. what you can do now is either one of these two:

  1. add the pivot from progress_bar
grab_meter.global_position = $GrabMeterPoint.global_position-grab_meter.pivot_offset
  1. actually make use of Control Container node to contain the progress bar in the center anytime, doesnt matter if it’s long or short:

the first option worked perfectly. Thank you very much for your help zdrmlpzdrmlp!!

1 Like

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