Game Programming Patterns in Godot: The Command Pattern

  Рет қаралды 14,738

GameDev w/ David

GameDev w/ David

Күн бұрын

👉️ Learn how to implement the Command pattern in your Godot game!
Discover the Command pattern and other essential game development patterns with the book "Game Programming Patterns" by Robert Nystrom. Buy it now here: amzn.to/3QhtkSY
Alternatively, this generous author has made the entire contents of the book available for free on his website: gameprogrammingpatterns.com/
(Disclosure: As an Amazon Associate I earn from qualifying purchases.)
🔔 Subscribe:
Subscribe to my channel to see more videos like this:
www.youtube.com/@GameDevWDavid...
📖 Useful resources:
- Assets used in this tutorial:
Medieval Fantasy Character Pack: oco.itch.io/medieval-fantasy-...
Oak Woods - Environment Asset: brullov.itch.io/oak-woods
🔵 Follow me:
Find out about my latest videos and publications:
/ gamedevwdavid
mastodon.social/@GameDevWDavid
davidserrano.io/
⏳ Timecodes:
00:00 - Introduction to the Command pattern
01:21 - The Game Programming Patterns book
02:06 - What we want to achieve
02:53 - Creation of the commands
05:55 - Creation of the human controller
09:21 - Creation of the AI controller
10:43 - Putting it all together & final result
13:42 - Conclusions about the command pattern
---
Music credits:
Track: Alexi, Action, Infraction- Witch's Whispers
Music provided by Infraction No Copyright Music
Spotify: bit.ly/3DY8YYc

Пікірлер: 42
@GameDevWDavid
@GameDevWDavid 8 ай бұрын
This video is a reupload from my other channel. From now on I will upload videos about video game development and Godot on this channel, subscribe to stay up to date!
@TeslasMoustache419
@TeslasMoustache419 8 ай бұрын
Phew, I thought it was gone for a second there!
@GameDevWDavid
@GameDevWDavid 8 ай бұрын
@@TeslasMoustache419 Apologies! When uploading this one I had to delete the previous one, and there was a period of time where there was nothing uploaded, but now it's done =)
@Yoni123
@Yoni123 4 ай бұрын
game at 0:18?
@DavidSerranoIO
@DavidSerranoIO 4 ай бұрын
@@Yoni123 Blasphemous II
@Yoni123
@Yoni123 4 ай бұрын
@@DavidSerranoIO no the other one
@angulinhiduje6093
@angulinhiduje6093 7 ай бұрын
absolutely phenomenal lightweight video. im working on my first project and was looking on how to implement grid based tactics characters. characters can get captured by either team so this makes that aspect very intuitive. i just changed player_controller to character controller and command all characters on the screen like that. and even better if i want them to walk to certain spots on the map after special events i just have a neutral AI that just sends a grid coordinate and lets the player code handle the pathfinding. thank you!
@GameDevWDavid
@GameDevWDavid 7 ай бұрын
The Command Pattern works like a charm in board/grid games as you mentioned. I'm glad it was useful to you! And thank you very much for watching the video!
@danielsepulveda219
@danielsepulveda219 8 ай бұрын
Very instructive video about the command pattern in godot!
@GameDevWDavid
@GameDevWDavid 7 ай бұрын
Thanks for the compliment!
@joggerjoe
@joggerjoe 3 ай бұрын
ty for this video. helped a lot for my first gamejam. wanted to have ai-controlled characters. made a base-character getting controlled by different types of controller. works fine.😊
@GameDevWDavid
@GameDevWDavid 3 ай бұрын
Thank you for watching!
@Flamebamboo
@Flamebamboo 4 күн бұрын
Thank you :)
@GameDevWDavid
@GameDevWDavid Күн бұрын
You're welcome!
@gonderage
@gonderage 7 ай бұрын
Man, this is such a cool pattern; it's a bit complicated, but I can see why this could work at scale. Although, I wonder if instead of using a smelly stinky chain of if statements, the AI controller could just await finished signals from commands and timers like this: await get_tree().create_timer(seconds).timeout command.execute(...) # emits "finished" at the end await command.finished The AI controller might not even have to use _process / _physics_process, just have the chain of events called once the AI controller is initialized, maybe. If that's the case, maybe chains of events like these could even be turned into resources for reuse :D
@GameDevWDavid
@GameDevWDavid 7 ай бұрын
The example I give in this video of AiController is so that you understand the concept. As you say, this type of class must use more sophisticated mechanisms, but I did not want to implement them because they would only make the explanation much more confusing and would move attention to something that is irrelevant to the pattern I am trying to explain in the video.
@amirhm6459
@amirhm6459 7 ай бұрын
Really interesting. Similar to UE input system. Btw, I'm always curious about implementing good collision response programming structure. I don't thing it is good if the GameObject instances have hard coded response on it. I'm thinking about creating collision response library for the GameObject to inherit or ref from it. But not sure it will scalable. What your advice about the good way to implement this in Godot? Thank you before.
@GameDevWDavid
@GameDevWDavid 7 ай бұрын
In my opinion the advantage of using high-level engines like Godot is that all these basic functionalities are already implemented. If you want to go down to the level of creating your own mechanisms, perhaps it would be better to use a framework instead of an engine; but of course that's just my opinion. Specifically in the case of Godot, collisions are very well integrated into classes like CharacterBody2D.
@uncarpinchomatero
@uncarpinchomatero 4 ай бұрын
One question about this pattern. Suppose its not an action game but a turn based rpg. Would you have a controller for the map scene and a controller for the battle scene? Would it be best to use the same controller with all the commands and then just filter what you use in each scene?
@GameDevWDavid
@GameDevWDavid 4 ай бұрын
The specific case and needs would have to be studied, but if the map scene and the battle scene are different components, each with its own peculiarities, yes, each one should have an independent controller adapted to its needs.
@longuemire748
@longuemire748 5 ай бұрын
Thank you for this tutorial But why use a container controller in 8:53 if you can only use one command at a time? Is there a reason rather than storing the command in a simple variable?
@GameDevWDavid
@GameDevWDavid 5 ай бұрын
You are welcome! The reason is so that the current Controller can be added to the node tree. ControllerContainer is simply a Node to add that class to.
@longuemire748
@longuemire748 5 ай бұрын
@@GameDevWDavid Thank you:)
@simpson6700
@simpson6700 6 ай бұрын
this is so confusing. i used this in a pong game as exercise. in the main menu i select 1 player or 2 player. depending on the choice i set player 2 to the AI or to a player. it's fine with AI, but the player2 is where i struggle. as a bandaid fix i simply duplicated the human controller and changed the variables for the keys. it's fine in such a simple game, but it's undesirable, since if i make changes to the human controller in the future i also have to make changes in the duplicate. i tried extending the human controller, but then i'm one inheritance layer too deep and can't reference the HumanController2 script in the same way that i reference the HumanController script.
@GameDevWDavid
@GameDevWDavid 6 ай бұрын
Why do you have to duplicate HumanController?
@simpson6700
@simpson6700 6 ай бұрын
@@GameDevWDavid i want to have two people be able to play against each other. i don't know how else to assign different controls to the HumanController.
@DavidSerranoIO
@DavidSerranoIO 6 ай бұрын
@@simpson6700 Oh I see, in that case you can't use a duplicate of HumanController, since HumanController receives keyboard inputs for only one player. In that case you should have two different classes, for example HumanControllerP1 and HumanControllerP2, each with different key mappings. Of course this could be improved with an abstract class one level higher to avoid duplicating code, but for now I'd go with it.
@atmancheater9657
@atmancheater9657 7 күн бұрын
@@simpson6700 Why don't you just create two different HumanController instances?
@piyushbhatnagar4735
@piyushbhatnagar4735 7 ай бұрын
Sir Can you make a video from sketch how to install Godot and other setups
@GameDevWDavid
@GameDevWDavid 7 ай бұрын
Well, installing Godot is quite simple, just download it and double click on it to open it.
@piyushbhatnagar4735
@piyushbhatnagar4735 7 ай бұрын
Sir upload source code according to topics
@GameDevWDavid
@GameDevWDavid 7 ай бұрын
Unfortunately I do not have permission to distribute the assets I use in this project, sorry!
@sunofabeach9424
@sunofabeach9424 7 ай бұрын
@@GameDevWDavid then kindly upload source code saar
@devilmonkey471
@devilmonkey471 5 ай бұрын
Do your own work. Learn something. The entitlement in these comments, Jesus.
@IberianInteractive
@IberianInteractive 7 ай бұрын
you might as well just show us the code and let us figure out because you don't really explain how anything works...you just write lines and lines of code
@GameDevWDavid
@GameDevWDavid 7 ай бұрын
I try to follow an entertaining style of explanation, mixing minimal theory with practice. If you watch carefully what I do and say you will be able to understand what I am trying to explain. This video was on my other channel and had about 14K views, no one at any time told me that they didn't understand what I was explaining. What may be happening is that perhaps you are more interested in the purely theoretical, in that case I recommend that you look directly at the book on which I base myself to make these videos: gameprogrammingpatterns.com/command.html
@D-Ogi
@D-Ogi 7 ай бұрын
​@@GameDevWDavidI agree that a bit more explanation would be beneficial, especially when you decide to skip some aspects
@GameDevWDavid
@GameDevWDavid 7 ай бұрын
@@D-Ogi Okay, thanks for the feedback, I'll note it for future videos 👍
@JuanTarallo
@JuanTarallo 6 ай бұрын
If you are having difficulties with understanding what is presented in this video, you should start slower and work on your foundations. Stuff done here is pretty straightforward and you shouldn’t struggle with it if you’re watching this. What is being done: 1. Create a base controller class that defines common methods to control the character. 2. Abstract the logic in the player class to use this new controller by creating the based HumanController. 3. Create an AIController that will be the controller that takes over when a cinematic is taking place. Everything around these 3 key points is just boilerplate code that you should be able to comfortably interpret. If you’re not comfortable, I suggest to just go back to the basics and then come back and try again. Also, your complaining tone is not great. You are getting a video with useful information for free that someone took the time to make so… A little bit of respect comes a long way when giving your opinion.
@poleve5409
@poleve5409 26 күн бұрын
I agree^ The video is really easy to follow and straightforward. I am thankful the maker of this video doesn't slow down for every little things.
3 Game Programming Patterns WE ACTUALLY NEED.
14:13
Jason Weimann
Рет қаралды 14 М.
NERF WAR HEAVY: Drone Battle!
00:30
MacDannyGun
Рет қаралды 58 МЛН
Жайдарман | Туған күн 2024 | Алматы
2:22:55
Jaidarman OFFICIAL / JCI
Рет қаралды 1,8 МЛН
How to use Classes in Godot! - Intermediate Tutorial
8:46
Queble
Рет қаралды 4,4 М.
How to write more flexible game code
8:36
The Shaggy Dev
Рет қаралды 19 М.
Best FREE Software for Game Development in (2024)
8:01
anyDev
Рет қаралды 32 М.
Bob Nystrom - Is There More to Game Architecture than ECS?
23:06
Roguelike Celebration
Рет қаралды 195 М.
Implementing Undo And Redo With The Command Design Pattern
32:25
Optimizing my Game so it Runs on a Potato
19:02
Blargis
Рет қаралды 482 М.
How to Program in Unity: Command Pattern Explained
22:37
iHeartGameDev
Рет қаралды 65 М.
Godot 4 Souls-Like Template: Programming Patterns & Signals
8:25
Cat Prisbrey
Рет қаралды 2,6 М.
Building a Gamified Productivity App with Godot 4
16:50
DevDuck
Рет қаралды 99 М.