Godot Version
4.4
Question
I’m trying to make a power bar for my golf game. When you left click, the power bar animation is supposed to play, but it won’t. When I call activate_power_bar(), it prints “e” but does not start the animation. The ready func is just there for testing and when I run it the ready func starts the animation just fine, but the activate_power_bar doesn’t. I know activate_power_bar works and I know the animation works so I don’t know why this is happening. The UI scene is an autoload if that changes anything.
#power bar script
extends CanvasLayer
func _ready() -> void:
$AnimationPlayer.play("power_bar_move")
func activate_power_bar():
print("e")
$AnimationPlayer.play("power_bar_move")
func pause_power_bar():
$AnimationPlayer.pause()
var power_multiplier = $power_bar/ProgressBar.value
$power_bar/bar_reset.start()
#ball script
extends RigidBody2D
var push_strength = 500
var rotation_speed = 3
var power_bar_active = false
func _physics_process(delta: float) -> void:
look_at(get_global_mouse_position())
if rotation_degrees <= -50:
angular_velocity = rotation_speed
elif rotation_degrees >= 0:
angular_velocity = -rotation_speed
if Input.is_action_just_pressed("Left_click"):
if power_bar_active == false:
power_bar_active = true
Ui.activate_power_bar()
else:
var push_direction = Vector2.RIGHT.rotated(rotation)
apply_force(push_direction * push_strength)