excuse me, i believe i might be have noticed an issue with this node-based setup, and i figured i'd ask to see if im missing something. i'm using this currently, in the process of setting up a very basic testing character. it has an Idle state, and if the player's Input.x variable is anything but zero, it calls switch_state from the StateMachine and switches to the Move state. in doing some debugging, i did a test where i called Engine.get_physics_frames() (gets the current number of physics frames that the engine has run in total) and it noticed something. If you have the game print the current physics frames immediately before calling switch_state, and then immediately before move_and_slide is called inside the Move state, the second call is 1 frame more than the first one. this seems to imply to me that, the point where the game detects the Input.x and switches states, to the point where the character is actually moved via move_and_slide, does NOT happen on the same physics frame (as i believe it normally does) Is this true? am i misinterpreting the numbers?
@dziwic2 күн бұрын
I would really love I you could say something about that x-com style ground highlight you did in your games. I'm uding AStar Grid and have collisions down, but struggle with that. That and textured lines, they work unitl I need to swap a texture.
@TheShaggyDev2 күн бұрын
For that piece, I have a tilemap with a auto-tiling / terrain set up so I just need to feed it all the tiles for an attack or movement and it displays correctly. As for figuring out *which* tiles to highlight, I just brute force it and check every potential tile within range. Not exactly elegant, but it's simple and works.
@thirteen36784 күн бұрын
Thanks man, this really helped!
@lautaromendieta90865 күн бұрын
Use assert(), it's like push_error++ (pauses the execution when the given condition equals false)
@lautaromendieta90865 күн бұрын
This is so powerful, mainly for SceneTreeTimers, Tweens callbacks and signals
@tycho258 күн бұрын
There are appealing aspects to this approach, but I really don't like how much you have to repeat your code if you want certain behaviors like movement to be available in more than one state. This gets messy if you have more complicated logic that you want in more than one state but might change later. If I have a complicated object, I like to add an additional layer of sub-states as children of the states which all run in parallel. For example, you can have a "jumping" state consisting of the "jump," "walk," and "run" sub-states, so while the object is in the "jumping" state, they are able to use all of those abilities at the same time (in this case allowing the player to move while they are jumping.) This modular approach makes it easier to modify the behavior of the substates and have your changes apply across the board if needed.
@Zewofficial9 күн бұрын
New sub! Great stuff!! Im a noob into 2D godot. Keep it up!!
@adomasjarmalavicius280810 күн бұрын
things have changed in two years, but it still holds up, thank you for the great video!
@jhyoon917411 күн бұрын
Great video, I learned exactly what I was looking for!
@aussiescorner395411 күн бұрын
Question, can something like this be used to allow the player to write scripts to run in the game that are more then 1 command long? More or less I'm trying to create a mechanic like in "The Farmer was Replaced"
@TheShaggyDev11 күн бұрын
Technically, I believe that would work, but you may not want to give the player full access to run code in your game using this method, at least not without being very careful about how you implement it. You wouldn't want them to be able to trigger Steam achievements, change internal values they shouldn't be changing, etc. Not saying it can't be done, just that you'd need to be mindful of your safeguards to prevent cheating.
@aussiescorner395410 күн бұрын
@@TheShaggyDev This makes sense. I'm just looking for a way to make certain objects be controlled by code that the player can write. Sorta like a programming automation game.
@TheShaggyDev10 күн бұрын
@@aussiescorner3954 Sure. I'm afraid I'm not exactly sure how you'd want to do that in Godot. I know Juan wrote about that on Twitter recently, maybe there's some insights there: twitter.com/reduzio/status/1811368725808918816
@aussiescorner39549 күн бұрын
@@TheShaggyDev Thanks I'll give it a look.
@rossmurphy459314 күн бұрын
at several times during this vid I found myself saying "dang that's smart". Great explanation. Sub earned.
@milesmungo14 күн бұрын
One thing I'm adding to my game is smash-style fast-falling. So the player can press the down button to fall faster. I think this is more relevant to action games that include air combat and an air moveset that's different from the ground.
@davariusaz15 күн бұрын
I don't see how this lets you reuse states on different objects. If you try to reuse your move state node on an object that can't jump, you'll have to make a new version of the move state script that doesn't allow transitioning to the jump state. Then when you want to tweak how the move state works for all objects, you'll have to make that same change multiple times for each object that uses it.
@CyonixOfficial16 күн бұрын
Hey so there arent any errors in the code itself, but when trying to run the game it gives me the error (Invalid set index 'parent' (on base: 'Node') with value of type 'CharacterBody2D(Player)'). Not sure how to fix this and any help would be greatly appreciated. (Also i've been mixing and mashing tutorials together so maybe that could be an issue)
@lexolotlgod19 күн бұрын
LOVE seeing your node structure. This is the most helpful kind of video.
@SaturnnsStash19 күн бұрын
As for the heirarchical states, i made a dash the same way you did, but since my move script changes its animation in process_physics() based on its current velocity.x, the dash animation is overriden after 1 frame with a movement animation. Any way i can ovveride that in the dash script?
@TheShaggyDev19 күн бұрын
Sure, just use the same techniques shown in the video. It'll depend on how you've got it set up, but you could, for instance, move your animation code to a function that dash state overrides.
@pippybrown363420 күн бұрын
Can confirm this works in Godot 4.2.2
@bunnybreaker21 күн бұрын
That dictionary tip is going to come in really handy. Got yourself a sub, thanks! 👍🏽
@hidingdissident25 күн бұрын
that was really a great video, thx for that! loving the quality! I"m wondering, have you found a good solution for showing movement range in a tactical combat system? your other videos often show highlighted tiles when selecting a unit so I guess you have. would you mind sharing your solution? or maybe just point me in the right direction. my current issue is that simply using the number of nodes in the path as a proxy for distance does not take into account that diagonal movement should be more expensive. i thought about using two grids (one without diagonal movement and one with) and comparing the path array size to infer the number of diagonal movement, but that seems stupidly expensive computationally. I wish the _compute_cost function would be accessible (rebuilding it seems kinda overkill)
@TheShaggyDev24 күн бұрын
I think it depends on what you need the distance info for. I'm lazy enough, and AStarGrid2D is fast enough, that what I personally do to highlight cells is just run a pathfinding query on nodes in the grid to see where you can move to. Then the diagonal movement is taken into account by AStarGrid2D, I can easily throw whatever obstacles in that I want by toggling nodes on/off, and there's no potential for bugs on movement since what you're seeing is what you'll get when you actually move. If you need an actual numerical value, I might just iterate over the output and calculate the node-to-node distance directly, which would inherently count diagonals as longer.
@Dkerza27 күн бұрын
Whats the difference between state.gd and state_machine.gd, the former doesn't have any owner of a node while the latter has whichs state_machine.tscn?
@TheShaggyDev27 күн бұрын
In short, state.gd handles the state-dependent logic where state_machine.gd handles coordination between states. So you might make a run state using state.gd, but let state_machine.gd handle transitions between states, dependency injection, etc.
@lloyd01172128 күн бұрын
this is cool. you should 100% expand on this.
@blairdog258129 күн бұрын
Wish I I woulda watched this before making my platformer physics based😅. I just can't make it feel good.
@HlebLegendaryАй бұрын
)ty a lot!)
@stevedowning3892Ай бұрын
Gold dust, dude! export_group and export_subgroup are going to come in incredibly handy
@BrokencircuitboardАй бұрын
Finally a basic explanation of fsm that i can understand. TBH, i never fully understand state machine even after watching many tutorial and sample project. You just make it all make sense. Turn up, i already using some kind of state machine in my project.. albeit primitive one 😆
@lukusridleyАй бұрын
i followed this tutorial but i implemented it wrong and now i've been locked in my room for 3 months and i can't reach the key to escape send help
@3bears744Ай бұрын
Woot! Much easier than in unity IMO :D Great tutorial, I was able to get this running fast!
@kieranjames2344Ай бұрын
Nice
@davisnoah347Ай бұрын
how do I create a State class that godot will allow my state scripts to inherit? Because right now I get "Invalid inhereted parent name or path." whenever I create a script for my classes that tries to extend my State class. I am at my wits end with this.
@TheShaggyDevАй бұрын
There are two ways to inherit from a class in GDScript. The easiest is to make sure that you have "class_name State" (or whatever the class name is) at the top of your script and then "extends State" in the script you want to inherit from. You can also just do "extends" with a path to the script, but that's cludgy.
@Shack263Ай бұрын
I watched this video and it's precursor a while ago, and couldn't recall anything from it besides using nodes as states. This weekend I made my own implementation before rewatching these, and I did a surprising amount of things the same way. It's probably a combination of my subconscious, and the fact that there is a natural solution in Godot using nodes. I will detail some cool differences below.
@Shack263Ай бұрын
Firstly, I made extensive use of custom component classes, such as a move component that moves a chosen physics body. Each state has export variables for the components it may affect (dependency injection). If one is left blank it won't error, so there is some flexibility. I also tried decoupling transition logic from state logic. I made a separate class of state transitions which could be children of states. That way, the transition logic can be customised for each entity. For example, some entities may have additional states to transition to from idle. The idle state only manages what it needs for an entity to be "idle", not when to change to another state.
@Shack263Ай бұрын
I am exactly the 1000th person to like this video 😎. From now on, no one will ever know exactly how many came before them.
@mudinlangeАй бұрын
THANK YOU! I was going crazy dealing with Resources and it solved all the problems
@DGdevvАй бұрын
I still love this method of node based state machine but I don't know if it worth convert a godot 3.x project to the 4.x. the new interface looks really cool and helpful and I wanted so much to try it in my current project.
@saintadel8902Ай бұрын
For people getting null node error, you have to add 'transitions.tscn' to autoload, not 'transitions.gd'. Check your path again!!
@TheOpenWastesАй бұрын
Thanks so much for this. It took me three days to wrap my head around state machines, but thanks to your videos and downloadable examples, I've got state machines handling characters' actions in the game I'm working on
@TheShaggyDevАй бұрын
Glad I was able to help!
@mrussogamedevАй бұрын
awesome, thanks! Any directions for the range highlight that "shapes" around the walls?
@TheShaggyDevАй бұрын
No special sauce there. I grab every potential tile for an action, filter it as appropriate (line of sight checks, how many tiles to move to it once obstacles are accounted for, etc) and then use an autotiling layer to display the results of whatever is left.
@mrussogamedevАй бұрын
@@TheShaggyDev never thought about autotiling. Brilliant, thanks!
@mrussogamedevАй бұрын
Gold stuff
@PotatoPiano1Ай бұрын
Thank you!
@Kibble_BitesАй бұрын
Wow, this is actually a very informative video with a bunch of quirks I didn't know about... LIKED!
@gonderageАй бұрын
nooo he didnt mention the shortcuts to evaluate an expression(ctrl shift e) and copying or moving lines of code (ctrl alt down/up)(alt down/up)!!! sidenote: these might not work when preferring wayland, since it's broken on my linux laptop
@michelcosta76Ай бұрын
Godot has REGIONS? Oh thanks god for this information. I use them so much on my c# scripts and was missing them on godot (though I also should have checked)
@WeahlАй бұрын
Oh the prints() will save me a lot of time, thanks a lot ❤
@tjspeirs75Ай бұрын
Brilliant vid, definitely saving for reference 🙌
@GTheepicguyАй бұрын
Dude thank you so much this is amazing information to have!