Multiple Animation handling

Godot 4.2.2

When creating a top down 2d RPG that will have multiple weapons all with different animations assigned to the weapons EX:( Short sword animation will be visually different from an Great sword and so on for how ever many weapons will be added) what is the best method in handling all the different animations? I’ve read that a state machine paired with an animation player and animation tree is best, while I’ve also read you can easily achieve multiple different animations with just an animated 2d sprite and some lines of code. - I am a straight up Noob to animation and scripting and it’s been difficult to wrap my head around. Any input would be awesome, Thanks!!

If the different weapons are different scenes then you can add a unique AnimationPlayer to each one, and use the same animation names for “Attack” or “Block”. In that case a script might look like this

func attack_with_sword() -> void:
    var sword := $SwordSlot.get_child(0) as Node2D
    if sword:
        var animation_player := sword.get_node("AnimationPlayer") as AnimationPlayer
        animation_player.play("Attack")
    else:
        push_warning("No sword in sword slot!")

If your swords are merely animated sprites you could save each SpriteFrames resource for each sword.

Hard to recommend either one without more information, what do you have so far?

2 Likes

I don’t have anything made quite yet but have played around with both animation player/tree state machine, and animated sprites. The initial plan was to build animations Into the character base sprite for the actions then attach the weapon sprite into individual frames. I figured with this method it would be easy to replace the sprite 2d in this scenario for variations of the same weapon. I don’t know if this is the best route to take but with all the different animations to consider i wondered what will be the most stable/logical decision regarding what should be used to control animations, don’t know if this helps drive you to a solution of what would be recommended, Thank you for your response it is greatly appreciated :slight_smile: