HOW TO MAKE A BOSS BATTLE WITH UNITY & C# - TUTORIAL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to black thorn prod I'm Noah and in this video we will create a boss battle now all games are different in some ways and as a result all bosses will be specific to each game but despite their differences many bosses do follow a similar structure they'll play an intro animation as soon as the player sets eyes on them and from there they'll throw the player challenges he'll need to or comma in an action game for example this will be various attack patterns the player will have to dodge and then once the boss is midway through being defeated is usually a stage - resulting in the boss character changing appearance to look more dangerous enraged or cunning and you'll also change attack patterns or do the same ones fully faster as can be the case in an action game and so in this video we will bring our very own boss character to life with an intron amasian random attack patterns two stages of difficulty a death states as well as in your health bar now I'll be making an action-oriented boss but again a lava will be shown here can be applied to any games boss character so I currently have a simple project setup with a player character that can move left and right and handle a weapon that shoots projectiles these product Isles will tell me boss characters and damage and spawn some particle effects it would be great if we could see how much health the boss still has land so let's make a health bar doing so is very easy simply head over to UI and create a slider remember to set the canvas scale mode to scale with screen size and type out your game's current dimensions so that the UI will fit nicely with multiple screen resolutions okay I'll start by deleting the handle slide area which is mostly only used if you're using the slider for an option setting like the game's music volume for example which isn't the case here now this slider looks a little ugly I'll change the back graphic - this round edged rectangle I made in Photoshop and then simply change the size of the bar so it's thicker now you'll see that I can select this slider head over to value and move this handle around and my health bar will fill up or empty cell I'll make sure to change the health bars fill to some red color as tell that boring whites now all we need to do is change via code this value so it matches the value of our buffs characters health so I'll head over into my boss character script and add the using unity engine dot UI namespace which I remind you is necessary to tweet anything UI related via code now I can make a public variable of type slider called health bar and simply say it's value equal to the bosses health value and there we go now my boss character starts with 50 health so I'll make sure that these sliders max value is 50 and then drag and drop it inside that empty slot in the inspector and hit play and you'll see that by shooting any boss the health bar would be by bit empty self of juice you can of course add a cool little boss icon image here to me the bar look cooler as well as a little drop shadow components to the health bars backgrounds awesome our boss's health bar is complete and of course you could also make a similar health bar for the player if you want now my boss character has various animations there's an intron amasian I want them to play this as soon as the game starts and then for in stage one he has two behaviors he will be switching between his simple idle behavior that will see the boss simply catch his breath then he has a simple jumping at a behavior where you'll hop up and down moving towards the player and trying to squash him and then once he reaches the half health mark he'll play a stage two in tradition in which his face transforms revealing bloody red teeth and red gleaming horns from there you'll either play a faster paced more frantic idle animation or a speedy more dangerous jumping attack animation ok finally he has a death animation for when he falls twos your health now before continuing with this tutorial I highly recommend you first check out my videos on unities animator and state machine behaviors says we will be diving headfirst into the enemies and the state machine behavior world right now on so as you can see here I have many rectangular boxes each representing one of the bosses animations the one highlighted in orange is the animation the boss will play by default currently his first idle animation is set has the default animation I want the intro one animation to be the default one so I can simply right-click on that intro one animation and choose set has layer default States and there we go that's the first thing the boss will play now once the boss has played his intro animation you're either transitioned to his first idle animation or his first jumping attack animation so I'll create to trigger parameters one called idle the other jump and then right-click on my intro 1 animation and choose make transition and I'll simply make a transition going from the intro to the idle animation adding a condition to this transition that the idle parameter must be triggered so in other words once we trigger the idle parameter via code the character will go from his intro animation to the idle animation also make sure to leave has exit sign checked with a value of 1 this way 100% of the intro animation will play we're transitioning to the idle animation downtime 0.1 from the transition duration so that the transition is fast but not completely snappy I'll now make a similar transition going from the intro to the jump 1 animation except this time I'll only transition between those two animations if the jump parameter was triggered and so now I'll randomly choose which two animations to play first I can do so by adding a behavior to my intro animation so I left click on it and choose and behavior calling it the intro behavior I'll then open that up inside of Visual Studio so have seen in my previous video were greeted with a bunch of comments I'll remove the forward slashes for these three functions as well as removed these comments here I'll also get rid of these two commented functions I won't be using these during this tutorial now quick recap this on state enter acts has the star function in other words it will get cold when the animation first plays this is like an update function that will get called every single frame as long as the intro animation is being played and this on States exit function will get called once when the bus stops playing his intro animation so I'll simply make a private int variable called Rand for random and inside of that on stage enter function I'll set that equal to a random number between 0 and 2 remember that 2 is not included so Rand will either be equal to 0 or 1 it is equal to 0 then I'll simply type animates or dot set trigger and in the parentheses type between quotation marks the exact name of one of the trigger parametres we made just a moment ago for example idle if it not equal to 0 though so if it's equal to 1 they'll simply play the job animation instead and there we go that's how we'll get the boss character of playing a random animation either if idle 1 or his jumping attack 1 it's all hits play my boss will play his intro and then transition to his idle or job awesome of course we don't want him staying in his idler jump state all the time but to switch between those two animations every X seconds so I'll make a transition going from his idle 1 to his jump 1 if the jump parameter was triggered and vice versa if the idle parameter was triggered I'll select my idle one animation and add a behavior to its called idle behavior here I'll make a public float variable called timer and in my own state update function I'll check whether timer is less or equal to 0 if it is then I'll transition to the jump attack States by simply typing animator dot set trigger job if it isn't less or equal to zero then I'll slowly decrease it using the famous - equals tiny dots Delta time of course you could make the timer value random to do so simply make a public float variable called min time and a public float to Max timer and then in the on state enter a function set timer equal to a random number between min time and Max time now notice that if you're more than a jump attack States you could randomly choose which animation state to transition to like we're done for the intro animation we randomly transition to either idle or jump ok back instead of unity I'll not forget to type out my min and Max values they'll add a behavior to might jump one animation called jump behavior here I'll make the same timer as I did for the idle animation and then transition to his idle States I also get this boss moving to more the player when in this jumping attack states to do so I'll simply grab a reference to my players transport position and that move the boss character to war that position in the on state update function with a certain amount of speed possibly set in the inspector back in unity I'll type out a value for the min and Max time and then for speed and now I can hit play the boss will please intro then he'll randomly transition to his idle States there he'll stand for a random small two seconds for jumping after the player and then after a few moments he'll transition back to his idle States greats so to recap this idle behavior scripts is only working when the boss is playing his idle animation and this jump behavior script is only working when the boss plays his jump attack animation ok it's now time to shake things up by adding a stage to to this boss character so I'll make another trigger of parameter called stage two and get my idle one and jump one animations transitioning to the intro to animation when this stage to parameter has been triggered and I'll only trigger that stage to parameter when the boss reaches only half of his initial health so I'll head over into my boss scripts and make a private variable of type animator called animal and said that equal to the animator component attached to the boss character and now I'll check with an if statement whether health is less or equal to 25 which in my case is half the boss's health if that's the case I'll type Anand or set trigger stage 2 so you'll see that indeed when the boss reaches 25 health kill transition to his angry more dangerous looking self and now all I need to do is make a transition going from that intro to enemy to my idol to animation if the idol parameter was triggers and same thing for the jump to animation if the jump parameter was triggered and then simply add the intro behavior to that intro to animation and the boss was i''m plated to abandon a transition to his idle or jump to animation of course if you add more animations for stage 2 or animations with different names then you simply have to create a new trigger parametres and also make a new behavior just for the intro - which would get the boss randomly transitioning into those new states okay with that said I'll make the transitions going from idle to jump and from jump to idle and adding the idle behavior to my idle - States and then of course adding the jump behavior to my jump to States and now our bosses really comes to life transforming himself when he's reached 25 health and playing a more vicious jump attack animation and a more frantic mad idle animation all we now need to do is get this boss transitioning to his death state when he reaches your health so make a last trigger parameter called death and make two transitions right here that will only work if the death parameter has been triggered they can go inside of my actual boss script so check whether the boss has your health or less and if so I'll play his death animation it's as simple as that and so testing this out - indeed see that pond falling down choose your health the boss will fall down dead and defeatist and down mark the end of this how to make a boss battle tutorial so to recap you can easily make your boss character plate intro animations get in transitioning between random States and even give your villain multiple stages to increase difficulty with the use of the animator and state machine behaviors so hopefully from now on creating bosses will be an easier funner task with that said thanks so much for watching if you enjoyed and found this video helpful then anything the like and subscribe buttons would be so appreciated and encouraging we also consider supporting me and my contents financially via patreon like these awesome people okay stay choose you very soon [Music] [Applause] you
Info
Channel: Blackthornprod
Views: 180,132
Rating: undefined out of 5
Keywords: blackthornprod, gameDev, unity, tutorial, noaCalice, c#, programming, art, animation, boss, boss battle, boss AI, create a boss character, designing a boss battle, boss in unity, boss battle tutorial, enemy AI, 2d, 3d, health bar, UI, state machine behaviors, animator, animation transitions, coding, beginner, HOW TO MAKE A BOSS BATTLE WITH UNITY & C# - TUTORIAL, easy, hollow knight, boss stages, random patterns, attacks, stage 2, multiple stages, difficulty, intro animation, slider
Id: cXefXSD2SM0
Channel Id: undefined
Length: 12min 48sec (768 seconds)
Published: Thu Aug 23 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.