The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

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)
in Engine by (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.

by (90 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.