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
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. :)
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.
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
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!
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
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
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 :)
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.
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
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.
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..
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,
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.
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
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
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.
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
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
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.
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.
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.
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.
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.
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).
AnimatedSprite can only change textures. In this example we are also moving and enabling/disabling collision shapes. You need AnimationPlayer to do that.
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.
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
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
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.
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!
I just don't get way you would ever use something like this. I feel like it all falls apart when you start creating the hurt() and die() functions: you could just as well recall the "hurt" and "die" animations directly from the AnimationPlayer. The only situations I can think of that's easier to handle with the AnimationTree is when you want to concat animations, like when you combo Attack 1 into Attack 2
I believe the animation tree is for handling the transitions between animations (immediate, etc.) and as author mentioned keeps the code cleaner from a bunch of if statements
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...
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"