Godot Tutorial || Part 1 || Basic Input System || Godot 3.X

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

I feel like all of this is done 1000 times easier and more intuitively if done in the AnimationPlayer. AnimationPlayer also has .queue("animation").

Most of what you do here is setting properties to fit an animation timeline. Easy and most intuitively to do with AnimationPlayer because WYSIWYG. For the rest there are Method Call tracks, which are equally a joy to tune and balance as they are keys as well you can visually shift as you please in each Animation with all the other keys for Sprite frames, property changes, sound fx and so on.

I don't even want to imagine how unfun it would be trying to balance a medium sized fighter game with the approach you are suggesting here.

👍︎︎ 3 👤︎︎ u/golddotasksquestions 📅︎︎ Oct 06 2021 🗫︎ replies

If it were me; I would use AnimationPlayer and enable the required collider. But as an alternative, it's a nice tutorial.

👍︎︎ 1 👤︎︎ u/erayzesen 📅︎︎ Oct 06 2021 🗫︎ replies
Captions
hello everybody my name is kellen from kindersword productions and welcome back to a new tutorial for the godot engine today we are going to take an approach to a well-known arcade genre from the 90s it's the tournament fighter these types of games are really fun to pick up but are also really hard to master especially with all of those combos you need to keep track of so what will i do until the end of this tutorial well it's simple i will make a working character that can throw a punch have a basic combo system that uses time and of course a basic functionality for the hit detections if there's an interest for the making of a more advanced tutorial please let me know in the comments today i will kinda give you a base to work from don't skip this part yet but before you start you might want to know how i have set up everything first in the top left corner of the engine under debug i have set visible collision shapes to true this will help us to see all the colliders within the debug play scene second when i first looked at these types of games i immediately knew a way on how collision might have been done since the total amount of collision boxes were mainly used for the hands feet and body of you and your opponent it seems logical that these were the only boxes within that scene and that they were shut off when not in use so with that idea in mind i have created a separate scene which will store our player the player starts with a kinematic body to d and has the following children a collision shape to d an animated sprite and a simple 2d note which will be called colliders and will hold two more 2d nodes one for the hands and the other for the feet if i open up the hand colliders node you can see that i have added an area to denote and within that another collision shape don't worry about any special settings or other weird stuff that i might have missed since that was all that is needed i only changed the visibility on some of the colliders i then made a new group to store all of player 1's colliders this can be whatever you want to call it for now i've called it p1 hand feed call if you can't remember how to make a group and place objects in it here's a quick recap click on the note tab click on manage groups in the bottom left left of add fill in a name for your new group press add you can now click on your new group and select the things you want to store within it for now only store the collision shapes lastly head over to the project settings and click on input map in here you will have to make a new action called ui punch or action or whatever now that everything has been set up we can finally start with the actual work like i said earlier the player uses an animated sprite this handy note will help us make some easy animations and will grant us access to some functions within our code for now i've created 4 animations for ryu don't get me started on the pronunciation of this fella these animations are idle low kick straight punch and uppercut idle is the only animation which loop is set true now that our player has some basic animations we now want to help him figure out how and when to use them at our player kinematic body 2d we will add a new script which will be called player movement script before i start coding i want to ask something godot has a way for you as developer to work in c sharp which is really neat but the way things are found or used is sometimes completely different than what you might have expected so here comes the question if you are using godocy sharp would you like to also have this project available on my git in c-sharp for now i haven't really done it but if you think it would be nice to have please let me know in the comments anyway let's get back to coding now with the new script open we first want to give godot a way to access our animated sprite we do this by writing down on ready for animated sprite equals dollar sign animated sprite next we want to have some variables that can keep track of the most important stuff a boolean call is in combo which starts at false two floats called time till next input and time the first starts at 0.5 and the latter at zero and also two integers which we'll use to keep track of our current attack and also previous attack inside function ready we will set time equal to time till next input inside the function process delta we will start off by telling godot that if ui punch is just pressed we want to do the following check if our current attack equals zero we want the animator to play the straight punch below this if we want to start a new alif this one is going to check if our current attack is equal to 1. if that's the case it needs to play the uppercut and lastly if our current attack equals 2 we want to play the low kick now we will exit the last alif and place our current attack this will be connected to the input and will go up by 1 after every input when checking the debug scene you are able to see every transition of your character from the idle to the last punch or kick okay now that that is working let's get going to the next part every fighter needs to have a combo system and this can become as advanced and technical as you want but for now i want it to be simple and easy to use we will only focus on performing these actions within a time limit and creating a combo system out of that but for the people who really want to have an extra challenge of making the system advanced listen closely to the following because i will leave you with the following route to take a combo within fighter games can usually only be performed within a fixed time limit but also with the game holding onto a list of previous inputs within a time span if the new list of inputs matches a list of inputs for a special attack or special ability it will be performed and a new list will be made or the old one is being refreshed this list will do that as well if you ran out of time or got hit by the opponent the most important question for you will be how do i keep track on my previous inputs how will i store the list and also how will i compare this list to the rest okay with that out of the way we will make the simple form of a combo system using time after we hit ui punch we would like to set some variables to a new value above our current attack plus equals 1 we will place the boolean is in combo we set this value to be true this is because the player always starts with the first part of a combo underneath current attack we then make a new if statement this one is outside of the input statement this if is asked for every frame and will check if is in combo equals true if this is the case it will do the following decrease time by delta it will then check for a new if this one being about if the time has become less than zero if that is the case it will do something new it will reset almost every variable this means that time becomes the value as time till next input is in combo becomes false again our current attack is being set back to zero and lastly our animated sprite will have to play the idle animation once again we now only miss one thing and that is a function that will reset the time after every input since we now have a cycle where we have to perform all the inputs within 0.5 seconds this is just way too short so this new function will be called reset attack timer in here we will place an if statement to see if the current attack is higher than our total amount of moves plus 1. since the last move also needs to have 0.5 seconds of stay time if the check is completed we will reset our time to the same value as of time till next input we will call this function right underneath current attack plus equals 1. if we test out the game it should display every move correctly and also reset everything to the right values we are almost there we only need to see how we can move our colliders in between every move and also turn them off when they aren't in use it would be kinda mean to hit your opponent every frame by only standing next to them so here is how we do it we go back into our player scene and make a new script this script will be placed onto the 2d node named colliders and will have the very generic name of collider script in the collider script we will add only two more variables one array called p1 fight call and one boolean called disable call disable call will start off as true we then head towards the area to denote this will help us detect if a body has entered we can connect these areas to the collider script as follows click on an area to denote click on the node tab click on signals click on a function called body entered body either click connect bottom right or double click the function click on node to the colliders and lastly click connect once more if performed correctly you will see a signal next to the area to denote and also a new function inside the collider script do this for all the body parts except the main body cool we now have to add a new process delta function for debugging a function called handle all collider disabling within the parameter a bull called is disabled and to top it off also a function called handle specific collider disabling within its own parameter two variables one boolean also called is disabled and an integer called picked call the first function to be filled with code is going to be handle all collider disabling in here we will make a for loop named colliders and we will make it go through our colliders group made all the way at the beginning of this tutorial we then make a local variable called h and we'll make it start at zero h will be our indicator for in our array we just made after this we tell our array p1 fight call to insert new values in the first parameter this is going to be the letter h and in the next parameter we place the current collider the loop is currently on now the this collider is stored we can now ask our array to either disable or enable it depending on the is disabled variable input keep in mind that it says set disabled this means that if you say true it is off and if you say false it is on for debugging sake we'll debug the name of the current collider the loop is standing on for more debugging security we'll make an if alif this one will check if the current collider is on or not again look closely for the wording of this function it goes from the perspective that the collider is already disabled upon entering now to make the debugger readable we have to add an empty line in between all the information after that we will add plus 1 to h and call all of this from the ready function within the parameter the disabled call bull next on the chopping block it is the handle specific collider disabling like the name suggests it will be our main function to use since after we have thrown a punch we don't want to reset all colliders every time so let's get specific at the start of our game the array will be filled with all of our colliders which is really nice because we will not be needing the for loop in this one and can simply call the array we only have to set the value of the collider set disabled by the is disabled parameter again for debugging standards a new if alif is added to check the specific state of the collider to see if everything is working i'll add a process delta to the script and fill it with some actions if everything went correctly you should now see that your collider is turning on and off again with the handle specific you should be able to enable and disable the specific collider within the array now we only need to connect all of these things to the player movement script what we'll do now is that the player needs to be able to control his or her own colliders meaning that these will only move to a set position or at least move when we press the attack input to get inside the collider script from the player movement script all we have to do is write already far collider script dollar sign colliders we now have access to the script that is placed on another node and with that we also gained access to the functions we had written this script will now also gain another function called reset previous attack as parameter it will have an integer named previous attack id in this function we will enter the collider script enter the array holding our colliders set the value of the collider to pick to be the same as previous attack id fill in dot position and set that back to vector 2 0 0 aka their starting coordinates at the start of the game we then go back inside collider script and send a signal to handle specific collider disabling and set the parameters to be true and also give it the previous attack id to select with we call this function after each current attack value check and also after the time has become less than zero only filling in the parameter the previous attack value which is for now a hand set number because of my three moves before i forget this value is set after calling the preset previous attack and also after the very first punch one of the last things on this list is setting the positions when this action is performed and calling for the handle specific collider disabling function and setting the values to false and the number of the collider if you have more moves or more colliders you might like to have a better system for sorting what kind of move requires what kind of hitbox before the end i did see that i have some code duplication so i'll fix this right away the only thing you have to do is make a new function and make sure that it will store the attack id and also a vector 2. now you can set it anywhere everywhere after each attack whatever if you have managed to make everything within this tutorial i want to congratulate you because now you have a very basic fighter lane right in front of you just waiting to be enhanced and build upon to test all of these things out i've added e honda who's only a kinematic body with a collision shape and sprite and connected all of the body entered functions to simplify when its name is the same as e honda hopefully my code has helped you quite a bit for your arcade classic development and if you have any questions or you want to share some improvements please leave them in the comments this way we can help each other become better developers i'm calling from kindershot productions and this was another godot tutorial see you next time bye
Info
Channel: KindoSaur
Views: 35,767
Rating: undefined out of 5
Keywords: 2D, Godot, Godot Engine, Tutorial, Godot Tutorial, Fighter, 2D Fighter, 2D Tournament Fighter, Arcade, Arcade Tutorial, Developer, GDScript, Godot Script
Id: XrR5jibBVxo
Channel Id: undefined
Length: 16min 19sec (979 seconds)
Published: Tue Sep 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.