State Machine Setup for 2D Platformer Character ~ Godot 4 GameDev Tutorial

Поділитися
Вставка
  • Опубліковано 4 лип 2024
  • Break down a complex character into more managable states that run selective code and can transition into each other while controlling animations through AnimationTree and the playback travel function. This is one example of how you can structure a character for a platformer character to scale up to having many animations and different rules for how the character moves around your Godot 4 game world.
    Use Part 1 End Project (below) as the Starting Point for This Tutorial to Follow Along
    Download Project ➣ ko-fi.com/post/Godot-4--Platf...
    Also on Patreon ➣ / godot-4-quick-80723131
    Art Pack Used anokolisa.itch.io/sidescrolle...
    Part 1 ➣ • 2D Platformer Quick St...
    Part 2 ➣ • 2D Platformer Attacks ...
    ➣ Downloadable Assets, Video Courses, and Other Places to Follow Me
    linktr.ee/ChrisTutorials
    ko-fi.com/christutorials
    chris-tutorials.itch.io/
    00:00:00 - What to Expect
    00:01:29 - Starting Point
    00:03:12 - Download in Description
    00:03:25 - Add Nodes (Sprite, AnimationTree, AnimationPlayer)
    00:04:26 - Idle Animation in Animation Player
    00:09:10 - Run Animation
    00:10:56 - Move BlendSpace1D
    00:13:16 - Setting Animation Parameters
    00:17:20 - Facing Direction
    00:18:04 - Removing Animated Sprite References in Player script
    00:19:48 - Setup State Machine
    00:20:54 - Setting Up State Scripts
    00:23:31 - Get States in State Machine
    00:25:47 - State Can Move
    00:29:58 - Jump from Ground State
    00:35:12 - Change from Ground to Air State
    00:37:15 - State OnEnter and OnExit
    00:40:04 - State Debug Label
    00:41:49 - Exit Air State to Ground State
    00:44:12 - Double Jump from Air State
    00:47:48 - Reducing Gravity for More Floaty Characters
    00:48:19 - Jump Animations in Animation Player
    00:51:46 - Animation Tree Setup
    00:54:12 - Travel Tree through Playback
    00:57:49 - Landing State
    01:01:43 - Switch to Air when Not on Floor
    01:02:37 - Player Script Cleanup
    01:04:02 - Animation Position Offset due to Sprite Centering
    01:05:37 - Wrapup
  • Навчання та стиль

КОМЕНТАРІ • 165

  • @capra3537
    @capra3537 Рік тому +141

    Just want to point out for anyone who is new to AnimationTree like me. Do not set your idle animation to Autoplay on Load as it will break your animation loop. Spent about an hour figuring that one out 🙃

    • @yamanalkayyali89
      @yamanalkayyali89 Рік тому +2

      thanks man it really helped me out

    • @donatkamary8137
      @donatkamary8137 Рік тому +2

      Thanks it helped me too ☺

    • @javaughnwilliams878
      @javaughnwilliams878 11 місяців тому +1

      The same thing happened to me. Took me way longer to figure it out though 😂

    •  10 місяців тому +1

      What should be done then?

    • @driver694
      @driver694 8 місяців тому +1

      Happened to me, sadly I did not read your comment and spend way too much time on finding it out myself

  • @DavidRycan
    @DavidRycan 20 днів тому +1

    It is impossible to explain how useful this tutorial is. I went from being totally confused on every element of animation and Godot state machines, to having a fully functional one thanks to this video

  • @lutecemina2240
    @lutecemina2240 Рік тому +44

    This is probably one of the best tutorials that explain how to set up the state machine, very easy to follow and also in deep.

    • @ChrisTutorialsYT
      @ChrisTutorialsYT  Рік тому +5

      Glad it was helpful. I know it's a pretty tricky subject so I hope I didn't lead anyone astray here. Will see if it still performs well in the next video when I throw in some attacks to the animation set (it should lol)

  • @hiiambarney4489
    @hiiambarney4489 Рік тому +12

    Also I love that you literally time stamped everything in this video, makes it so useful for coming back to it.
    May be a small thing but it's really appreciated!

  • @zicraftian
    @zicraftian 11 місяців тому

    What at incredibly helpful video! You have shown what I searched for and even provided information for things I never even knew I needed!

  • @stucktj
    @stucktj 6 місяців тому +5

    Thank you for the time and effort you put into this video. This helped me understand on how start the process of converting my existing code without starting from scratch.

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

    I just wanna say thank you for explaining things clearly and taking us through your mental process/logic. It's really helping me learn how to think.

  • @pascalcasier959
    @pascalcasier959 Рік тому +3

    Love your tutorials. Please continue on this project.

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

    Thanks Chris! I really like your content on Godot 4. Really complete series.

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

    I was really confused about how state machines actually worked, fully following through this tutorial made me able to understand all the basics, also learned about a new method of character animation. Thank you so much for this!

  • @codyj9983
    @codyj9983 10 місяців тому

    Fantastic! Thank you for explaining it in so much detail so quickly.

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

    really amazing tutorial. big fan of longer more in depth tutorials like this

  • @aceofspades7927
    @aceofspades7927 Рік тому +39

    Awesome tutorial! One thing to note is that you don't necessarily need to use a Sprite2D, instead you can keep the AnimatedSprite2D and use the AnimationPlayer to key the animation and frames. This is my preferred method since it works the exact same as the Sprite2D, but the AnimatedSprite2D keeps all your sprites organized and on one node without having to key texture changes and not having to worry about hframes. Keep up the good work and I can't wait to see the next tutorial!

    • @jamesrivettcarnac
      @jamesrivettcarnac Рік тому +1

      Gtk

    • @nayronysantanafagundes5147
      @nayronysantanafagundes5147 8 місяців тому +3

      But the keys simply doesnt show up in AnimatedSprite2d 😭

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

      that's a great tip! but when i add the animation and frame keys i have to recreate the timing for individual frames i eventually set in AnimatedSprite2D, so is there a point to set them in AnimatedSprite2D if i just recreate that in the AnimationPlayer?

  • @TimothyParez
    @TimothyParez Рік тому +2

    Your tutorials are very nice, content, presentation. Thank you!

  • @hamzahichmine7084
    @hamzahichmine7084 5 місяців тому

    This the most comprehend lesson that i had ever watched, really appreciate btoo

  • @StorytimewithChippy
    @StorytimewithChippy Рік тому +2

    Hey Chris! Big fan of your work, your videos tend to be really perfect for my learning style and I've developed a lot under your pseudo-tutelage. If you're building on this tutorial in the future, would love to see some ray casting!

  • @fleetfoxx
    @fleetfoxx 8 місяців тому +4

    Awesome tutorial! I followed along in C# and all the concepts still apply. I decided to use signals to transition between states rather than checking for a next state in the physics process loop which felt a little cleaner.

    • @Fatalhck
      @Fatalhck 5 місяців тому

      Yeap, way better

    • @SkeletonBill
      @SkeletonBill 4 місяці тому

      Would you be willing to share your C# code? I'm trying to do the same but can't quite get it right.

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

    you are a real angel man thx for dense tutorial ı was zero and afraid before your video but now ı can code and understand most of the other tutorials

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

    This is awesome. Thanks for your effort 😊

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

    This is crazy informative, thank you!!!

  • @hiiambarney4489
    @hiiambarney4489 Рік тому +8

    Big Work!
    Looking forward to more.
    This is pretty intense, especially if you are like me coming from Game Maker 2, where functions and object oriented programming concepts are extremely minimal.
    I think it was about time broadening my horizon and hey, usually, I don't really learn all that much from coding along and end up wondering why something is not working when I try to extend functionality but this time I at least began grasping the newly introduced concepts to some extend, as you made a good effort of briefly stating your objective while coding, even if hastily. (Perhaps since this is already second nature to you, none the less, it helped)
    I could code quite complex structures in GML but I could not for the life of mine code an old school collision structure with slopes. And apparently, neither could the entirety of what's left of the GM community, since I've asked on any forum, subreddit, discord and even stack exchange to no avail.
    I even asked people that seemed like code wizards directly and I always got to no result in the end, even if they where very helpful.
    And with that, I left game development, even if I had a decent project on my hands (art and sound got insane feedback, gdd's where praised by my industry contacts and so on)
    I just couldn't get over the fact I was beaten by slopes, more so, knowing how they SHOULD work in theory but not in code.
    That really destroyed me.

  • @FayteZephyr
    @FayteZephyr 7 місяців тому +4

    Thank you for the tutorial, it was fantastic overall. I followed along in C#. For any other newbies... some tips!
    1. In CharacterStateMachine, for the playback use
    foreach (State state in GetChildren().OfType())
    {
    state.Character = this.Character;
    state.Playback = (AnimationNodeStateMachinePlayback)this.AnimationTree.Get("parameters/playback");
    _states.Append(state);
    }
    If you need to add debug you can still iterate and log.
    2. In GroundState.cs, the Character.Velocity is immutable, so use
    private void Jump()
    {
    Character.Velocity = new Vector2(Character.Velocity.X, Character.Velocity.Y + JumpVelocity);
    NextState = AirState;
    Playback.Travel(JumpAnimation);
    }
    same in AirState.cs
    private void DoubleJump()
    {
    Character.Velocity = new Vector2(Character.Velocity.X, Character.Velocity.Y + DoubleJumpVelocity);
    Playback.Travel(DoubleJumpAnimation);
    _hasDoubleJumped = true;
    }
    Other than that, muddling through the rest was pretty easy.
    Thanks again Chris!

    • @markallieu7097
      @markallieu7097 6 місяців тому +1

      hey, I used C# in Godot and has been stuck for the past few hours, thank you so much for your comment! this really helped me through this video, thank you really

    • @Andrei_Bush
      @Andrei_Bush 5 місяців тому

      Appreciate it very much, kind humanbeing :)

  • @iswhatheis
    @iswhatheis 9 місяців тому

    Subscribed, good voice for tutorials I hope to learn a lot here

  • @venny1689
    @venny1689 Рік тому +19

    I would like to point out using animation trees is honestly not the best for sprite animations. The point of animation trees is that they allow to set up transitions but you don't need that in 2D games since sprites cannot be blended like 3D animations can. You already have a state machine setup which is perfect to use with an animatedsprite node. The only advantage of creating animations through the animationplayer node is that you can trigger signals / call methods midway through an animation, but it's likely not worth the work for most people.

    • @felixw976
      @felixw976 2 місяці тому +2

      Thank you for this comment! I am working on a small 2D game and have been using the AnimationPlayer all along, wondering why its better to use an AnimationTree, when I have to declare each animation in the State Machine anyway...

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

      Concur

  • @The_Foreman
    @The_Foreman 5 місяців тому +5

    If you decide to include slopes, and have the problem of entering an Air state when running down hill, add a RayCast2D pointing down a bit past your feet, and use if it's not detecting anything to enter the ground to air state.
    stateprocess in GroundState would look roughly like this
    @onready var ray_cast_2d = $"../../RayCast2D"
    func state_process(delta):
    if ray_cast_2d.get_collider()==null:
    playback.travel(double_jump_start)
    next_state = air_state

  • @min0itsgaming299
    @min0itsgaming299 3 місяці тому

    Bro, literally searching for this around a week all video come across are cut off and in-completed, your video made it bro tnx

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

    Awesome tutorial. Hoping you'd make more tutorials on 2d platformer.

  • @user-jr2lr9sq3p
    @user-jr2lr9sq3p 3 місяці тому

    Super cool, thanks man

  • @d_atura
    @d_atura Рік тому +1

    Amazing tutorial! I have one question tho: when working the jump of the character you said that it's better to set jump velocity inside the state. Wouldn't it be better to set it in the character script so the state can get different speeds depending on the character chosen? I think it would make for better composability. Also it feels better to just control all character variables from the character node instead of the state.
    Any way, thanks for the great video, will be referring back to it multiple times for a long while

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

    Very good tutorial.

  • @Alriightyman
    @Alriightyman Рік тому +1

    I'm actually using an AnimatedSprite2D and an AnimationTree. In my scenario, I have 2 spritesheets - one for basic movement and the other for battle related stuff. I use the AnimatedSprite2D to be able to load both spritesheets with with the desired sprites, but I don't use it for the actual animation playing. I use the AnimationPlayer/AnimationTree to handle my actual animation by setting key frames on the AnimatedSprite2D "Frame" property and "Animation" property (to select the group of sprites I am interested in).

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

    Very nice tutorial. Inspired by your video, I have some questions about AnimationTree. Could I check if an AnimationNode can travel to another specific AnimationNode (eg. return a bool)? Additionally, is it possible to obtain the entire route to know the node sequence (eg. move -> jumpstart -> jumpend) ? Thanks for your share.

  • @di4352
    @di4352 Рік тому +5

    I made a mistake in the code somewhere and the character won't jump, and at first it just wouldn't do the jump animation on the first input and would go into the air animation on the double jump. Now it won't even move or jump at all, it's stuck in place. I tried to get the Part 2 code from your "Download Project" link to compare to my project, but it appears to have been a duplicate of the Part 1 project. I followed the video, but couldn't complete this tutorial stage. Could you update google drive with the correct files?

  • @timbob1301
    @timbob1301 Рік тому +1

    Thanks for the great tutorial! How do you handle a "Hurt" state, which is triggered by an external influence, e.g. the mob detects a collision with the player and calls hurt() on the player?

  • @Koden
    @Koden Рік тому +5

    25:39 Is there a reason in line 10 that we are making an array of the states in the CharacterStateMachine? I don't see us using it anywhere.

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

    I've been following your steps since your first video and it really helped me ( i have 0 prog background but really want to develop my own game)
    I was wondering how would you integrate the falling loop animation for when you drop from a floor so it doesnt stay on the iddle animation, where would you integrate this in your machine state
    I dont know if you're gonna read this ahah

  • @justinmoore4946
    @justinmoore4946 Рік тому +2

    Just a thought but with the direction you provided if the player presses up or down while moving even though there is no movement for it, it will slow the player down.
    I would use direction.x = Input.get_action_strength("right") - Input.get_action_strength("left")
    Love the series so far!

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

      You can also use Input.get_axis("left", "right") which is just short-hand for what you suggested.

  • @gogglebobb
    @gogglebobb 4 місяці тому +1

    Honestly, this tutorial has crushed my soul.
    Maybe its just me, but he keeps saying how much simpler and easier this is, but it's the exact opposite for me. Literally, every step breaks my game, and I have to stop and spend like half an hour trying to figure out what went wrong or why I'm recieving an error while he breezes on with an "and that seems to work just fine" ... I've been trying to follow this single video for about 3 days, and I've only gotten about 45 minutes in. The animation player is breaking every couple minutes. The animation tree seems like a useful tool, but I haven't found a situation yet when it actually feels like its made animating a 2d pixel art sprite any easier or better. I need to take a break. I'll come back later because im really hoping that I can save my project because, as of right now, the whole thing is broken.

  • @mountainwhale8173
    @mountainwhale8173 5 місяців тому +1

    should i start with this tutorial first before doing the attack tutorial?

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

    Thanks bro

  • @KryFuZe
    @KryFuZe 9 місяців тому +1

    The animation tree is getting set back to idle but the animation stays on run and just stops instead. Nothing is working.

  • @smash6368
    @smash6368 10 місяців тому

    Thanks for the video! I have a question. When I tried it up to 35 minutes It doesn't seem like the function state_input is ever being read. Is there any reason for that?

  • @rendcycle
    @rendcycle 10 місяців тому +2

    What if I have a "Run" animation aside from "Walk"? How do I set it up in such a way that if the Speed of the player reaches or goes over a max value, the animation will switch to run? Player animation will then switch back to walk if he slows down that max value?

  • @JoaoNeto-up8zi
    @JoaoNeto-up8zi 6 місяців тому +5

    This is much more complex than the previous tutorial. Not because of the coding but the way it mixes everything up in a back-and-forth that loses meaning easily and leaves no space for improvisation. Are we sure this is the best way to handle 2d sprite animation? Seems like the cost benefit of doing all this to get the exact same results as the simpler solution is not worth it.

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

    Very good tutorial, the state machine works nicely for me. I tried to simplify the jumping process but just cant get it to work, i want to have a simple jump animation that plays whenever the character is in the air but I just cant figure out how to make it work with the animation tree

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

    how do I implement the starting point? I tried starting from where I left off in the previous video but couldn't resolve some bug as it does not exactly tell me why I went wrong, only that something was. So now I want to try the quickstart but I want to know how to actually add it in before I try anything.

  • @db3d607
    @db3d607 Рік тому +2

    if you could go over the state machine again I would appreciate it.

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

    Would you be able to do a video on doing this for a top down? 😢 can't find a tutorial on it anywhere, it's just all for platformers or a really old version that the methods don't work anymore

  • @berndo3038
    @berndo3038 5 місяців тому +2

    I don't get the logic on the "switch_states" function. We can only ever enter that function when the current_state.next_state has a value so then why do we immediately check if the current_state is null? We would never have been able to enter the function if that was the case. In fact, the program should crash if the current_state ever was somehow null because the conditional in _physics_process would be checking for the property of a null value.

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

    I'm assuming you could go a bit more ECS by embedding states and data into nodes and iterating at a higher level

  • @mrmisplaytcg
    @mrmisplaytcg 9 місяців тому

    Took me a whole day to follow this tutorial with lots of user errors but I did it! One question is if I have some slopes, the Character will be switched to Landing as it kinds of is in the air a little, how can I program it to still be on the floor?

    • @rubenkoch6455
      @rubenkoch6455 5 місяців тому

      If your using the is_on_floor() function you can set the slope it recognizes as a floor, so if it is 45 degrees or more it will not see it as a floor!
      you can probably search how to set this using the search function in the godot editor!

  • @mr.catface-2635
    @mr.catface-2635 Рік тому

    I have the state transitions and the jump/double jump/landing animations working but my idle and run animations are never playing. Ive checked the project on the github and all of my code and nodes appear to be the same, but only the github project correctly plays all the animations. Im not sure how the idle and run are working in the one on the github since I don't see them ever get called or used in any of the scripts. I would appreciate any advice on how to fix them

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

    I just want to know how to use the animation player using the individual sprites not the whole sprite sheet since i dont have sprite sheet in my files only individual sprite for individual animations per frame. Any suggestions?

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

    how would you go about syncing state in a multiplayer godot game, general strategy.

  • @Koden
    @Koden Рік тому +4

    26:35 Not sure if it's mentioned anywhere but another way you can get it to show is by closing the player tab and reopening it, it's just that it needed to refresh the information, that would be faster than redoing it for each State.

    • @antleredwolfstudio
      @antleredwolfstudio Рік тому +1

      Thank you, I was having this issue even after dragging all of the scripts back into the script holders. This fixed it.

  • @jellygingy8115
    @jellygingy8115 4 місяці тому

    at 17:22 couldn't you also just flip H in the animation player to make the character face that direction instead of coding it? Or is there drawbacks in the future for doing that?

  • @raoinshishiza152
    @raoinshishiza152 Рік тому +5

    how did you add the backdrop?

  • @placidopenitente5434
    @placidopenitente5434 4 місяці тому

    If I wanted a falling animation to play whenever the player is in the air when the player didn't jump (basically entering the air state without jumping) how do I adjust the animation tree to fit in a "falling" animation and how do I get it to play whenever the player enters the air state by falling?

  • @Pixelbean275
    @Pixelbean275 6 місяців тому +1

    Hey, thanks for the tutorial! I am making a 2D platformer game, but I have transition animations e.g. a "start run" animation for transitioning between idle and run, a "turn" animation for transitioning between facing left and right, and a "landing" animation for transitioning between fall and idle. How do I use the AnimationTree to implement all of these? Thanks!

    • @Pixelbean275
      @Pixelbean275 6 місяців тому

      I think a good example of a game with the same animation aesthetics is "Phoenotopia"

  • @shmoopey1650
    @shmoopey1650 Рік тому +1

    Hey Chris, I'm interested in godot but I prefer C#. Will you be making any C# tutorials?

    • @ChrisTutorialsYT
      @ChrisTutorialsYT  Рік тому +2

      Possibly. I'm used to C# from Unity as well. Gdscript is better supported in Godot. For instance, C# class names arn't recognized for Resource files when trying to add a resource to your project folder but they are with gdscript. I'll keep in mind that you're interested in some C# tutorials for Godot going forward. Thanks for the comment.

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

    It would be so cool if they had an "Import to AnimationPlayer" option in AnimatedSprite. Doing this manually for the number of animations I have already seems kinda tasking. At least I'll only have to do it once.

  • @rafic1214
    @rafic1214 Місяць тому +1

    Can some one help, when I hover over the Add Animation it doesn't show me any options instead a small empty bar maybe 1px thick (the step at time 12:00 ) i reviewed and compared my steps with the tutorial on the idle and run animations 3 times and nothing . i am working on what i did from the previous tutorial ,if i have to use the versions provided in the description i cant (Ko-fi's not available in your location) . if someone can point if and where i made a mistake i would be thankful .

  • @wyattbiker
    @wyattbiker 4 місяці тому

    What is the logic that goes into deciding states? Why not choose each state by the animation names? E.g. walking, running, jumping up, landing, attacking, idle etc.

  • @Psydefex
    @Psydefex 5 місяців тому

    im having an issue where my character stays in the last frame of the landing animation after landing , but i am switching back to ground state, just not able to play the run animation for some reason
    .. not sure what i did lol i have no idea how to program

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

    Is this really easier than just typing out a character movement script to control it all? It's just a 2D game. Will there be that many animations where you need a web like this?

  • @sawyheartgames2161
    @sawyheartgames2161 Рік тому +1

    I love it, very good tutorial! It's really fun to work with a statemachine. Just one question: how would you handle an event that needs to be handled in all the other states in much the same way?
    Let me give you an example: by pressing a key I switch to the dash state, but this change I can do from all other states, such as: jump state, ground state, falling state...
    maybe when the code to determine the transition to the dash state starts to get more complex and when there start to be many more states, going to add the code in every state seems unfeasible to me.
    I thought of two possible solutions: add the code in the abstract state class so that the super can be called in the child classes that need it; or handle it from the main Player script.
    What would be your approach? thanks :)

  • @SuperVillianStudios
    @SuperVillianStudios 7 місяців тому +2

    I have a really inconsistent delay when trying to move left or right. I tried moving around the "update animations" but I cant get it to be more responsive. Any ideas where I went wrong

    • @JoshColter
      @JoshColter 5 місяців тому

      my character no longer moves left or right at all, did you end up figuring it out?

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

    For anyone saying it's not working for them, I'm using the latest version of Godot and it worked fine for me. The issue I have is, why would the landing state stop you from moving? It doesn't feel very good and even if you set can_move to true then you still can't jump again until the landing animation is finished. Does this get fixed in later tutorials?

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

    At 52:07, I don't have anything like the "Advance" option anywhere. Is this something that changed in Godot 4.2b? Also, there is no "Switch" option. I cannot find the AnimationNodeStateMachineTransition either. What's going on here? What I see is AnimationNodeAnimation, and further down Animation, Play Mode, Resource and Script. Nothing else.
    EDIT: Ok I see, you clicked the line, not the animation to get the option Advance.

  • @pomeroytv895
    @pomeroytv895 Рік тому +1

    So my nodes scripts aren’t generating the can_move boolean in the inspector for me. I have tried re-adding the scripts but that doesn’t get them to pop up for me like they do @ around 27:34. My class names and CharacterStateMachine script seem to match

    • @pomeroytv895
      @pomeroytv895 Рік тому +2

      I figured it out. I did not set my scripts to inherit States properties. Recreated my scripts to inherit States instead of Nodes and they show now

  • @user-cd1wr6hg3t
    @user-cd1wr6hg3t 15 днів тому +1

    how can i make jump loop please its an important thing so when i fall without jumping it looks weird please any help🫤

  • @The_Foreman
    @The_Foreman 5 місяців тому

    I was really disliking the landing for the longest time. Mostly that the animation seemed to go on for so long after we had landed. The truth of the matter was that the animation was playing after the fact. How to fix? Add a RayCast2D. Surprised at how useful these things are. I borrowed the one I was already using for slope handling, and used that to trigger the switch into the landing state, allowing it to start playing sooner.

  • @nezqwe4818
    @nezqwe4818 9 місяців тому

    can someone explain me the on_enter() and on_exit. how does godot know when to call those?

  • @Mastersujo
    @Mastersujo 2 місяці тому

    Anyone know why animations are not showing in animation tree? I have them in player working but won't show in tree

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

    can you show how a variable jump is done through state machine? like it depends on how long you pressed the jump button?
    thanks

    • @rubenkoch6455
      @rubenkoch6455 5 місяців тому

      You can probably try combining the Input.get_action_strenght and Input.action_just_released and scale the jumping speed by the action strength and trigger the jump after releasing the jump button... Just a thought havent tried it myself!

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

    Thank you Chris for this series. Implementing a state machine definitely made it easier for me to add in hit and hurt boxes that worked.
    I have encountered a weird error though and I am hoping you or someone else might be able to help me solve it. When I run the project within Godot, everything looks and runs perfect. However, the web exported version of my game instead displays a black cube equal in size to the overall animation image size in the 2D view. This black box only appears when the state is idle, and I haven't had any luck yet figuring out how to resolve this error.
    CORRECTION - The black box appears when direction.x = 0. This line appears to be the culprit, specifically the direction.x callout. If I manually set that to anything other than the variable, being in the ground state at all makes the black box appear.
    func update_animation_parameters():
    animation_tree.set("parameters/Move/blend_position", direction.x)

    • @eorm4776
      @eorm4776 4 місяці тому +1

      In case anyone else ever has this issue, the incorrect display issue was appearing when I exported my game to WebGL. It was caused by the images I was using being larger than the max size allowed by WebGL. Changing them to less than 4096x4096 fixed it.

  •  Рік тому

    Thanks for tutorial, I am not judging the code quality which is imo not good but as a roadmap for API it does the job. (y)

  • @cynnful3461
    @cynnful3461 7 місяців тому +1

    Followed up to 45 minutes fine but then before state text section I tested game, but when I jumped it crashes and gives me errors in the jump function on ground state but it’s typed letter for letter like yours. Also says delta on physics in state machine script is unused

    • @soultaker76
      @soultaker76 6 місяців тому

      If you do not use delta in the function, change "delta" to "_delta". It functions the same but gets rid of the error. If you end up adding a delta variable in the function later, remove the _

  • @maellize9629
    @maellize9629 Рік тому +1

    I can also make a state machine for my player character using animatedsprite2d right ? I find the animation tree pretty confusing, and since you have to manually code parameter and stuff, I dont really see what it improve

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

      and thanks for the tutorials ! Its helping me a lot

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

      @@maellize9629 I feel the same way, nothing much has changed from the last video, the player does all the things we already coded, how does this improve upon what we did in the last video? But still, thanks Chris for the video us noobs really appreciate it!

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

      @@chelsiekristyn589 I understand that its really nice for complex pattern tho, but for a idle + jump + run I felt like it was unnecessary.

    • @WalkerRileyMC
      @WalkerRileyMC Рік тому +3

      When you get into more advanced coding you'll find state machines to be a god send. You're scratch the tip of the iceburg here. So you might as well learn how to use them on something simple so when it comes time to add in more complex concepts you'll have the foundation already there.

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

      @@WalkerRileyMC Thank you that actually helps a lot! :)

  • @The_Foreman
    @The_Foreman 5 місяців тому +1

    If you drag one of your scenelist's objects into your code it will autofill how to reference it. Holding CTRL when you're dropping it will auto generate a variable. NOT while picking it up though, which always catches me off guard.
    as for how to get parent objects:
    $"." = self
    $".." = parent
    $"../.." = parent's parent (grandparent?)
    $"../child" = sibling
    $"../../child" = grandparent's child

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

    I do exactly as you do but I get some differences. I don't know, maybe you do something in between the records or I just get lost sometimes. When I play the game I get two characters overlapping, you don't have it. In AnimationTee>Parameters>Move> you had 0.025 value by default while I had it as 0 and I don't know if I should switch to 0.025 or keep mine 0. All this feels like I am not sure if I am doing everything right and just keep going in wrong way and want me to drop the tutorial. Everytime I run the game to test I see double character which makes me feel bad I messed something and I don't even know how to correct it. I look on your screen and it seems we have everything the same - it's frustrating. And on top of that, the previous lesson was how to set the animation, it took like hour to do and this video starts with "lets forget it and do it again different way" so it feels like we are moving backwards with this tutorial while other tutorials always get me a feeling of progression and don't throw me back which makes me fight the urge to drop the tutorial. You are 100x better than others in explaining and you get a lot of knowledge but I just felt like sharing my impression on working with the video, I hope it won't hurt too much.

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

      for the thing where you have 2 characters over lapping just click the eye next to animated sprite node to make it invisible

    • @guardian1243
      @guardian1243 5 місяців тому

      The double character is caused from you not clicking hide on the AnimatedSprite2D, and the AnimationTee>Parameters>Move doesn't seem to change anything

  • @shinsoataraki
    @shinsoataraki 4 місяці тому

    delta and event is never used idk why, I guess it's the update since you are using godot 4 while some of us are already using godot 4.1 or 4.2

  • @MrAleksander59
    @MrAleksander59 3 місяці тому

    Some textures have height 80 pixels, some of them 64, so all animations have different vertical height and don't want to centered it adequately.

    • @MrAleksander59
      @MrAleksander59 3 місяці тому

      I solved it by adding "offset" value to all animations, so they will shift in needed positions.

  • @alejo1003ful
    @alejo1003ful 11 місяців тому

    tengo un error en la linea 3 del landingstate, copie el codigo tal cual el video y de algun modo hay un error
    "Expected end of statement after variable declaration, found "Literal" instead."
    code: @export var landing_animation_state : String "landing"

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

      Olvidaste el signo igual. Debería leerse como
      @export var landing_animation : String = "Landing"
      You forgot the equal sign. It should read as
      @export var landing_animation : String = "Landing"

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

      @@eorm4776 oh gracias, aunque quizas hubiera sido util hace 4 meses XD, estoy considerando reconstruir todo mi juego de 0 luego ya que de todos modos no lo tenia muy avanzado

  • @JoshColter
    @JoshColter 5 місяців тому +1

    My guy seems to be locked in place, No longer move left to right.
    -while in ground there is no h.flip or movement or animation
    - character jumps fine
    - set to "can move" in ground & air not "landing"
    - the States transition well with the label.
    - When turning off can move on "ground" the animation "run" plays but with no movement.
    - can slightly "glitch" it to flip.h right after leaving ground but only animation plays
    - tried checking the State transitions and they all look good.
    - Messing with the Ani-Tree just to see if I can get another outcome to narrow it down
    I'm messing around with everything && I mean everything trying to free my guy from this code prison I've trapped him in... please comments section you're my only hope before I delete this all and restart......... was what I was going to post until I figured out a solution.. well I think at least.
    my solution was that I changed every "landing Animation" to a single named animation including the animation tree ending name. idk what the issue was with it before tbh, it all was named "fall" the same in my code as well. I made another animation that ended up changing the forms my character was stuck, changing the animation made it not able to jump but was able to run in place. im not quite sure what I did to fix it but, I am working a bit off of my own code and trying to fit this Machine in, it could have been some of the ordering in my player script even though I deleted everything and copied line for line what was in the video and in the link to make sure absolute accuracy (other than my Ui inputs). In the end I brought back my original code and enabled what I thought was an irrelevant line at the bottom that had to do with an attack I was trying to implement and it strung together maybe its ordering or something else i dont entirely understand yet. ALL IN ALL, NEVER GIVE UP! there is always a way! thank you for the tutorial

  • @vanHale.
    @vanHale. Рік тому

    Because I am completely Fresher from the beginning, because in my country there is not much tutorials about Godot - especially Godot 4.0, so I started studying with your series. I really do not know the exact use of adding the Node Characterstatemachine when added. From my perspective when watching from the first video, I have not seen any significant difference since this node, in addition to we can divide the states of the animation in each different state to ease easily. edit and manage separately the parameters of the animation. Is this done aimed at updating more states later when the character has a bad effect/ buff, right? I don't know if I am misunderstanding the purpose and use of this node that you are conveying. My English is also quite limited (030) so I hope to receive your feedback!

  • @Maedros11
    @Maedros11 2 місяці тому +1

    How could you set up a Coyote timer with this state system?

    • @Maedros11
      @Maedros11 2 місяці тому +1

      Solution: Create a timer node, then when character is on the ground state, and then becomes not on floor, instead of switching to Air state, simply start the timer. After the timer times out, only THEN _on_coyote_timer_timeout() switch to the AirState

  • @niksopov4937
    @niksopov4937 6 місяців тому +1

    The tutorial is really amazing but I have one problem. I can't change from Ground state to Air state and I don't understand why. I am working on 4.2.1 version and I followed all the instructions that were in the video. Maybe the reason is that I am using another version but everything is similar to tutorial there. If anyone had problem like this please help)

    • @rubenkoch6455
      @rubenkoch6455 5 місяців тому

      What is your trigger for the change of states? Is your character getting of the ground? maybe your jump_velocity and or gravity are not calibrated enough. I had the same issue and tried printing my velocity.y to see how long it takes to return the characterbody to the 'ground'.

  • @stimulatesenses6014
    @stimulatesenses6014 Рік тому +1

    he is not double jumping... when i play

  • @leynieraragon9417
    @leynieraragon9417 25 днів тому

    I cant get passed 39 minutes due to an error that reads "Invalid get index 'velocity' (on base: 'Nil')"

    • @leynieraragon9417
      @leynieraragon9417 25 днів тому

      While this video took me a few days I finally got through it
      there is still so much I dont understand but I do feel like I've learned so much.

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

  • @Justprince1452
    @Justprince1452 5 місяців тому +2

    For a beginner my brain is so cook try to understand soo many things

  • @LiamRodriguez1967
    @LiamRodriguez1967 Місяць тому +2

    There are so many things wrong with this tutorial ... Hard to even recommend following it anymore. Ive spent well over 5 hours troubleshooting the problems and errors i get from following this video. Ive tried following the video over the course of 3 days and every day just feels more hopeless than the last.

  • @jamsd20
    @jamsd20 6 місяців тому

    I need help from anyone - when following the guide PERFECTLY I got to the point where he has coded the ground to air state and he plays the game and presses jump, for me it crashes and I don't know why

    • @ThisTimeIsForMe
      @ThisTimeIsForMe 6 місяців тому

      did you ever figure this out because i'm having the exact same problem! "cannot call static function "is_on_floor()" on the class "CharacterBody2D" directly. Make an instance instead."

    • @jamsd20
      @jamsd20 6 місяців тому

      @@ThisTimeIsForMe sorry I have not, I gave up and found a different guide

    • @Chonkster33
      @Chonkster33 6 місяців тому

      My issue is that I can't jump at all, following the code perfectly still had the same results sadly. What tutorial did you find for this issue?

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

    imma give u a kiss if you will make an upside camera tutorial like Stardew Valley game

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

    i think that i done somethg wrong becouse i cant jumap, and its not change my state from ground = air. cant fix it :(

    • @cynnful3461
      @cynnful3461 7 місяців тому +1

      I’m having same issue, figure it out?

    • @ThisTimeIsForMe
      @ThisTimeIsForMe 6 місяців тому

      @@cynnful3461 did you fix it? lol

    • @cynnful3461
      @cynnful3461 6 місяців тому +1

      @@ThisTimeIsForMe no lol. I just copied his finish project from this section, and moved on. It definitely didn’t look any different than mine and rewatched vid like 8 times

    • @Chonkster33
      @Chonkster33 6 місяців тому

      ​@@cynnful3461that's so real, I've been working on the same issue for a whole day and getting stack frame errors even though the code is exact lol

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

    Why do characters in 2D platformers always breathe so heavily when they don't move?

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

      Being flat there's not much volume in their lungs, so they must breathe deeply 🤣

  • @princessbitch96
    @princessbitch96 3 місяці тому

    Every delta you've told me to put in Godot says that they never use deltas it the function... Also It tells me that I can't call is_on_floor on a nil value?? I followed your tutorial to the tee... I think your video needs to be updated. Cause I didn't learn jack shit seeing that the code doesn't even work. It worked at first then I got towards the end and everything broke.

  • @yaroslavus7380
    @yaroslavus7380 11 місяців тому

    39:53

  • @Grizz-909
    @Grizz-909 2 місяці тому

    3:06