My animation will not play

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)

I noticed that the animation plays because the progress bar value changes when I print it, but the animation is not visible.

Is there any other code that will play an animation on the same AnimationPlayer that could be overriding the animation?

No, I only use that animation player in the script above

I found the issue, for some reason, even though the background of the bar is behind the bar animation in the editor, when I run it, it goes in front. I tried changing the z-index but that didn’t help, I guess I’ll just delete the background for now.

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