This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

How to mix two simple animations?

rjoshuarjoshua Posts: 37Member

Hello, I have a sprite with animations of idle, jump and others. I also have an animation called "blink",that is modulated with zero alpha, and then one, repeatedly three times, is when the player hits with an enemy. Well, how do I mix the two?

I read that it is done with the animationTreePlayer node, but I have not found a tutorial that explains clearly, and the 3d platform uses the node animationTreePlayer but I do not understand anything, and I think that is the node I need. Can someone explain to me in detail how to do this simple thing.

I have an "animationTreeProblem" :|


Tags :

Best Answer

  • TwistedTwiglegTwistedTwigleg Posts: 2,561
    Accepted Answer

    I messed around and it seems changing Color does not work with AnimationTreePlayer. I found a workaround, it just requires a simple script and exported alpha value. The AnimationTreePlayer is getting a rewrite in Godot 3.1, so likely the bug will be fixed then (especially if someone adds an issue to the Github repo).

    Also, in your case you do not want to use a blend node, but rather a mix node. You want to use a mix node because you want both animations to play simultaneously. blend plays both animations with a strength equal to how far the number is leaning (0.5 = both animations playing at half strength. 0 animation 1 is playing at full strength, while animation 2 is playing at zero strength. Etc). mix plays both animations at full strength at the same time.

    I attached the edited project so you can see the changes (I added rotation to the animation when I was debugging, in case you were wondering :smile: Feel free to remove it.)

Answers

  • rjoshuarjoshua Posts: 37Member

    I don't know if this topic is the right, sorry.

  • originaltenkaoriginaltenka Posts: 7Member

    You can do animation blending(mixing) for the different animations

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin
    edited February 2018

    I personally do not know how to blend animations in Godot, but a potentially good reference is the Platformer3D demo. In the Platformer3D demo walk and idle animations are blended, along with firing animations.

    EDIT: Just realized you've already looked at it...

    I will do my best to explain how it is working (though as I said before, I haven't actually used animation blending myself):


    You need to set up your scene tree so animations you want to blend are connected to each other. Using the Platformer3D as an example, you want to make sure your idle and running animations are connected to a Blend2 node. You can add a Blend2 node by pressing the plus icon on the top left window of the animation tree editor.

    If you want to transition through animations you need to use a Transition node.

    You can rename the nodes to more descriptive names by right clicking them and selecting "rename".

    Repeat this for all of the animations you want to blend. Make sure everything eventually connects to a Output node.


    Then in your code you need to use blend2_node_set_amount to change the how much the animation is blended. Here is how it is done in the Platformer3D demo: get_node("AnimationTreePlayer").blend2_node_set_amount("walk", hspeed/max_speed)

    walk is the name of the blend2 node, and then you pass in a float ranging from 0 to 1, where 0 will play the animation attached to socket a, 1 will play the animation attached to socket b, and any value in between blends the animations depending on how far they lean to either 0 or 1. (A value of 0.5 will blend both animations equally)


    To use transitions, you need to use transition_node_set_current. The platformer3D code looks like this: transition_node_set_current("state", anim)

    state is the name of the transition node in the AnimationTree, and anim is a int. If anim is 0, then it will transition to the animation that is connected to socket 0.

  • MagicLordMagicLord Posts: 578Unconfirmed

    There is a graphic editor to setup blending without code
    Check Marcos Bitetti video

    https://youtube.com/watch?v=IHWPVR3no10

  • rjoshuarjoshua Posts: 37Member

    Thank you @originaltenka, @TwistedTwigleg and @MagicLord for your help. Finally I could already understand how the animationTree works in Platform3d! Ahua! :D

    However, the bad new is that when I try to mix my two animations, something strange happens. The Sprite turns black, instead of transparent. I do not know what I'm doing wrong.

    Here is the file:

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin
    Accepted Answer

    I messed around and it seems changing Color does not work with AnimationTreePlayer. I found a workaround, it just requires a simple script and exported alpha value. The AnimationTreePlayer is getting a rewrite in Godot 3.1, so likely the bug will be fixed then (especially if someone adds an issue to the Github repo).

    Also, in your case you do not want to use a blend node, but rather a mix node. You want to use a mix node because you want both animations to play simultaneously. blend plays both animations with a strength equal to how far the number is leaning (0.5 = both animations playing at half strength. 0 animation 1 is playing at full strength, while animation 2 is playing at zero strength. Etc). mix plays both animations at full strength at the same time.

    I attached the edited project so you can see the changes (I added rotation to the animation when I was debugging, in case you were wondering :smile: Feel free to remove it.)

  • rjoshuarjoshua Posts: 37Member

    Thank you, finally it works! My programmer's nose told me to try to animate an exported variable, but I did not know very well how things work with the keyword tool.

    I am also grateful for the explanation about the mix node and for the file, now I will see more tutorials since I understand better the animationTreeProblem node .

Sign In or Register to comment.