My guess is that the battery bar is a TextureProgress node, and then it is controlled using code like this (not tested):
var battery_power = 100
const POWER_DRAIN_SPEED = 4
func _process(delta):
batter_power -= delta * POWER_DRAIN_SPEED
$TextureProgress.value = batter_power
I’ve done similar techniques for resource bars before in the past, and it worked pretty well. Later I can see if I can find an old project and extract the code I used.
For recharging, you just need to add to the batter_power
variable when colliding with a battery. For example, in the battery node, you could have a function like this (not tested):
func _ready():
get_node(“Area2D”).connect(“on_body_entered”, self, “on_body_entered_battery”)
func on_body_entered_battery(body):
if (body.name == “Player”):
body.battery_power += 100
# Optional - clamp battery power to a max value
if (body.battery_power > 100):
body.battery_power = 100
# Remove the battery node since it has been collected
queue_free()