0 votes

Is it possible to emit the shoot signal on a certain frame of animation? I made a 20-odd frame animation of a minigun spooling up, shooting, then spooling down and I just want to time a burst in the middle. I'm new and pulled an example from this link: https://www.reddit.com/r/godot/comments/aa7jff/how_do_you_play_a_sound_on_a_specific_frame_in_an/ about how to make something happen on an individual frame.

I'm getting the error "expected block in pattern branch" on the emit line at the bottom.

func _on_GunTimer_timeout():
    $AnimatedSprite.play("firing")
    $AnimatedSprite.connect("frame_changed", self, "on_firing_frame")
    $AnimatedSprite.connect("animation_finished", self, "_on_firing_animation_finished")
#   emit_signal('shoot', Bullet, $Position2D.global_position)
    $GunTimer.start()

func _on_firing_animation_finished():
    $AnimatedSprite.play("default")

func on_firing_frame():
    match frame:
        9, 11, 13, 15:
            emit_signal('shoot', Bullet, $Position2D.global_position)
asked Jun 17 in Engine by Kutkulio (19 points)

1 Answer

+1 vote

Hi There,

My suggestion would be to switch from using the node Animated Sprite to using Animation player and animation tree player. You can use these two together to control the animations of your Sprite.

If you use the Animation player you can actually trigger functions on a frame by frame basis. This gives you substantially more control over what’s happening.

If you want a crash course on how to use the animation player and animation tree player nodes then you should watch heartbeast’s action RPG tutorial on youtube. He covers it really well. I was sceptical at first but once I put in the work and switched my code over to work with it, I’ve been able to do much more with my sprites.

answered Jun 17 by Chafmere (50 points)

Thanks so much. I'll check that out!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.