Godot Recipes: Animation States

Поділитися
Вставка
  • Опубліковано 15 тра 2019
  • Using the animation state machine to manage your animations.
    Art by Elthen: elthen.itch.io/
    Text version: godotrecipes.com/3.x/animation...
    Support me on Patreon: / kidscancode

КОМЕНТАРІ • 152

  • @lucasnievas4890
    @lucasnievas4890 2 роки тому +7

    Just the first 10 seconds summarize my entire morning

  • @BK-id6pc
    @BK-id6pc 5 років тому +32

    Another great video. In my mind you do the best videos in the field of game development. No other channel has taught me as much as your one. Please never stop sharing these great videos with us. :)

  • @robotscanplaydev6939
    @robotscanplaydev6939 2 роки тому +5

    This is so much easier than every other tutorial on animations trees out there. Works out of the box. Thanks Chris!

  • @salvadorm7564
    @salvadorm7564 5 років тому

    Awesome video as always. Thank you for all the effort you put into your content.

  • @CRYsistem
    @CRYsistem 5 років тому +5

    You're a life saver mate, this is exactly what i was looking for, thank you!

  • @Pspisripoff
    @Pspisripoff 3 роки тому

    Wow, godot added statemachine! Niiice!
    Thank you KidsCanCode for the tutorial! Amazing job!

  • @tayete
    @tayete 4 роки тому +1

    Great tutorial: really clear and well explained.

  • @easyU2B
    @easyU2B 4 роки тому

    Whoa! This is really powerful...! Thanks for the tutorial.

  • @awiggan1
    @awiggan1 5 років тому

    These little recipes are really good. Very handy

  • @ArkOfAges
    @ArkOfAges 5 років тому

    Really interesting. Thank you for posting.

  • @TackerTacker
    @TackerTacker 5 років тому +1

    Great video and I love the Godot recipes website

  • @drakibble2199
    @drakibble2199 5 років тому +13

    Thank God for this! My animation script was a jumble of awful if statements lol. Thank you for these videos, I know that you dont get a lot of views, but I appreciate every video.

    • @gargoyled_drake
      @gargoyled_drake 2 роки тому

      i personally find the if statements easier to keep track of than both having to keep track of if statements, travel commands and the animationtree
      this made everything more complicated for me, but also seems to be the only way to have the attack animation play till the end before going back to idle

  • @MattRandall160
    @MattRandall160 4 роки тому

    Some really awesome and useful videos!! thank you

  • @jackspade6401
    @jackspade6401 5 років тому

    Dude! Thank you! Keep up the awesome videos!

  • @suvigyamishra4604
    @suvigyamishra4604 3 роки тому +2

    i was checking on the gdquest professional game development course.. and reaching to just this part was so overwhelming.. not saying that the course was bad.. but see this is all it takes to understand how states work.. Great Video!

  • @ChavsberryGaming
    @ChavsberryGaming 4 роки тому

    Absolute unit.

  • @jckelleri
    @jckelleri 2 роки тому

    I didn't even know this was possible, it was very helpful, and I learned a lot thank you.

  • @josuereis6367
    @josuereis6367 4 роки тому

    Awesome! Thank you!

  • @ducanhtran8929
    @ducanhtran8929 5 років тому

    Love your videos! Keep it up

  • @McHumaty
    @McHumaty 5 років тому

    Nice work.

  • @pranavkul525
    @pranavkul525 3 роки тому

    That helped me a lot. Thanks!

  • @markyap3865
    @markyap3865 4 роки тому

    great video man. Thanks for the help!

  • @fossegutten6579
    @fossegutten6579 5 років тому

    Nice video! Love the website aswell.

  • @PeterKLee
    @PeterKLee 4 роки тому

    thank you for sharing your knowledge! It was greatly helpful to me :)

  • @diegoh473
    @diegoh473 Місяць тому

    thanks this is what I was looking for!

  • @MarcLdhl
    @MarcLdhl 5 років тому

    Awesome!

  • @mohamedSGH420
    @mohamedSGH420 Рік тому

    Thank so much bro your a life saver

  • @spiritabsolute
    @spiritabsolute 4 роки тому

    Thank you very much dude, you really helped me!

  • @lucaspec7284
    @lucaspec7284 4 роки тому

    this was very helpful, thanks

  • @luisv1308
    @luisv1308 5 років тому

    Thank you!

  • @MarvelousLXVII
    @MarvelousLXVII 3 роки тому

    Really nice video.

  • @omaryahia
    @omaryahia 7 місяців тому

    amazing🌟

  • @flowfrog101
    @flowfrog101 Рік тому

    Thank you so much i was really struggling with the animation tree

  • @StrikeKINGyt
    @StrikeKINGyt 5 років тому

    awesome, thanks man!

  • @johnhammer8668
    @johnhammer8668 4 роки тому

    mind blown !!

  • @yapayzeka
    @yapayzeka 5 років тому

    lovely

  • @robertnett9793
    @robertnett9793 2 роки тому

    Well.. that solves problems. Soooo many problems. Thanks a lot mate :D

  • @hessaa1712
    @hessaa1712 4 роки тому

    thats very good video

  • @Petoj87
    @Petoj87 4 роки тому +3

    Is there some tutorial where you go over how you setup the animations in the animation player? your animation is in sync with the line, mine just starts when i hit play, and continues even if i pause..

  • @Garniy_Hlopchik
    @Garniy_Hlopchik 8 місяців тому

    "and than there's die, when we reach that state there is no return"
    went dark all of a sudden lmao

  • @pixelrabbit261
    @pixelrabbit261 4 роки тому +5

    Great video! I just watched a bunch of other "state machine" videos which just use code (enum). Is this doing exactly the same thing but saving us having to write as muchcode for each state?... when would you use code rather than an animation tree. Pixel Gamemaker relied heavily on this tree approach. I gave up in the end and decide to learn to code :)

    • @Kidscancode
      @Kidscancode  4 роки тому +4

      Those videos are talking about a generalized state machine for your character, which can handle any aspects of its behavior. This is specifically an *animation* state machine.

  • @johnpark3243
    @johnpark3243 4 роки тому +1

    Great video to see after hand crafting a complex animation state function that's tightly integrated into all of my scripts... :( lol gonna have a go at tearing down and rebuilding all of my animation code now, see you guys in 5 hours

    • @1nopinate
      @1nopinate 2 роки тому +1

      how was the 2 years and 5 hours goes ?

  • @ennizodev
    @ennizodev 2 роки тому

    It's shown on my UA-cam, this is a great opportunity.

  • @harveyg2147
    @harveyg2147 4 роки тому +4

    I have four idle animation {right,left,up,down} and don't know how connect them each other

  • @samuelallen6494
    @samuelallen6494 4 роки тому +1

    i have been using this method:
    func _physics_process(delta):
    |> if Input.is_action_pressed("ui_right"):
    |> |> vel.x = speed
    |> |> $animation.play("walk")
    ------------------------------------------------------------------
    this is a good way to do it but it has limitation like sliding before going into idle is not possible in this method

  • @nickbubuioc
    @nickbubuioc 3 роки тому +1

    i love your tutorials , they are short and right to the point , i have a question , im trying to make top down rpg , and i have idleRight,Left,Up,Down , how can i set this up ? :) Thank you for the amazing work

  • @martinmajewski
    @martinmajewski 5 років тому +2

    It is possible to make a double-attack by checking the current animation state and transition to the second attack only if the first attack's animation is still playing? Moreover, it would be nice to read the current timestamp of the animation.
    In this case, the physical length of the animation an/or time range during the animation's play would make an excellent condition to perform combo-attacks by hitting the same input action (button) multiple times in the correct time-distances.

  • @fanimation2000
    @fanimation2000 4 роки тому

    THAT WAS VERH HELPFUL TNX A LOT ^_^

  • @AkaiKnight
    @AkaiKnight 3 роки тому +2

    *flashback to unity mecanim*
    oh god I dont wanna go back

  • @carismicaids7614
    @carismicaids7614 2 роки тому

    i was missing one word for my code to work, if i had not found this video i may have lost inspiration to continue the creation of my game. Thanks!

  • @pattyorigami
    @pattyorigami 4 роки тому +1

    Any possibility you could do another video on this showing how to implement it with 2d platformers? I'm having a lot of trouble getting jumping and falling animations to work smoothly this with animation states

    • @Warionator
      @Warionator 3 роки тому +2

      in your code, if the player y velocity is negative (they are going up), then play the jump, if the y velocity is positive (they are falling), play the falling animation

  • @HeraldOD
    @HeraldOD 4 роки тому

    How do I detect when the death animation is finished (to reload the scene for example)? With AnimationPlayer I just used the animation_finished signal, but it doesn't work with the state machine, and there's no signal on the AnimationTree.

  • @adhityarisyad9029
    @adhityarisyad9029 4 роки тому

    is there anyway to stop running and finish the attack animation when you pressed attack while running?

  • @muajin
    @muajin 4 роки тому

    Hello. I'm in a similar bind. I have the script with animations but either i'm missing a line or have one misplaced. My player moves but only one animation works and doesn't change direction.

  • @nowherebrain
    @nowherebrain 4 роки тому

    Looking for a video on AnimationTree usage in GDscript, but everyone seems to be covering state machines that can be done easily with a switch case(match)...could you do one that covers accessing animation nodes inside an animation tree...like changing the "add" animation from a one shot...this is one of the things I am fighting with.

    • @Kidscancode
      @Kidscancode  4 роки тому

      Thanks for the suggestion. I put it on my (unfortunately very long) list! :)

  • @jovlem
    @jovlem 4 роки тому +5

    For me, the "statemachine.travel("animation_name") is not working.
    Any idea what could be wrong? ( I use stable version 3.21 )

  • @rikzander8691
    @rikzander8691 4 роки тому

    Hello,
    Is it possible to play animations backward in the state machine?

  • @ChavsberryGaming
    @ChavsberryGaming 4 роки тому

    Oh thanks a lot. So many things to screw up.

  • @tohut5507
    @tohut5507 3 роки тому +3

    How do I make the animation playing smooth of the walk, sometimes the animation plays and other times it does not play ? How do I fix it ?

    • @nbourre
      @nbourre 2 роки тому

      I have the same problem. The walk animation goes back to idle even if I don't tell the code to travel to "idle". This occurs with an enemy I'm trying to implement.

  • @fastfading4667
    @fastfading4667 5 років тому +1

    could u share the project file ? it will be helpful

  • @josesena4314
    @josesena4314 5 років тому

    Your videos are so great. I have a newborn child and I can't wait until she get the age of learning how to code. Your channel will be so helpful

  • @mrmixedvideomaker9767
    @mrmixedvideomaker9767 4 роки тому

    Hi I am trying to make a platformer and this worked, but the animation speed is too low, so how do I increase the speed?

  • @gendalfgray7889
    @gendalfgray7889 4 роки тому

    Hello. I'm making fps with godot tutorial. In it animation state tree is not used, states and changin process writed in code. I managed to simplify tutorial code for animation changing to single structure. Guns in tutorial have 5 animations, idle, equip, unequip, fire, reload. In my piece of code i can add weapon with another name but with same 5 animations without changing the code.
    Is it possible to make such universal structure in animation tree? Because for every new weapon i need to add 5 more animations in to tree. And i want lots of weapons.
    Animation tree is convenient and have blends, which i want to use too.

  • @Nugget11578
    @Nugget11578 4 роки тому

    is there a way to blend the animations while also having this state tree?

    • @ryoneer
      @ryoneer 4 роки тому +1

      click on the arrowed line between nodes, and play with the Xfade time, it smoothens it nicely

  • @cedricleclercq3601
    @cedricleclercq3601 5 років тому +2

    Hi,
    How can i reverse the position when my character is attacking in a another way?

    • @smutnywalen
      @smutnywalen 4 роки тому

      $AnimatedSprite.flip_h = true

    • @mrlonelyFilms
      @mrlonelyFilms 4 роки тому +1

      @@smutnywalen Yeah but that only flips the sprite not the hitbox....

  • @robby2725
    @robby2725 5 років тому

    I love you ❤️

  • @Zephyroths
    @Zephyroths 4 роки тому

    do you have tips on what to do if i want the attack combo is done by pressing the attack button twice?

    • @Kidscancode
      @Kidscancode  4 роки тому

      You'd need to keep track of when the button is pressed, and if it's pressed again within a certain length of time.

    • @Zephyroths
      @Zephyroths 4 роки тому

      @@Kidscancode is there a way to check if the animation is finished playing? There's no animation finished signal in the animation tree, and if I use the animation player, it'll return the animation i already set before starting the game

  • @jovlem
    @jovlem 3 роки тому +2

    When I use:
    $Animationtree.get("parameters/playback").travel("attack1") it won't work, why is that?

  • @annoyed567
    @annoyed567 3 роки тому +2

    var current = state_machine.get_current_node() is an invalid call non existent function "get _current_node" in Base NIL
    also the var current variable is never used so i tried experimenting and removing the line completely, perhaps i dont understand state machines.
    with out a var current line of code it then seems to bring up a error on state_machine.travel("idle"), right at the end of get input. if i replace this with return the game then loads, but any action or input that requires it to use the .travel function breaks the game and come up with another non existant function "travel" which was the same error the idle arror had.
    can anyone explain this,

  • @grandromusic683
    @grandromusic683 5 років тому +3

    Nice video, it helped me alot :)
    But I think one detail needs to be added which I found out having troubles with the AnimationNodeStateMachine:
    Its better to check if the state_machine is playing before you travel to a node, because otherwise you could get an error if the state machine is not active.
    You do that simply by checking:
    if state_machine.is_playing():
    before you use the travel function.
    This becomes definetly necessary if you work with sub state machines, as they wont get activated at the beginning.

    • @Kidscancode
      @Kidscancode  5 років тому

      Yes, I noticed your issue about this.

  • @martinpellicer8489
    @martinpellicer8489 4 роки тому

    hey please help me,I searched in every place and noboady answer me. its works all perfect for me except that when I try to go from "shooting" animation to "idle" at the end, it dosen´t work, "Fire" play very very fast and then "idle" play. Both have the same conditions because my "idle" animation play when velocity is 0 and is_on_floor, and my "Fire" animation too, because I want that you can´t move when you are shooting. I think it is because of when I select in animation tree "at end" it dosen´t work.
    Shooting on the condition has the key you have to press to shoot, so it enters and change from "idle" to "fire" but then very fast to "idle" again

  • @Duraznito9712
    @Duraznito9712 3 роки тому

    What if I want to have four aditional animations for diagonal movements? How could I program it?

  • @9livesK9
    @9livesK9 2 роки тому

    Its also possible to use an AnimatedSprite node and then key in the frames into an animatedPlayer then use the animationTree to control the state machine "AnimatedNodeStateMachineTransitions"?
    Or does this just only work with Sprite? Sorry if this is a silly question. I'm a beginner in Godot.
    Why I'm asking is because I already have my SpriteFrames loaded up in one AnimatedSprite and I don't want to start all over again and re-import everything if its not necessary (if AniatedSprite and Sprite are similar enough).

    • @Kidscancode
      @Kidscancode  2 роки тому +1

      AnimatedSprite can only change textures. In this example we are also moving and enabling/disabling collision shapes. You need AnimationPlayer to do that.

  • @Ifrit_desu
    @Ifrit_desu 4 роки тому

    is there a node like this for the animated sprite?

  • @wash99
    @wash99 3 роки тому

    How can I add
    Jumb and dash

  • @danobra
    @danobra 3 роки тому

    What are transition nodes for? It seems you don't use them and some other devs do

  • @brucelee7782
    @brucelee7782 8 місяців тому

    does this work for cutout animation? Im using bones and ik and rotating the sprites around

  • @Nipah.Auauau
    @Nipah.Auauau 5 років тому +3

    low volume :/

  • @spachurrenGuias
    @spachurrenGuias 4 роки тому

    I have one strange problem when trying to turn the kinematicbody2d scale:
    if Input.get_action_strength("ui_right"):
    input_dir += 1
    self.scale.x = 1
    if Input.get_action_strength("ui_left"):
    input_dir -= 1
    self.scale.x = -1
    But when pressing them it does "blink" and has both left and right looking elements (my animation is build with 1 node with sprite each per element... hand, feet, body, head...) and while "blinking" it does get out of collision with ground and fall down...

    • @spachurrenGuias
      @spachurrenGuias 4 роки тому

      Problem solver, avoiding scale, appart from having stuff at the positive range of X axys that when scaled goes auto into negative one which causes clunky animation, it does blink even when fixing it.
      Finally used a node group to set_flip_h among the whole group and "et voila"

  • @bubblemage
    @bubblemage Рік тому

    So how would you make it so the double attack is not automatic, but instead you can press the attack button twice to first make attack1 and then attack2? like a combo attack

  • @gargoyled_drake
    @gargoyled_drake 2 роки тому

    for some reason this didnt work for me, i havent added the attack yet, but just the travel from idle to run and such dosnt work, my character is just stuck in a still frame after adding this.
    animation player worked fine though, but this seem to be the only way to play a full animation and go back to idle state when button is pressed

  • @TheTattorack
    @TheTattorack 4 роки тому +1

    This doesn't work for me at all.
    I've followed JayAnAm's tutorial on 3D character movement and it's fine, but I want to add some in between animations for when, say, the character lands on the floor. State Machine can apparently do that, and this is the only well made tutorial for animation state machines, but "var current = state_machine.get_current_node()" throws an error, something about it not existing.

    • @MoogieSRO
      @MoogieSRO 3 роки тому

      I just encountered this and fixed it. Firstly, check that you didn't capitalize the "parameters/playback" bit. Then make sure you have set a 'start' and 'end' state in the animation player with those two little flag buttons you see next to the trash button. You might run into additional difficulties if you don't have an 'idle' animation (like I don't) but we should be able to figure that part out for ourselves. Hope this advice didn't come too late!

  • @ivanmectin9106
    @ivanmectin9106 2 роки тому

    for the two attacks , he does a return, does that mean it returns to idle ?

  • @Yamoyashi
    @Yamoyashi 3 роки тому

    But how do you prevent movement during the attacking animation?

    • @Kidscancode
      @Kidscancode  3 роки тому

      You can disable movement during the attack with a flag. Set can_move = false when the animation starts, and then back to true after.

  • @kenet206
    @kenet206 4 роки тому

    DAYS BYGONE?!

  • @adamsmiddy
    @adamsmiddy 5 років тому

    What is velocity.length? Why not just use velocity.x == 0 or something similar?

    • @GameEndeavor
      @GameEndeavor 5 років тому +1

      Because it's a top down game not a platformer. If there is any movement in a top-down game, then you want to transition to the run state.

  • @mleitejunior
    @mleitejunior Місяць тому

    I know the focus of the video it is the AnimationTree (an Animation State Machine), but would not be perfect to align it with a player state machine, instead of all ifs in process?
    Something like a node/script and subnodes/subscripts to handle all the logic and attributes of the player in each state. You can par it with the animation state machine and everything would be organized and easy to grow with no big problems.

  • @fernanboxfrias381
    @fernanboxfrias381 3 роки тому +1

    How did you change the color of the letter of your script

  • @jasonwilliams8730
    @jasonwilliams8730 7 місяців тому

    I see start and end but what about an anystate?

  • @aayushghosh3357
    @aayushghosh3357 5 років тому

    Hi i followed this tutorial, but changed some things to better suit my game which is a platformer. Whenever I activate the Animation State Machine the Output gets spammed with this scene/animation/animation_tree.cpp:861 - Condition ' !track_cache.has(path) ' is true. Continuing..:
    and whenever I start the game my error thing gets flooded with this error:
    E 0:00:02:0964 Condition ' !track_cache.has(path) ' is true. Continuing..:
    scene/animation/animation_tree.cpp:861 @ _process_graph()
    Can you please help me understand what is going on and how to fix it. Everything in the game works perfectly fine but I keep on getting this spammed and its killing me.

    • @Kidscancode
      @Kidscancode  5 років тому

      It seems you have a pair of nodes with no path between them. That's what "!has(path)" would mean.

  • @teambeluga1934
    @teambeluga1934 4 роки тому

    Good video, but this setup will only work for a very simple character. An involved complicated enemy with AI and the like, I'm still not certain how this will help. Especialyl with areahit boxes and the like. Perhaps I need to think about it more.

  • @boratsagdiyev1586
    @boratsagdiyev1586 4 роки тому +1

    I guess i'm going back to IF statements, because my spritesheet of run jump walk run attack are all on separate spritesheets.
    Making that work is worse than anything... I cant put 2 sprites on 1 animation player so eventually it's even more clutter.
    Back to learning GDscript >< My animation only stops walking when i move to the right while holding jump

    • @7_rlz_714
      @7_rlz_714 4 роки тому

      Same problem, I have separate Sprite action, i can't add two action in one spritenode, because are in top or behind between them

    • @Kidscancode
      @Kidscancode  4 роки тому

      > " I cant put 2 sprites on 1 animation player"
      Sure you can. AnimationPlayer can control *any* property, including the Sprite's *Texture*.

    • @boratsagdiyev1586
      @boratsagdiyev1586 4 роки тому

      @@Kidscancode but i need animatedSprite not the normal sprite , still possible?

    • @awesomehazimex7410
      @awesomehazimex7410 4 роки тому

      @@boratsagdiyev1586 yes animated sprite and animation player can be used together

  • @motizukilucas
    @motizukilucas Рік тому

    During IDLE it stay stuck at idle left regardless if I've moved right or up before

  • @Riodragon1
    @Riodragon1 5 років тому

    you are a god thx , you could made one tutorial rhythm games?? I do not encounter anything about it /=

  • @freshouttathebag7725
    @freshouttathebag7725 Рік тому

    what does the sync transition do?

  • @lockingsalt
    @lockingsalt Рік тому

    How do you implement this on godot 4?

  • @AxlCake
    @AxlCake 4 роки тому

    He sets a var for get_current_node() but never uses it, could anybody tell me what that is for exactly and why it needs to be there?

  • @salman-ej2wb
    @salman-ej2wb 4 роки тому

    Hi
    I have problem here.i already write code Almost like you,but the Animation/characther still doesn't move.i even have copy your code from internet but still won't move.why this happen?

    • @Kidscancode
      @Kidscancode  4 роки тому

      Copying the code isn't everything. Did you also add the input events that the code is referencing for movement ("move_left", etc)?

  • @pow4570
    @pow4570 2 роки тому

    I cant active animation tree.
    1:53
    can someone help?

  • @boratsagdiyev1586
    @boratsagdiyev1586 4 роки тому

    Edit: removed question and figured it out.