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! - Навчання та стиль
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
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.
is there a git repo for this tutorial?
Oh my, what sorcery is this? Are you reading my mind? hahah This is exactly what I needed right now.
Thank you, HeartBeast!
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.
Thanks!!!
I put NEW_DIRECTION under my ready function, so it chooses a new direction upon starting, first, before anything else.
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!
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.
most short/concise/simple/effective state machine video out of all of them. Thanks!
Thank you so much for this! You explained everything in this video amazingly!
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 ❣️
One more thing can i add animation when moving?
Thank you for this. I'm looking forward to your Godot course!!!
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 :(
@@vatrenikrug lol
Learned tons on this one, thanks sir!!!
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".
help i want to know the differences between this and Godot's animation tree node
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
i hust wanna ask how to make signal when state is choosen and when is choosen then change scrip
Seus tutoriais são muito bons, eu aprendo Godot e aprendo Inglês.
Um br (・∀・)
ok thanks, will be using state machines soon
awesome tutorial!
Great video man! Might end up trying the program soon!
Noice
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
sir, what can i code so that npc can detect collision
Pledged. Can't wait for the couse :)
Thank you!
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
this is so good, thanks
Good tutorial taste good
This isss exactly what i neeeddddd!!!!
Can you make one for Godot 3.2?
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.
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.
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.
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.
언제나 큰 도움이 됩니다.
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?
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).
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.
GOOD MORNING AFTERNOON
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?
When the AI changes directions, use this ^^ sprite.flip_h = true
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.
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.
Same here, did you find a solution yet ?
@@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.
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()?
no there is not
I think he was just being conceptually verbose
Readability
Nice !
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.
Unfortunately, my NPC does not seem to be changing states. It just moves into the right forever.
you can watch video on inheritance by kidscancode its about npc
I was actually looking into fsm =)) great
Perfect timing then :)
Buen tutorial
lol I actually handle my player movement with position += direction
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.
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.
@@uheartbeast I see. I never played Pokemon.
@@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.
Cara, você é genial, muito obrigado!
The tutorial has the State Pattern but not the State Machines it self...
Should I use this or this method? ua-cam.com/video/Ty4wZL7pDME/v-deo.html
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.
So, is this channel 100% only Godot now?
I'm hoping it is...
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.
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.
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.
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.
@@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...
@@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.
@@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!
@@GrumpyOldBastard. Never to late when my problem as not been solved yet . I will see if it makes a difference.
Wow....It works!!! Huge Thanks to you! Gracias! Merci ! Arigato gozaimasu!