 This video was brought to you by my patrons. Thank you so much for your support Hello there Something that I knew since the beginning that I wanted to have in kitchen tails is support for Local multiplayer So kitchen tails has some modes one of them is an arcade arena where you play against mobs and bosses And I wanted the both players to play together to defeat these enemies So the major concern when we talk about local multiplayer is how we will handle inputs, right? Because both players will have to interact with the system and they will probably use different inputs because it's very hard to have two players using the same inputs and basically just doing different things so let's say one player will use the up arrow and We can use the same up arrow for the other player to interact with the system, right? They can both be pressing the same thing God provide us a very very cool system to deal with that In Godot engine we have what we call an input map and this input map works as follow You can name an action So let's say jump and you can add a list of inputs that will trigger this action So let's say jump and the jump can can be the space bar can be the up arrow Can be the W arrow buttons from the joystick or something like that Once you have all these listed You can check only for the action instead of checking for all the events that you have all the events that could trigger this action But if we are using the same action, even if we have different inputs So let's say the the jump action is built up of three Input even it can be the space bar It can be the first joystick button up arrow and it can be the second joystick Button up arrow So we have two joysticks and both will trigger the jump action But the major problem with that is is that since they will both be checking for the same action So the jump action if we have two objects with a check for the jump action Both will jump if the first player for instance press jump So if we press like the space bar both players both characters will jump because we are checking for the same input Action so the way that we can work with that is that we can create two different actions so jump on the line one and jump on the line two for instance and In the logic of the player instead of having a constant check So instead of having a string with the name of the action that we want to check Instead we have a variable that we can change depending on which player we are dealing with So let's see how I did that in kitchen fails because I think that the system that I created is a very cool And very flexible one. So let's check this out So here I have two characters, which is the first player and the second player One I am pressing the keyboard arrows to move and the other one I'm moving with the joystick So this is what we are going to achieve at the end of this video because I want to explain to you How did I achieve that with the system that I created with the architecture that I created? So the first thing that we have to understand to get why did I made this implementation is To get to the project project settings input map. So we have here the First player so the player one action so left right up and down so on and so forth And then we have the actions for the second player. So player two Left on the underscore two right on the score two and so on and so forth. So we have kind of like indexing characters, right? But what happened? How do you actually check for these input actions? So let's go to the player scene and you can see that here. I have the controls node This is what represents the control of the player. So as if I was abstracting this Physical thing inside the player scene. So we have here the left right jump and so on and so forth actions And how do we check for actions in Godot engine? Well, we can we can use the unhandled input method, right? Or we can use the input class as well. So let's open these These are actually the the building blocks of the system. This is the thing that will hold this system together So if I open the script, you can see that on the unhandled input method at the very bottom So if this even passes through all these checks here at the very bottom We have a check for if this is an action. So if this is an specific action Very often what we have is something like this is action Presid and let's say jump something like this But the question and the major problem with that approach is How we will change this value if we are dealing with two players or more players So you would have a check of course for the first player input, but what about the second player? For the second player, you would have you need to have something like this But you will then have to script because this is a constant check This is a check for a constant value. You are not using a variable for that So you can change that in runtime, but with a variable You can check that at any time and you can change the value of this variable at any time So this action variable here is what I use to store the value of the action that I wanted to check With and whenever with whatever script with whatever instance of this class So with whatever object after that, we have the handle input with basically just check for okay This handle is being hand this input is being handled and this was pressed or this was released And then we have the is holding method which basically can be used with other classes to say, okay Is this action that you represent being held and it can return true or false depending on Whether this input if this action is being hold so it's been held actually So it will check for that and it will also emit a signal telling that this action is present if this is true And basically that's it. So since this action is a variable this this action That this class should check is a variable. I can also export this to the same file so instead of having a Value being changed in runtime. I can change the value right when I am designed the scene So if we go back to the scene here, you can see that the left action node Has the left value in the action variable. The right one has the right value So one and so forth and if we go back to the combat Playground, which is what I used to test the combat system of kitchen tails I have a second player character. So I have one on the left So this is the first player character and this is the second player character And what I did to have this support for mood player is basically that I Appended a underscore with the two so with the index two for the Actions of the second player. So instead of having Left I have left underscore two and with that if we play the scene Yeah, so if we test that now since one is being checked for the player For the player one inputs and the other one is checking for the player two So now we have the proper mood player the local mood player Input handling being done first. So this is very cool. I Wish I have someone to play with me Smash that like if don't have friends to play texture multiplayer games So that's it that was how I implemented the local multiplayer support in kitchen tails If want to get this exact implementation that I just showed you I will put a link to the description and also in the pilot comment for the Kitchen tails github repository so you can go there and check out the implementation Don't forget to turn on the notifications for the project and also to start the repository, please and Don't forget to follow me on each IO as well because I repost some devlogs there when I release Some content off the game. I will release that as well so I can get updates about the project a Big shout out to Tili can Leslie Sultani and Jack for joining me in my patronage. Thank you so much for joining me guys I really appreciate your support. So that's it. Thank you so much for watching keep developing and until the next time