Godot 3 Tutorial - Simple State Machines

Поділитися
Вставка
  • Опубліковано 22 лип 2024
  • The 1-bit Godot Course by HeartBeast: www.kickstarter.com/projects/...
    Follow me on Twitch for gamedev livestreams: / uheartbeast
    Twitter: / uheartbeast
    Facebook: / heartbeast.studios
    Tumblr: / uheartbeast
    Thank you all so much for your support!
  • Навчання та стиль

КОМЕНТАРІ • 95

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

    Here is the Kickstarter! Hope you enjoy the video! More Godot tutorial videos coming soon!
    The 1-Bit Godot Course by HeartBeast: www.kickstarter.com/projects/heartbeast/a-1-bit-godot-course-by-heartbeast

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

      I've wanted to know something for a while now, but I'm not getting any results on google...
      what happens if I program my player to move with the keyboard WASD keys, and I put my game on android?
      what controls would I have to code for my game to work on mobile devices? btw the game is a 2d game that's similar to Mario.

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

      is there a git repo for this tutorial?

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

    Oh my, what sorcery is this? Are you reading my mind? hahah This is exactly what I needed right now.
    Thank you, HeartBeast!

  • @Dustpetro
    @Dustpetro 4 роки тому +18

    Btw, if anyone is wondering how to fix the first direction the npc moves in when the game starts: add the following into the ready event after randomize() -- direction = choose([Vector2.RIGHT, Vector2.LEFT, Vector2.DOWN, Vector2.UP]) this will keep it from moving right every time it starts up.

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

      Thanks!!!

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

      I put NEW_DIRECTION under my ready function, so it chooses a new direction upon starting, first, before anything else.

  • @jadegamestudio4639
    @jadegamestudio4639 4 роки тому +8

    thank you for this very straightforward and well explained video! this is the best godot state machine video on youtube.
    all the other existing videos are unnecessarily complicated and almost unusable except for their own projects. one even forces you to create a hierarchy of nodes! hows that for reusability!
    again, thank you!

  • @FirstNameLastName-wg8ld
    @FirstNameLastName-wg8ld 2 роки тому

    So I meant to use this as a state machine guide to refresh my memory on how they work after watching your action rpg tutorial, however, now I'm working on a simple clicker game and I was given the idea to make the button move around over time, so I used this script and (with the addition of nodes and some slight modification to the code) it worked!
    Thanks, HeartBeast, and good luck with your game.

  • @aloufin
    @aloufin 4 роки тому +6

    most short/concise/simple/effective state machine video out of all of them. Thanks!

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

    Thank you so much for this! You explained everything in this video amazingly!

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

    Oh i never thought this is what ive looking for and i just leave it and put it in the playlist so i can comeback and search for another video about random npc movement and i just now realized that this video is all about what im looking holycow thank you so much ❣️

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

      One more thing can i add animation when moving?

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

    Thank you for this. I'm looking forward to your Godot course!!!

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

      Can you plase copy paste your code :( i have problem in last part with timer, something i miss spelled and i cant find it 3 hours now :(

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

      @@vatrenikrug lol

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

    Learned tons on this one, thanks sir!!!

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

    I tried to add rotate to this and had the issue of Vector2 could not be converted to a Float. I tested a boulder rotating in the same direction as "direction".

  • @cmds.learning7426
    @cmds.learning7426 4 роки тому +1

    help i want to know the differences between this and Godot's animation tree node

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

    I really like this. I have been struggling to understand state machines. I think this breaks it down just enough. That said Can you include like for instance Detection? aka if the AI detects the player, and attack if say it is an enemy NPC

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

    i hust wanna ask how to make signal when state is choosen and when is choosen then change scrip

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

    Seus tutoriais são muito bons, eu aprendo Godot e aprendo Inglês.

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

    ok thanks, will be using state machines soon

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

    awesome tutorial!

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

    Great video man! Might end up trying the program soon!

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

    howdy hey, would there be a way to add animations using an animation tree to this state machine? if so how would that be possible

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

    sir, what can i code so that npc can detect collision

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

    Pledged. Can't wait for the couse :)

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

    I make games as a hobby and recently migrating from Game Maker Studio to Godot (in love with this engine), your videos is helping me a lot! Thank you so much :D

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

    this is so good, thanks

  • @Nickname-lm7ch
    @Nickname-lm7ch 2 роки тому

    Good tutorial taste good

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

    This isss exactly what i neeeddddd!!!!

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

    Can you make one for Godot 3.2?

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

    I guess after all times I mentioned to you on twitch caused you to create a tutorial on this. Thanks for sharing. This looks similar to a state machine I created before. The one I am currently would be different classes that can be called and modified at any time.

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

    Other tutorials seem to set up with the states on different child nodes, which didn't work for me. It seems the "enum" at the top is key to getting Godot to understand changing states from one to another, as my state machine wouldn't work at all until I realised I didn't have that line of code. Then I just added a line saying "state = (name of your state)" and it switched up like clockwork.

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

      If you look at the 2D platformer tutorial that comes with Godot, it has a state machine with no "enum", so maybe you don't need one. But it fixed my crappy code that I hacked together from 3-4 different tutorials.

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

    Nice and simple, good job. If I were to nit pick, and this doesn't really matter unless you have a lot of these NPCs running at once, but shuffling a whole array to only gather one entry is a lot less efficient than just generating a random index. Though I realize in Godot you would then need to setup a generator, etc., which is kind of annoying.

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

    언제나 큰 도움이 됩니다.

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

    Cool! Quick question, enumerations are considered arrays then? Is this an issue to shuffle those? Like in other languages you can refer to the "index" of the values, are they changed by a randomize?

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

      So enums aren't really arrays. They are a list of "variables" (using the term very loosely) that each have an int value assigned. It usually counts up in order. so if you have:
      enum {
      Sunday,
      Monday,
      Tuesday
      }
      The value of Sunday would be 0, Monday would be 1, and Tuesday would be 2. They can't change value after (so really they are more like constants than variables).

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

      You could do:
      const Sunday = 0
      const Monday = 1
      const Tuesday = 2
      and get a similar effect but it would be more work and you could make mistakes and be off on numbers and such so enums are better for it.

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

    GOOD MORNING AFTERNOON

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

    Hey so i'm making an npc platformer ai and i used a vector2.right and a vector2.left for randomizing the movement but now i want the sprite to flip when he faces lift do you have a solution?

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

    Nice. I would think in most cases the state machine would be on the character since, if you had a lot of them in the world, it would get unwieldy otherwise. Learned a lot, though, thanks.

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

    This is really helpful, exactly the kinda thing I was looking for in order to create a wandering state for enemy AI. Specifically shuffling through an array of vector 3 directions. This works, however, after adding this to a kinematicbody3d and adding a collisionshape, it still doesn't collide with my player.

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

      Same here, did you find a solution yet ?

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

      @@elijahnyendwa2281 you have to use move_and_slide(velocity) for kinematic bodies. If you just move them by position, it's just going to ignore physics.

  • @Alche_mist
    @Alche_mist 4 роки тому +2

    Is there a reason (like some hidden performance reason or whatnot) you chose array.front() instead of the slice array[0] ?
    EDIT: or even array[randi()%len(array)], removing the need to call shuffle()?

  • @5minutemovies977
    @5minutemovies977 4 роки тому

    Nice !

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

    Hi Benjamin, first of all thank you for these tutorials really help me a lot.
    I would like to ask if you could upload a tutorial about enemies or traps by harming the player.

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

    Unfortunately, my NPC does not seem to be changing states. It just moves into the right forever.

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

      you can watch video on inheritance by kidscancode its about npc

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

    I was actually looking into fsm =)) great

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

    Buen tutorial

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

    lol I actually handle my player movement with position += direction

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

    The NEW_DIRECTION state should set the next state as MOVE (nothing else), and the timer should change the state to either available states. Changing direction, then going IDLE is weird and unnecessary.

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

      Well, that isn't necessarily true. It sort of depends on the effect you want. For example, in the original pokemon games, NPC's would actually change directions without actually moving because direction could also affect the direction the sprite is facing not just the direction it is moving.

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

      @@uheartbeast I see. I never played Pokemon.

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

      @@yanfoo Haha no problem. I appreciate you keeping me in check, though. Getting comments that critique my work helps me to learn and make better videos in the future.

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

    Cara, você é genial, muito obrigado!

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

    The tutorial has the State Pattern but not the State Machines it self...

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

    Should I use this or this method? ua-cam.com/video/Ty4wZL7pDME/v-deo.html

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

      I know I'm 2 months late, but it really depends on what you want to do. GDQuests's State machine is mainly used for player scenes while HeartBeast's approach would be better if you use it on an NPC.

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

    So, is this channel 100% only Godot now?

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

      I'm hoping it is...

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

      He said he might do some Game Maker video after the new GML features/changes but for now, it's just Godot because it is the engine he is using for his project.

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

    i've skipped to the end and i guess it's exactly what i need,
    What can be put under a state? Physics and animations or like practically everything?
    What defines a state machine, i wonder if i have written one that i dont know of when copy pasting shit.

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

      You could put anything you want in the state machine, because it's just switching between different functions. Basically a finite state machine is something that can choose exactly one state from a finite list of states.

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

    Hello! I set up a kinematicbody with this method but the thing go pass my tile map even though it as it's collision set up. What's the reason for that? Thanks.

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

      @@neolak168Hello! No. I use my tile in a tile map method. it doesn't use static body in this fashion i think. but i don't really know. anyway thanks. I suspect it has to do with script actually...

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

      @@susmiasyaefudin5000 A KinematicBody ought to be stopped by a tile that has a CollisionArea. Try checking the Collision Layer the tiles are drawn on, the Collision Layer the character is drawn on, and their Collision Mask.

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

      @@thomashalsted1888 Did that already. I check the layer and mask stuff. Was sure it was the problem but no it's not that. thanks anyway!

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

      @@GrumpyOldBastard. Never to late when my problem as not been solved yet . I will see if it makes a difference.

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

      Wow....It works!!! Huge Thanks to you! Gracias! Merci ! Arigato gozaimasu!