C# Godot 2D Platformer | Magic System Pt 3 Creating Our Scalable Magic System!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is mitch with fine point cgi and today we're gonna talk about how to create a scalable magic system so this is kind of a part three i believe of our little magic system project that we're doing and we're gonna go through the process of creating our magic controller we're going to go through and create our base spell and then have everything kind of inherit from that bass spell and then finally we're gonna go ahead and cast that spell and do some damage to our enemy now this will probably end up being a multi-part series here because each time we create a spell it's going to be a little bit of work so we're only probably going to get through one but i know there are multiple spells that we need to get through so with that being said let's go ahead and get started okay so the first thing that we need to do is we need to build our magic controller and our magic controller is going to basically allow us to cast spells and it handles a lot of our magic logic now i know that we did a little bit of magic stuff before with our potion and things like that so we might need to go in and refactor some of that maybe in a future video or maybe in this video depending on if we have time but let's go ahead and make a magic controller and we will go from there so i'm going to right click on res i'm going to say new script and i'm going to call it magiccontroller.cs and then i'm going to double click on that and that'll open it up inside of visual studio code so our magic controller is going to be pretty simple we really can't do much without having our spells and things like that already put together so unfortunately this is borderline useless right now but we do need to have it now what we can do is we can go ahead and lay the groundwork here so we could have a public void cast spell and what that's going to allow us to do is it's going to allow us to cast our spell so we'll go ahead and just lay that in here so that way we have a function already built but basically the idea is that our magic controller will cast our spell and will handle all of the lower level spell stuff so right now we're done with this but we're definitely going to need to come back to it in the future probably soon so we have that so let's go back to godot let's right click on our res let's create a new script and let's just call this spell with a capital s we'll go ahead and create that and our spell is going to be a class that is going to hold all of our information about our spells that's generic so things like mana cost things like damage amount and stuff like that and we also want to allow us to override our values so we're going to do is we're going to do what's called an abstract class and an abstract class is something that says hey this class can be overwritten by another class if that makes sense so you know the nice thing about this is we can inherit from this and get all the cool properties from it but we also gain a lot of flexibility now since this is a 2d game i'm going to inherit it from a node 2d whoops two d so that way it's inherited from a node 2d i'm going to get rid of this little bit of code here and we're going to go ahead and say private string resource path we're going to go ahead and say public int damage amount and then we're going to go ahead and say private int speed which actually you might want to make public actually now that i'm thinking about it so let's make that public so that way it's it's accessible outside of the project and then we're going to go ahead and do public float mana cost and now from here we can go ahead and define uh functions that we want to make sure that the classes below us have which is really useful if you're going to be calling generic code so what we can do is we can go public abstract void cast spell and we can do that and what this is going to do is anything that inherits from this class needs to implement this so you have to build this you can't just not have this in your class and the reason why this is useful is because then you can generically call this function from multiple different classes that all inherit from this spell now i know that that's confusing so i'll explain it more in detail once we get to this point but it's a really really cool feature so from here we'll go ahead and say public abstract void load resource path and then we're going to say public abstract void setup so each spell is going to have a setup right because you need to set up your spell for it to work and we'll go ahead and use the semicolon there so that's basically what we're going to need for now now you can see that we have this ready here we'll go ahead and pull that out we don't need that and that's basically our spell now there's some additional stuff that we might need to add later but at least for right now that's what we have so the nice thing about this is it allows us to really build our spells so that way we don't have to have that additional information so what i'm going to do is i'm going to come up to our damage amount and i'm going to export it so now every thing that inherits from this spell will have their damage about exported so i can change it later and i'm going to do the same thing with my speed i'm going to export that and i don't like that it did that and i'm going to go ahead and go to my mana cost and i'm going to also export that so now anybody that inherits from this will have these values exported automatically for us so that way we can reference them in our code without needing to have that additional code so now the first spell that we're going to do is going to be an ice knife right so we're going to come back to our dough engine we are going to come up here we're going to right click and add in a new script and we'll just call it ice knife simple enough we'll go ahead and double click on that and we will actually inherit up here from our spells or from our spell i should say you'll see that we have an underline here ice knife does not implement inherited abstract member cast spell setup or load resource path so what that means is the game's not going to work unless we have a setup a load resource path and a cast spell now we may not need our load resource path but i'm going to put it in anyway just in case i can't remember if i need that or not so we're coding a little bit on the fly here so what we're going to do is we're going to implement these inherited members so the first one is spell.setup so we can do is we can say public override void set up and you'll see suddenly if we come up here it's gone right from this thing it doesn't say that we need to implement it anymore so basically what we're saying is hey we need to we are creating this setup function but we are overriding it with our own functionality i know that that seems weird but trust me it's very useful and it'll become a great it'll become apparent very quickly once we start actually coding our project so we'll come here we'll go public override void and we need to go ahead and do our cast spell and you can see that when i hit tab it says hey we're going to throw a not implemented exception that's fine and we'll do the same thing public override void load resource path and you're going to see that it automatically threw a non-implemented exception as well so that way if we try to call it it's not just going to do nothing it's going to say hey you haven't implemented this which is good so now from here what we can do is we can go ahead and set up our scene for this ice knife here so let's go out to godot and let's go ahead and go scene new scene and let's make it a 2d scene because we need to because our ice knife inherits from our spell which inherits from node 2d so we need to make sure this is a node 2d so what we can do now is we're going to need a few things first i'm going to name this ice knife so from here we can go ahead and get our sprite in here because we need to have a sprite so let's do sprite and then we're going to need to have some collision so we'll go ahead and add an area 2d and we need to add collision to our area 2d so let's add some collision so we'll add a collision shape and then a collision shape always needs a shape so we'll come over here and we'll create a rectangle shape so now that solves that and from here we need our sprites so what we're going to do is we are going to go out and fetch ourselves an ice knife sprite set so we'll go to itch.io here and we will go ahead and type in ice i don't know knife let's see if ice knife works it doesn't so let's see if we can do ice shard maybe oh there we go there's a good spell so you can see it looks perfect actually it looks exactly like what i would expect so let's go ahead and click on ice shard and then let's go ahead and click download now because it's free so we'll say no thanks take me to the downloads and we'll go ahead and download this and you'll see that it's going to dump out a bunch of png files so let's go ahead and go to downloads let's right click and extract it and extract it awesome so now we've got our spell simple enough so what we can do is we can come over here we can copy this if we go to ice shard copy oops copy it and then we go back to godot and we right click on our res and open in file manager that'll give us our little file manager here and we can right click new folder and we will call it spells and then we're going to go inside of there and paste our ice shard now godot is going to go through and do some importing which should be pretty quick and we are going to go into our ice shard and we are going to select all of them go to import preset and 2d pixel and that will allow them to be a 2d pixel simple enough so now we can go into our scene go into our sprite come up here and drag in our little sprite and you can see it's a huge sprite but we don't want it that big so let's go ahead and drag it down make it a little smaller and still way too big so let's make it a bit smaller something like maybe that that seems reasonable there we go simple enough and let's make sure this is zeroed out so if we go to transform we go 0 0 so it's perfectly centered same thing with our area 2d let's make sure that that's perfectly centered and our collision shape because i grabbed on to that yeah it didn't quite zero out and then let's adjust this so that it matches the shape we're looking for awesome so we'll go ahead and hit ctrl s and we're going to save this as iceknife.tscn and there we go so now it's saved and actually i think i'm going to take my iceknife.tscn let me see because we got to start organizing this project it's getting too much so we'll take our iceknife.tscn we'll drag that into our spells so now we have it underneath that and we'll go ahead and find our ice knife cs file and we will drag that up to our ice knife here and drop it in and it will go ahead and link that script with our ice knife so go ahead and hit ctrl s so now that we have all this hooked up let's go ahead and make it so that our ice knife can del detect collision right because when it collides with something it needs to do something like do damage to somebody right so go ahead and click on our area 2d we'll go to node and we will say on body entered because we're going to be doing damage to bodies only right we'll right click that connect it connect it to our ice knife let's go ahead and take that and copy it and connect it and then we can come down here and say hey public void on area 2d body enter object body and then we'll go ahead and do that awesome simple enough so now that we have this we need to go ahead and set up all of our casting code with our magic controller because like i said before our magic controller handles casting our spells right so if we come up to our magic controller we'll come up to our cast spell and we will go ahead and say okay so first we need to go ahead and have an equipped spell so what we'll do is we'll come up here and we will say public hacked scene equipped spell is equal to and in this case i'm going to directly make it equal to my resource loader so i'm going to actually just load that resource dot load and we're going to quote res colon slash slash spells slash and you'll see that it automatically picked up my ice knife here so we'll click on that and then we'll do a semicolon and you'll see that it gets mad at us and it says hey whoa whoa whoa we cannot implicitly convert type godot resource to a godot pack scene you need to cast it right are you missing a cast yes we are right so we're going to say as a packed as a packed scene and what that's going to do is that's going to tell the resource loader to load our ice knife as a pack scene so that way we can use our equipped spell simple enough right so what we're going to do is we're going to come down to our cast spell we can go ahead and say spell current spell is equal to equip spell dot instance as spell so what does this do well what this is doing is it's saying hey grab my equip spell that's my pack scene and instance it and then say it's a spell but this spell is an ice knife right so how can we get away with instancing something that's an ice knife not a spell right well since it inherits from spell that means that we can say it is a spell because it inherits from it so therefore you can say hey i know it's this type i know it's a spell even if it just inherits from it i know it's a spell so i only need to call the things that is in here i don't need to call the thing specifically that's in here if that makes sense so basically as long as we stick with these three methods here we can get away with just casting our spell through calling it a spell if that makes sense so and if it doesn't i'll be more than happy to explain it a bit more so what we'll do is we'll hit enter we'll say hey currentspell.setup right because if we need to do any setup on that spell we can go ahead and do that and then we can say hey game manager dot globalgamemanager.addchild currentspell and then we can go ahead and say game manager dot player dot mana update mana minus whatever their current mana amount is right minus whatever the the spell's cost is so current spell dot mana cost and we'll make that minus so that way we can minus whatever the mana cost is so if the spell is free right it's going to cost zero but if the spell is something that's more you know more expensive then it's going to cost whatever it is that we set it to so the beauty of this is this will work with anything that this that inherits from this spell because everybody has these specific things they have damage amount they have speed they have mana cost everybody's the same in that retrospect we can go out here click on our ice knife go to our inspector and you'll see that our exported parameters haven't shown up yet and that's because we haven't built so let's go ahead and build this and let's see if we have any build errors and if you click up here there is a build button i forgot to mention that but you can see there we go so our mana cost let's say for the spell is going to be 10 the speed of the spell is i don't know 50 the damage amount is 5. okay and we're going to go ahead and save that and now what that means is because this inherited from this it shows up here even though it's not in here that's the power of inherited classes and that's kind of the power of abstract classes allows you to override stuff so now that we are at this point what we can do is if we look at our magic controller we are now casting a spell which is good we can go ahead and open up our player controller and let's go ahead and set up the ability to cast a spell now i know that this isn't perfect right we're gonna instance this at the center of our scene so it's not going to actually do what we want but that's okay and don't worry it's not a big deal one thing that we should check first before we jump over there is set up let me just make sure that my ice knife okay my setup is empty i wanted to make sure of that because we don't need that and we may not need these but i have these for just in case there are some things that i'd like to maybe expand upon in the future so we'll just leave those for now um that should work okay so that should work so what we're gonna do now that we have this set up is we're gonna go over to our player controller and we will go ahead and add in a new function here so let's go ahead and minimize this so let's just go ahead and collapse a couple of these so that i can see what i'm doing there we go so now we can actually see what we're doing a little bit so what we'll do is we will come in here and we will say okay private void attack and cast our spell right but we don't have an access we don't have access to our magic controller because our magic controller doesn't exist yet right so we need to go into our game manager and we need to add that access so we'll say public static magic controller and we'll say magic controller and then we need to go ahead and say hey i'm ready magic controller is equal to a new magic controller and that'll allow us to just go ahead and have a magic controller that exists in our world so from here we can go ahead and access that from our player controller so we'll go into our player controller and say okay gamemanager.magiccontroller.castspell and we're going to need to go ahead and have some kind of animation that goes with this but we'll get with that we'll get to that in a second so we'll go ahead and save this and then we're going to scroll up to our physics process here which at this point we're starting to get pretty busy in here we might need to move over to a state machine at this point because it's starting to get this is starting to get really complicated right and um a state machine would definitely clean a lot of this up so we might need to investigate that for our next video so we can go and find a good place to put this so it's kind of something i'd like to do at the end so that way it kind of takes precedence over everything so we can come down here to i don't know here ish or maybe down here well we don't really want yeah we could do it after they get mana that seems fine so we'll come here and we will go ahead and say if input dot is action just pressed and we are going to say if attack is just pressed now we don't have that functionality yet but we'll go ahead and put it in and we will say go ahead and attack so now when the player hits the attack button they will go ahead and attack simple enough now we need to go into our godot engine we need to go into our project project settings and input map so that way we can hook that up so we'll go ahead and say attack and we will add that in and we'll go ahead and make that button a key and we'll make that x simple enough and we'll hit ok so now if we go ahead and hit play right and our game is running if everything we did is correct which who knows if we hit x it should have placed a spell somewhere let's see doesn't seem like it's doing anything because it would be in this general area so let's go ahead and see if it is firing off our attack spell first so let's go over here let's hit uh let's go over here let's hit a break point and let's go ahead and go to our run and let's play this in editor and let's see if it's even getting to this point it might not be so good is now running so we'll hit x okay so it's definitely getting to this point so we will step down we're going to see our attack we'll step in oh godo is being unhappy with us probably because we waited too long so let's try and see if we do that again see if it gets past our attack it's going to cast our spell with our magic controller so if we go ahead and hit x it goes into our magic controller so we'll step in and you can see that it does come in here and attempts to instance our spell it does our current setup add child update mana go ahead and put a break point here see if it's getting to this point i don't know why my visual studio is being dumb but that's okay i've been having some issues with it lately so we'll go ahead and run that again we'll hit x and it is definitely firing off our spell even our mana is getting updated so if i hit play our mana went down to 90 so that definitely worked and the spell exists in the scene oh there it is i don't know why it wasn't okay well that's fine so our spell now exists so that's good news that's what we wanted it's very large we should probably make it smaller but that's okay so that's good okay cool so now that we have that now we need to close our godot project here because it crashed on us but that's okay um now that we have this it's instancing our spell we need to a instance it in front of our player and our spell needs to move right so what we're going to do is we're going to go back into our godot project and we're going to go into our player and we're going to add in some spell casting stuff some fancy stuff right so what we can do is we can go ahead and say all right let's add in a child node let's add a position 2d let's go ahead and place that in front of the player like so so we'll go ahead and drag this in front of the player and we're going to call this spellcast right and then we're going to go ahead and duplicate this so ctrl d and we're going to change the name of this to spell cast left and we're going to grab this and move it negative 11.97 i don't like 0.96 we'll just do 12 and then we'll go ahead and change this to 12 as well i don't like it when it's that close to 12. there we go so that'll work right so now what we could do is on our spell cast we can just get our players global location and then fire off our spell simple enough right so we'll go over to our visual studio we'll go to our magic controller and since our magic controller is handling our casting we can just come in here and say okay so we know that we're casting our spell so let's come in here and say all right current spell dot global position is equal to gamemanager.player.getnode position2d quote whatever we named it so in our case of spell cast we'll say right so we'll go ahead and copy this so let's just rename copy and then paste that in there and that's going to go ahead and give us our spell cast location we'll say dot global position and that will set our global position to our player simple enough now from here we need to go ahead and make sure our spell is smaller because it's going to immediately collide with our player and i'm not a huge fan of that so let's go ahead and just make our sprite much smaller so let's make it something like that maybe and let's change the size of our collision shape to match so we'll bring that down in size quite drastically and we will save it so now if we play and we hit x it should deploy the spell right in front of us perfect that's exactly what we wanted so now from here we need the spell to move forward right we need the spell to actually if i show you guys as cool as this spell is it's not going at anything when we cast it right so we need to get this to move whatever direction it's facing that way and also you'll notice if we hit if we hit left and we hit x it still casts right here and that's going to be a problem so we need to have it cast that direction right and we also need it to update and flip right because it needs to go that way so what we can do is we can alt tab back in and let's go ahead and first grab our face direction so i'm going to come up to our cast belt and say bool face direction we're going to say hey if base direction then go ahead and set it to this location right else the face direction must be the opposite right so we'll just duplicate this code here and we will change this to left and that's going to go ahead and flip our node to cast off of this side over top of this side now we need to do our next big thing which is flipping our sprite right but i don't like how our setup spell doesn't take in our flip direction it would just be easier if it just took in our face direction right so if we just pass in our face direction and then go into our spells and change our setup to take in a boolean face direction then we can go into our ice knife come down here to our setup and you'll see our setup suddenly says hey you need to take our face direction right no no suitable method has been found to override right that's because we need to add in our boolean face direction and that will go ahead and allow this to once again be in good standing with our class that we have over here right so now from here and i know it seems like why would i do this when i can just do it a different way the reason why is it's just a lot more flexible in the future to do it this way than it is to do it manually and have a lot of duplicated code we're going to say get node sprite sprite dot blip whoops flip h is equal to face direction so now if the face direction comes in it's going to face that direction now something else that we're going to need is since the spike is going to be going in a specific direction we need this face direction to be global right so that way anything in here can say am i facing this way or am i facing that way now we could do this a lot of different ways we could just get our node flip h and then just use that but i think it'd be easier just to use this face direction so what i'm going to do is i'm going to go into my spell and i'm going to come up here and say private bool base direction and what that's going to do is that's going to allow me to use that face direction as my global variable if that makes sense so if we go into our ice knife here and i actually lower this d to a lowercase d because i don't want to have some duplication here i just don't like it we can actually come in here and just go base direction is equal to face direction and now that is global if that makes sense oh whoops face capital d direction is equal to face direction and i think it's going to get mad at me because it's private which is my fault so this needs to be public my apologies so go ahead make that public and then now it works okay so the reason why actually before i move on is you can't inherit something that's private so this is not going to be inheritable which means it's probably useless to us but i got some fanciness that i think i'm going to do later with this load resource path we're probably going to use this to load our resources so that way we don't have to load it inside of our magic controller instead we can just load it inside of here but that's something that we'll look at in a little bit but that's why this needs to be public is because you can't inherit something that's not a public variable so we'll go back to our ice knife and so now what we need to do is we need to go ahead and move our ice knife over every single frame until it hits something right so what we can do is we can uncomment this process i don't think i'm going to do that because i don't want to go off a delt i'd rather go off of physics so we'll go ahead and delete this and we're going to say hey public override void underscore physics process float delta and we'll go ahead and get rid of that base we don't need it and we will go ahead and say hey if base direction then position minus equals our transform dot x right times delta multiplied by our speed if you remember we have our little speed parameter that we had and that will handle this and then we could say else position plus equals transform dot x times delta times speed simple enough now there is a way that we could compact this a little bit more by basically creating a ternary operator here or we could probably do some fanciness where we just convert it to an integer or something like that but i think that this will work for what we're trying to do so now if we tab back into our project we have a failed for our build so you can see there's no argument given that corresponds to to require formal parameter face direction so if we double tap on that you can see that we have our cast spell that's my fault so we need to go ahead and pass in our player controllers animated sprites flip h value right so we can say is the player facing this direction or this direction right so if we say game manager dot player dot get node animated sprite and we quote it and say animated sprite dot flip h and that'll pass in that value so that should basically pass in everything that we need so if we come over here and we hit play it should handle it and from here we can go ahead and see our ice knife flying now you'll see that it's the opposite it's coming from the behind right but it's actually working everything seems to be working other than that so let's go ahead and tab back into our visual studio code and let's go over to our magic controller and just flip this so left and right and that should work from now on so if we fire it perfect perfect so something you'll notice though is a it just keeps going and it'll keep going forever which is not good we don't want that we want it to kind of fizzle out as time goes on right we want to delete itself if it's you know not going on forever right we don't want it to to exist forever we need to have a life span of some kind so let's go ahead and close this and let's come over here and go into our ice knife and let's add in a basically like a time to live right so that's something that we might want to put in all of our spells right because our spells aren't going to last forever so we can actually come in here go into our spell and say hey let's export this so that way everything can have a different life span public float life span and from here we can come in here and say hey life span minus equals delta and then we can say if lifespan is less than zero then go ahead and queue free and that'll just go ahead and delete it before it goes on forever right so the nice thing about that is if we come up to godot and then we go to our ice knife you can see when i build this it's gonna add in a new parameter on our ice knife so you can see our life span so we'll give that i don't know 10 seconds let's say and that's a pretty decent lifespan i think it'll be off the screen definitely by then right so it'll work out perfect so now that we have all of that and i know i'm this is a lot of information i'm sorry guys i know this is a lot so um what we're gonna do is we need to go ahead and set up our damage system right so that we can actually do damage to things so if we come down here and we go to our on area 2d body enter we can go ahead and say hey if body is slime let's say alright slime enemy then we are going to go ahead and do damage to it so we'll say slime enemy it slime is equal to body as enemy right here and then we're gonna go ahead and say that the slime needs to take damage now i don't think slime actually can directly take damage right now so let's go ahead and check does it have a damage code it does not so we're gonna have to build that so first we need to give the slime health so let's go ahead and say private integer health and let's scroll down here and let's say public void take damage and let's take in an integer damage amount and we'll go lower case d and then we're going to say health minus equals damage amount and then we will go ahead and say hey if health is less than or equal to zero then we're going to want to query free and that will go ahead and kill our slime right so if we come back to our ice knife and we say hey slime dot take damage and then we can pass in the amount of damage that we do which if you look at our spell.cs it's just damage amount so we'll come over here and say damage amount and actually i think it's capital d isn't it yep capital the damage amount and there we go so if the body hits a enemy it's going to do damage to it now we're going to want to do some refactoring of our enemy system because we can't just say if body is this if body is that if body is this that's just going to be too much work so what we can do instead is we're going to inherit everything from an enemy class i think and then we'll go ahead and just say if body is enemy then take damage right now what else we need to do is we need to also cue free our spell here so that way our spell disappears if it hits anything so if we go back here and we hit play and we come over here and we cast our spell as soon as it hits that wall it disappears simple enough right it doesn't go through it anymore which is perfect that's what we want if we come down here and we shoot our our enemy it misses it probably because is our let's check is our okay so i figured it out and i feel stupid but um our collision shape is tiny see how low it is to the ground so even when it goes up like this it doesn't actually you can't actually hit it so what we need to do is we need to make our collision shape taller pull it up and let's make it so that when the guy's all the way down which it looks like that will work just fine we'll pull this up so that way he can actually get hit by things and let's make him jump there we go and that will pretty much solve our collision problem now i'm kind of curious how this is going to solve the colliding with the player because the player may get caught up on this although if i remember correctly the layer that the slime is on is two so it shouldn't cause a problem the player should just be able to walk right through him if they don't touch their area 2d so we should be okay there now i'm going to go ahead and save this and we need to go over to our ice knife and change our area 2ds collision layer to be layer 2 along with layer one so that way it can collide with both so if we control s and we play this it should now detect our collision so if we run down here drop down and hit x you'll see it deletes our slime perfect that's exactly what we wanted so awesome that literally is what we wanted so that's good alright so now that we have this we need to add in some additional effects right we want this thing to actually look good and play good right so what we can do is we can right click our ice knife add in a child note and go ahead and add in an animation player and we're going to go ahead and make three animations so we'll go new we will call it idle we will call it cast and we will call it finish and these three spells are going or these three states are what our spell will be in so it'll either be in the casting state the finished state or the idle state right the idle state is when it's flying through the air so we'll start off with the idle state because that's going to be the simplest so we're going to do is we'll go ahead and click on our sprite we'll click on our texture and we'll put in a keyframe here and we'll just create a normal keyframe and you will see here that we've already got our correct texture here so that's perfect so if you click on it you can see right there it's the correct texture then we're going to move over to our cast we're going to go ahead and click on our sprite add in a keyframe and create it and we'll scroll up to our ice shard and we will start with our first png so we'll drag this in drop it in and drop in a keyframe we'll move forward a single frame we'll drag this in hit keyframe go up another frame drag this in keyframe we'll drag this in get another keyframe in we'll go ahead and pull this over drag it up keyframe and you'll see that this is a little on the larger side so we may want to adjust it because you'll see that it does one of these numbers and i'm wondering if we're going to want to move from here this over so we can actually just drag in our we can just come over here and add in a transform and then we can go back a frame keyframe it go forward a frame oh oops actually go up forward to this frame keyframe it let's pull it forward just a tiny bit like this to kind of keep that same magic ball dealie do here so we'll you'll see that it goes boop and that will work perfect we'll go forward a frame we'll go ahead and grab this one and we will go ahead and keyframe it and then our last frame we're going to go ahead and use our little ice knife spell so actually it didn't keyframe that's my fault so we'll drag this up keyframe and then we'll go forward one more drag this in and key frame it and then we need to go back so if we go actually is this yep that'll work and then we need to go back back a bit so we'll go back so that now this is perfectly dead center again and keyframe it cool so that will work so now that we have this let's go ahead and say on 0.6 it's going to be the end so we'll say 0.6 perfect and now we need to go to our finish state we need to go to the front and go ahead and keyframe this create we will go forward one frame we're gonna go ahead and put this in and keyframe that we're gonna go drag this in keyframe that we'll go in one more we will keyframe that we'll go in one more and we will keyframe our last one awesome and then we're going to go point five so that way it grabs that last little bit and it kind of shows it so you can actually see it because if you don't it might just kill it right after this now from here we need to go ahead and add in those animations so let's go into our script here let's go up here on our ready up here let's go ahead and fetch our animation player so we'll say get node animation player animation player dot play our cast now i don't like this because this is going to be very inefficient so let's go ahead and come up here and say animation player player is equal to and we'll go ahead and say player is equal to this and then we'll hit enter and say player dot play cast animation awesome so now we need to come in here to our physics process and say if not player dot playing is playing there we go then i'm going to go ahead and say player dot play idle and that's going to go ahead and play our idle animation simple enough right now from here we can go ahead and say all right once you hit something i want you to play your death animation right so player dot play and i believe we called it finish so we'll say finish awesome so now if we go to our script here and we run our spell i'll hit x you'll see that it casts it and then it throws it now you'll notice that the first problem is it casts it and it hits and it looks like it just disappears also when we cast it our spell is moving before it's actually finished casting so let's go ahead and fix that first so what i'm going to do is i'm going to set up a boolean up here called able to move and that's going to default to false just because we've instanced it so it'll be defaulted to false and we'll say if able to move then do all of this bit of code here and that will allow us to not move our spell until it is ready to be moved so what we can do now is we can go actually we're going to need to make this public aren't we so we'll go ahead and make this public and now we're going to go to our godot engine we'll go ahead and build this so that way we have that public variable available to us we're going to go to our animation player and we'll go ahead and grab our track we'll say property track and then we'll go to our ice knife hit ok and we are going to go ahead and i'll see it didn't show up so let me see did i save that yes i need to export it that's why so we'll go ahead and export this if able to move perfect so now we can go over here and we can go ahead and build this so now it's going to be built and then let's go ahead and add in that property track let's hit ok and then let's grab our able to move and then we're going to say on finish we are not going to be able to move so you'll see that this is now set to false right and on start after hour cast right we're going to be able to move so let's add in another property track ice knife able to move open that up right click insert a key click on that key and go ahead and click check now if we save when we cast our spell it's going to allow us to move or it's going to allow it to not move until we have fully casted our spell perfect that's exactly wanted but now this is disappearing before it actually is able to play its dead i'm dying animation right so let's solve that so if we come into here and we have our cue free here let's actually get rid of that and let's come down here and say public void remove spell and we'll just go ahead and call q free simple enough and we will save that now if we go into our godot engine we go back to our animation player and on our finish we'll go ahead and add in a call method track we'll click on that we'll click on our ice knife and we'll go ahead and add a key here and we can go ahead and call our remove function providing that it actually existed which of course it doesn't although i think we can actually just call it right here q free so that's something that is perfect so we actually can get rid of this that's my fault so go ahead and save save this get rid of that and then go ahead and hit play and you'll see that once we run over here and we fire off our spell bang it completely finishes its spell and then it disappears and it no longer exists awesome that's perfect that's exactly what we wanted so now if we're fighting our little slime guy we fire off our spell you can see that he disappears it it does its cool little shatter animation and perfect that's exactly what we wanted so that is all i have for you guys today so in the next video which will be coming out probably next week or the week after we're gonna go through adding two more spells probably something like maybe a healing spell or a levitation spell and maybe a lightning strike or something like that i mean we'll have to figure out what we're gonna do but that's where we're gonna do a little bit more refactoring and a little bit more playing around making this robust system a lot more robust right but we at least have the baseline of a pretty decent system so if you like this video go ahead and hit that like button if you dislike this video go and hit that dislike button even though it looks like it's getting removed apparently um yeah if you guys have any questions leave a comment below and i'll be more than happy to get to you or you can hit me up on our discord link is in the description below and yeah that's all i have for you guys today so thank you so much again for watching and i will see you all next time thanks [Music] [Music] you
Info
Channel: FinePointCGI
Views: 431
Rating: undefined out of 5
Keywords: godot platformer, godot platformer 2d, godot engine, godot, godot rpg battle system, godot 2d platformer, godot 2d platformer tutorial, godot dialog system, godot dialogue system tutorial, 2d platformer godot, godot dialogue system, godot 3, godot tutorial for beginners, godot tutorial, unity particle system, how to make a grid based movement system, unreal platformer tutorial, godot engine getting started, godot for beginners, platformer tutorial
Id: QvCOpBeDtVQ
Channel Id: undefined
Length: 55min 41sec (3341 seconds)
Published: Mon Nov 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.