+1 vote

Hi folks! I'm always have this doubt. for example some games have diferents animations pressing the same button, like left punch the when you press againg right punch, etc.
How do you accomplish this behaviour?

asked Jul 5, 2016 in Gossip by Nighttraveler (23 points)

1 Answer

+1 vote

I have done this, this way:

var anim = get_node("AnimationPlayer")
var next_anim = "stand" #this is the animation if there is no combo

func flush_attack():
    next_attack = "stand"

func do_combo():
    anim.play(next_attack)

then inside the place where I check for inputs I get the actions like this

if Input.is_action_pressed("attack_1"):
    var animation = anim.get_current_animation()
    if animation == "attack_1":
        next_attack = "attack_2"
    elif animation == "attack_2":
        next_attack = "attack_3"
    elif animation == "attack_3":
        next_attack = "attack_1"
    else:
        anim.play("attack_1")

Then inside the attack animations I call the function flashattack near the beginning of the animation and at the end of the animation I call the function docombo.

P.S. Cause my code is a little bit more complicated I wrote the answer from scratch. For example this code do not take care if you can attack.

answered Jul 5, 2016 by kakoeimon (162 points)
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.