Game Programming Patterns in Godot: The Command Pattern

preview_player
Показать описание
👉️ Learn how to implement the Command pattern in your Godot game!

(Disclosure: As an Amazon Associate I earn from qualifying purchases.)

🔔 Subscribe:

Subscribe to my channel to see more videos like this:

📖 Useful resources:

- Assets used in this tutorial:

🔵 Follow me:

Find out about my latest videos and publications:

⏳ 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
Рекомендации по теме
Комментарии
Автор

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!

GameDevWDavid
Автор

Nice tutorial <3
I can notice some caveats that are sometimes expected in this kind of educational content, but here is one that is probably unintended:
- Both Player and Controller are running on _physics_process
- Because of godot's nature of broadcasting events, the player moves in it's physica process before the controller updates the inputs
- this means some commands like move() will be executed in the next frame, because setting the _horizontal_movement variable works as queueing the input, and could even be overriden by something else, in example a call_deferred
- Other commands could run immediately, in example attack playing attack animation in the same frame that was executed

marianosuligoy
Автор

I would LOVE an undo/redo tutorial. I'm working on a game in which house design is a major pillar, and wrapping my head around how to implement that functionality is proving to be a challenge.

JaneSamborski
Автор

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!

angulinhiduje
Автор

Very instructive video about the command pattern in godot!

danielsepulveda
Автор

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.😊

joggerjoe
Автор

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
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

gonderage
Автор

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?

longuemire
Автор

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?

uncarpinchomatero
Автор

Can this pattern be combined with a state machine? Would you recommend it?

lautaromendieta
Автор

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.

Mr_Brodol
Автор

Are you on a Linux machine or a Hackintosh?

HDGTrailers
Автор

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.

simpson
Автор

Call me simple, but I just don't get how splitting up player input from a single script you can read through into 7 different scripts you have to page between just to follow the logic of making an attack is supposed to be a better system. There HAS to be a less convoluted way to do this.

MoogieSRO
Автор

Sir Can you make a video from sketch how to install Godot and other setups

piyushbhatnagar
Автор

Sir upload source code according to topics

piyushbhatnagar
Автор

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

IberianInteractive
visit shbcf.ru