Animation does not play?

Godot 4.2.2

So I’m trying to make a FNAF game and I’m trying to make an attack animation but it doesn’t work, and also it doesn’t give me any error?

My code:

if Input.is_action_pressed("Attack"):
		$SpringTrapattack.visible == true
		$AnimationPlayer.play("Attack")
		await $AnimationPlayer.animation_finished
		$SpringTrapattack.visible = false

If you want to view all the code ask me

Watch out, you’re using Input.is_action_pressed(...), which means that the code nested underneath the condition is executed every single frame when the key “Attack” is down. This probably explains why you think it doesn’t work; it’s just spam-playing the animation so only the first frame is probably playing.

If you want the entire animation to be played when the “Attack” key has been pressed once, then you should replace the code with:

if Input.is_action_just_pressed("Attack"):
    $SpringTrapattack.visible = true
    $AnimationPlayer.play("Attack")
    await $AnimationPlayer.animation_finished
    $SpringTrapattack.visible = false

That’s the difference between Input.is_action_pressed("Attack") and Input.is_action_just_pressed("Attack")

(and by the way, you should replace the double-equals to a single equal sign in the second line : if you don’t, you’re just evaluating a boolean expression (checking if the spring’s trap attack is visible) rather than assigning a new value to the variable (setting it to true here))

1 Like

Sadly it did not work :frowning: :sob:

Well kinda it makes it true but doesn’t play the animation

Problem is it shows the first animation part but doesn’t play the rest?

I have same problem I will post it and hopefully someone will see it and help us :slight_smile: