Adding 100's of abilities to my MOBA - Unity Source Code Included

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there I'm working on a mobo where you can select a bunch of different characters and I plan on having around a 100 or so options available at the start of the game when it comes out you can see here I've got a couple of them in there and all of these characters the tower is not supposed to be selectable but all the rest of them have abilities and attacks with different animations and particle effects and setting all of that stuff up could take me a long time as well as putting in characters but I've got a system that makes it extremely easy so I can drop in whatever character I want and set up the animations and effects really quickly so today I'm going to show you part of that system I'll show you the ability effect system how you can use it to make abilities or really cool effects in your own games and it's code that you can just copy straight over it's not directly tied to this project and not not very opinionated it'll work on pretty much any character that you want with any particle effects before we look at the code let's take a look at the system in action you can see on the left and the right I've got lists of all of my characters and I can just go select one of them like the elite Trooper on the left and maybe the ladybug on the right hit the trooper shot and watch him animate shoot and hit the ladybug can also add in multiple characters if I just hold shift and then he can shoot at all three of them so I can test out my AOE abilities now he can also fire off other things like this Spore shot or maybe try saber slash doesn't look very good or work r with that one or maybe this uh water ball purple Splash thing he can actually use any of the abilities and that's kind of one of the cool effects is or cool things about this system is that you can test out any of the abilities on any of the characters along with the impacts and we can modify and change them at runtime let's take a look at another one like this Hornet that one had that hornet sting you can see that he shoot something right out of his butt and it goes flying at the enemies so let's see how this all works and how it's put together and then how it ties into the game if I un maximize you can see that I've just got an ability effect scene and it looks like a little debug updator thing I'm not even sure what that is and they don't destroy on load and it's a couple objects in it let's stop playing and see what happens here and what we've got we've actually got a couple extra objects that I can delete some extra ability effects that were sitting there a prefabs manager that we don't actually need either something from the game side that isn't used in here and then we've got this ability effects tester script this thing takes a caster and a list of targets and then in ability Effect definition and then you can click this button to play the effect now it's intentionally this flexible so I can do crazy stuff like grab some spaceships drag them out maybe shrink them down a little bit put to 0.10.1 and 0.1 and then assign them into my FX tester so I can give them my Caster will be number 12 and then I'll put here this one in the other spot and if I go to my game view I can see that I can shoot all the way across I think that there may be a little bit too far apart part but you get the idea I can put in any object that I want let's just move these a little bit closer together I can position them however I want and then I can make them shoot at each other or do whatever different effect that I want of course once I have an idea that I want to use something I just add it into my characters and then it shows up on my list and then I can have it become a Target so I can start using any of these attack abilities and start firing them off now this one is just shooting without an animation that's because it doesn't have an animator controller let's take a look at how animations in all of these particles are hooked up in here and how this all works what does this play effects button do and how are these ability effects definitions set up let's start by looking at the ability effects and the way that they're defined I have here a folder of ability effects and this is a scriptable object you can see one definition right here it's an ability effects definition for the lava Smash If I click on it right here you see that it's this guy doing a well swing attack he windes up and then shoots off some fire and then if you'll notice that ladybug is actually taking some damage not playing an impact animation for some reason that's a surprise let's take the uh animation there that's where it's supposed to be if I now modify it and or hit it again boom now it plays it cuz it's supposed to play the target animation impact animation is for the projectiles now this thing waits for about 1.2 seconds if I put that down to a zero let's just cut that out down to a zero real quick and you can see see what that would look like let's see lava smash now it just instantly doesn't obviously that's not right so being able to just modify the delay in there makes it really easy I've got a delay for the caster and then a delay for the Target too notice that that doesn't hit instantly the effect on the guy comes slightly after 05 seconds after to be specific now here I can Define the effects and if I want I can just go in and change them I could change this to be like a feather effect so that when we do the lava smash it goes on and then hey he gets a weird Little Feather probably not the effect that I want to go with I'll switch it back to Fireball but having a system like this means that when I'm playing I can also go in change any of these ability effects and change any of these bits of data here and have it work while I'm playing running in game and tune things or more often do it right in here where I want to test different stuff out let's take a look at the code now and see how it all works and then we'll dive into some of these other fields and see how they're set up we'll start with the tester code it's really simple we've got a single method here play effects and this is actually called from those other menu buttons that you saw in the UI as well so I've got a button here using the Odin button option I'll leave a link for that down below if you haven't used Odin you should definitely go try it out but all it does is create a game object here name it ability effects it adds the ability effects component sets the Caster the targets the definition and then tells it to play now of course this is not super optimized and it could pull these things reuse them and it will eventually but for now it just creates one and then throws it away because that's a very simple problem to solve afterwards the hard part is making it so that everything can be put in as quickly as possible and that the data can be tested and added let's go take a look at the ability effects we've already seen the ability effects definition actually I'm going to hit F12 on it just so you can see what it looks like and please don't kill me for the naming because it's got terrible naming schema right now it has a bunch of public Fields with under scores for the names which makes me really really sad but I just haven't gotten around to hitting the rename hotkey and making them all uppercase and Pascal case I know if this really bothers you drop a comment down below but it will change eventually and and I'll fix that up but I've already got the data in there and I just haven't gotten around to making the change but this is all of the fields that you saw notice nothing else in the scriptable object all of the work is done in this ability effects object it is set to execute in edit mode although I found that I no longer need that because I'm always hitting run now and playing it instead of doing it in edit mode like I was initially it's got a couple things on it that ability effects definition the caster and targets just like we had before we want to keep track of those for this specific object uh we have a game object for our Caster effects that's the object that we're going to instantiate for the Caster a list of them for the Target effects one for things that will fire off on the target immediately the projectiles that fire fly to them and then the impact ones that would fire or fly off to them or fire off when the projectile hits them there we go got my words out and then finally a list of co-routines that are running and this is the routines that are moving the projectiles towards the target so in the play Method we kick off a co- routine that plays the FX routine and then in here we do a whole bunch of things we start by checking to see if we have a Caster animation again this underscore ah makes me sad but I can get over it for now now if we have one then we get the animator from our Caster if we don't find the animator we get it from the child and if we still don't find it while we continue on but if we do find it we set the trigger for that Caster animation now again could be optimized trying to keep it super unopinionated for now so it's just going to call a get component and then once it get around to the point where it needs optimization I spend the 20 minutes wrapping all this stuff up and making it nice and fast the next part is the Caster transform so you want to find the part on the body where we want to hit so first thing we do is look for an object by this name cter Target transform is actually a name and you see that most of them most of my ability effects if I can get to them they're searching for a transform named body so the target transform is body and actually the Caster one is supposed to be muzzle and that's where it fires off from so it'll fire from the muzzle object to the body object and this is another really interesting and fun thing let's take a look at how that works in game and why it's so cool all right to make things interesting let's take a look at a not gelatinous Cube using a not Stormtrooper shot to blast an insect and can see right here by default he's shooting from the base and hitting them on the base this is actually really easy to adjust and we don't even have to stop playing can control click let's see or shift click there we go to go select my Cube here I can open it up in prefab edit mode and go find the spot that I want to use as the body and as the muzzle point so here I'm going to say that I want to shoot maybe like right from the center this looks kind of Center is so I'll add an object here a right click and hit create empty we'll name it muzzle and then I'm going to oh I've already got a body added on here so I don't need to add one of those now I'll go back out save and check this out if I go back over to Game Mode and just respawn a cube start shooting and now shoots right out of that muzzle spot but right now it's hitting this guy which is a this is the Mantis right hitting my mantis on the feet so let's go find the Mantis again shift click oh my shift click didn't work that time okay I'll just go find the Mantis some reason my shift click doesn't always seem to work but if I find my object here or I just go to the usual thing I use V tabs makes it so easy to go find stuff go find IM mantis for insect mantis double click on the object here and we open this one up what I can do is go find The Body Spot where I want the center to be and you want to look through the bones here and usually it's going to be something off of the spine um maybe pelvis abdomen right around here we right click create an empty and call it body we can go back out exit back out go back over to the game view again still playing don't have to change anything go back in and start shooting and now it's it's Landing right there of course I changed this guy's uh as the Caster so I should probably give him a point where he can shoot from as well so let's go back in and add a muzzle so go back to scene View and I think I'll use like a let's just go for like the top of his head or something his neck his head his antenna maybe like one of his antenna like right there that that antenna I should probably use like a spot right in between the two antennas I think might be even better so let's go with the head We'll add a new object call this muzzle and I'll move it up just a little bit make sure that we're in local space so I can make sure that it's aimed right as well so then I want to rotate it was it going to be 90° nope and then negative 90 I just want to what I want here is the blue forward and the yellow or the green up so that way it's aiming forward straight out of its head it's going to look kind of like a muzzle shot coming out of his head for some things might look a little bit weird but it's a lot better than coming out of the feet so let's try this out we get back in and we go repick the Mantis and we start shooting Trooper shots now they come out of his head and they land at the body obviously things like the Spore Splash might look a little bit better or I don't even remember what his ability is supposed to be one of these probably not the uh the fire now let's uh jump over to the code again so you saw we got that Caster Target transform that was the body that I wanted to shoot at and if we don't find one then we just use the base that's why it was going to the feet instead then if we have that once we have that transform we look to see if we have our Caster effects if we do have a Caster effects then we play it on the Caster at that Caster transform part and I lied this is not the body this is the muzzle so this was the muzzle one first and then we use the other one um let's continue on so well after we instantiate it we check to see if we should parent the object or the parent the particle to our Caster if so we just parent it and then we make sure that it's set active it is a game object sometimes people turn these things off so I want to make sure that it's on plus when we start pulling it this would probably get turned off and reused later next we check to see if we have effects for the Target these are the impact ones or if we have ground Target effects if we do then we wait for the amount of time for that delay which is just so that we can wait for the impact and then we check on 63 to see if we have it at a ground Target one if so we play that at the position on the ground and we don't parent it to the object otherwise or the other thing that we do so this also let me say it let me stop for just a moment this bit of code here for ground Target effects is also the thing that would do like your ground circles so you get a circle on the ground where a Spell's landing and Fireballs are all hitting this is the one that would do that so it'll spawn one right at the object at the first Target basically so it looks at Targets grabs the first one and does it right there then we Loop through all of the targets the AOE targets and these ones might need like a little explosion playing on them or something and they'll also need to play the animation this will also hit the first Target so the animation will play it'll play an animation if one is selected and then it'll Loop through find the child this is where it finds the body that I lied about earlier and then it'll find the target effect and then play it on the on that one and then finally if we have any this that are projectiles we'll do the Caster to Target effects and to do that we add all of our routines we by we go through and loop and add well we say let's see if I can get my words right we're in a loop right here for targets so this is the loop of targets and we're going to in that Loop add a new co- routine for each one of these that is getting a projectile a co- routine calling Caster to Target effects we add it to this list of code routines so that on line 110 we can wait for all of them this will run them all asynchronously I mean technically it's not it's not threaded but it is asynchronously so it's going to run all of those co- routines and then wait until they've all landed and done their impact and then once they've done their impact it will destroy them all the last bit to look at is the Caster to Target effects this is the one that's going to spawn an object at the caster and then it's going to move it towards the Target right here on line 144 so it's going to wait until it gets within 0.1 M and until then it's going to keep moving closer and closer and closer there is an ability to offset it if you want using this target impact offset which I was using to play around with the not Storm Troopers missing all of the time but also for just offsetting the impacts of things and then at the end we play the impact animation for all of them that got impacted and then finally play the impact particle for all of them this looks like a lot of code but you have to remember that this is just one line of code here split up so that it's a little bit easier for you to read and this is setting the object to active and adding it to the list all of these are really just making sure the objects are around moving it around and then making it work since it's all done in scriptable objects it's all just totally optional or totally modifiable at runtime so you can go in and create new things you can go create a new entry here hit refresh it will reload all reload it from here go add in new characters like I showed you just a little while ago and you can do it all while you're playing and then this all again Works while you're playing the game as well so this is step one something to threw together on Wednesday just to make it a little bit easier for me to start putting in effects you can see I've only got a maybe like a little more than a dozen in here so far but now that I've got this system set up it's only going to take me a couple hours to put in enough to fill out 50 to 100 characters and the goal here is to have 100 plus characters you can pick from so it's got to be a fast easy process to make sure that I can get the data in get the content in that I want without wasting any time so that that's all there is to this one hopefully this is helpful if you want the code it's available on the page at game. courses I'll make sure to link it down below and um if you have questions about it drop a comment if you want to see the game make sure that you're subscribed I'll be putting up a bunch of videos about it really soon just been putting it together quickly and it's a lot of fun be multiplayer and you'll be able to play it sometime very very soon um I have the demo out as quick as possible if you want to see that too just drop a comment down below and um I will maybe add you to the uh the short list all right thanks again don't forget to like subscribe check out all the stuff as the page at game. courses and um check out some of the assets I'll link them down below in the description some of the assets that I've used in here there's a lot of really cool ones I'm using all stuff from the asset store using like this uh I I need to find a tower that I like more but using all particles and effects and other stuff and characters from the asset store so if you have recommendations thoughts something that you want to see kind of go in maybe you you're like oh I really want to see a dragon where is that Dragon where's where is my oh there he is young dragon V2 you're like I want to see a dragon in there and then I'll put your dragon in or whatever and if you got characters or effects that you want to see in too I'm totally open to just about everything working on uh anime characters and a couple other things right now going in there's even a spaceship it's blasting the bad guys all right that's it for this video thanks again for watching don't forget to again like And subscribe drop comments let me know what you think and uh I'll see you in the next video bye
Info
Channel: Jason Weimann
Views: 4,639
Rating: undefined out of 5
Keywords: unity3d, unity, unity technologies, unity games, gamedev, game abilities, gamedev abilities, jason weimann, game coding, moba, moba coding, moba gamedev, assets, unity moba tutorial, moba games, unity tutorial
Id: NBhmgRWlnnQ
Channel Id: undefined
Length: 18min 30sec (1110 seconds)
Published: Fri Apr 05 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.