Why doesn't my animation work?

I’m trying to impliment a taunt function into my code, but it won’t work as I want. The sound plays normally, but I’m still able to move and my animation doesn’t play.

if Input.is_action_just_pressed("taunt"):
	taunt()

func taunt():
	if Input.is_action_just_pressed("taunt") :
		velocity.x = 0
		velocity.y = 0
		animation.play("taunting")
		taunt_sound.play()

There is no reason to check the input twice btw. You can and as long as it is within the same frame, it will return true if just pressed, but it is not needed.

There is also nothing in your code stopping the movement, so why would the movement input stop reacting?

Your sound is playing so the animation.play command will also have run. Is your animation called “taunting” or is should it be taunting.play() perhaps?

Without seeing more code it is difficult to help further.

1 Like

Are you playing other animations? Do you play them every frame in a _process or _physics_process function?

It’s under _physics_process(delta)

I have a variable that makes it so I can’t move, but when I use that I’m permanetly stuck when I press the taunt button

The animation is under animation.play(“taunting”). The sound taunt_sound.play() works fine

Could you share the rest of your code? I’m sure animation.play("taunting") works but other animtions playing can interrupt this. Same with velocity.x = 0, this will only set the velocity to zero for as long as it’s uninterrupted, so very likely only that one frame.

I’ve figured it out. Other animations were interupting the taunt, so that’s why the sound worked but the animation didn’t. To fix this I made a boolean for if animations can play or not. Thanks for the help guys!

Oh, your idle animation was the cause? (I’m not sure if you have an idle animation)