How to repeat the current animation without changing the condition for one frame with animation tree?

Godot Version

GODOT 4.2

Question

I have a character with a “shooting” animation with a duration of 3 frames , and the animation plays while you press the button “shoot”, and the button also remains pressed for a duration of 3 frames. The animation_tree /parameter/shoot_condition is set to true while the button is pressed, but if you press the button too fast, the game remembers that you pressed the button and it presses itself instantly after the duration of the animation, to avoid having a frame of some other animation in between shots.

The problem is that when you press the button faster than the animation takes to finish, the animation doesn´t reset, but instead it stays on the last frame unless you wait the duration because the condition changes, but I want it to restart from the beginning without changing the condition.

There must be a easy way to do it but I can´t find anything and i have been looking for this very hard sorry if it is already been asked before, maybe I am not googling the right terms. Anyways thanks for reading, I hope you can help :smiley:

Sounds like you just have to enable animation looping for the shooting animation? There’s a button for it on the right side of the animation panel.

1 Like

I also thought about that, but then the animation plays as many times as the ammount of bullets left in the weapon, plus a little bit of an extra shooting animation of a non exixting bullet for some reason, i dont really know why, because the timers are set to the same time.

In fact, if I set the button to 0.30, and the animation to loop at 0.32 it looks good (for 6 bullets), but I don’t like it like that because maybe it will look weird in another computer or maybe it could bug out later on if maybe you pick more bullets of the machinegun while you are already shooting the machinegun or something.

It is only for that reason i think it would be better if it restart when a shot is actually fired instead of loop

Now, i have a shooting animation with a frame of delay at the start. At least is not fire coming out of the gun but it still looks bad to see a nanosecond of a frame that shouldn’t be there

You’ll need to get the AnimationNodeStateMachinePlayback object and force the node to start again with AnimationNodeStateMachinePlayback.start()

Something like:

func shoot() -> void:
	var playback = animation_tree.get("parameters/playback")
	playback.start('shoot')
1 Like

thanks for the answer, I am using a blend space 2D for the shooting animations, do you know if it will work for all the animations with that?

I don’t know, sorry.

1 Like