+2 votes

I have the frames of a Sprite animated by an AnimationPlayer (a character running) in Godot 3.0. I have another animation to be played when the character takes damage, where the sprite visibility is toggled on and off to produce a flashing effect. How can I play both animations at the same time? Do I use an AnimationTreePlayer?

Thanks in advance

in Engine by (109 points)

1 Answer

+2 votes
Best answer

You should use two AnimationPlayers as children of your Sprite.

The first will play the main animations and the second will play the effect animations.

Here is the structure:

KinematicBody2D (or whatever your main node is)
    Sprite
        AnimationPlayer1 (for your spritesheet)
        AnimationPlayer2 (for your effects)

You should create a reference to the first animation player and call it something like anim_player and create a reference to the second animation player and call it something like effect_player. Then you can reference them to play whatever animations you want in your code.

For example, in your main node script:

onready var anim_player = get_node("Sprite/AnimationPlayer1")
onready var effect_layer = get_node("Sprite/AnimationPlayer2")

func take_damage(amount):
    # lower health
    health -= amount
    # play correct animations
    anim_player.play("knockback_animation")
    effect_player.play("blink")
by (1,577 points)
selected by
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 webmaster@godotengine.org with your username.