extends Control @onready var sub_viewport: SubViewport = $".." @onready var health_bar_sprite: Sprite3D = $"../.." var center = Vector2.ZERO var current_health : float const MARGIN = 20 func _ready() -> void: center = Vector2(sub_viewport.size.x/2,sub_viewport.size.y/2) func _draw() -> void: var health_percentage : float = health_bar_sprite.character.health/health_bar_sprite.character.start_health #draw background draw_line(Vector2(0,center.y),Vector2(sub_viewport.size.x,center.y),Color(.5,.5,.5,.75),MARGIN * 2,true) #health for i in range(health_bar_sprite.character.health): var width = sub_viewport.size.x / health_bar_sprite.character.start_health var from = width * i + MARGIN/2 var to = width * (i+1) - MARGIN/2 draw_line(Vector2(from,center.y),Vector2(to,center.y),ColorSwatch.RED_COLOR,30,true)