 This video was brought to you by my patrons. Thank you so much for your support Hey, last Friday, I released a game the Fermi Parallax which is based on the Fermi paradox the Fermi paradox basically states that if there are It is mathematically impossible that we are alone in the universe But even though it's impossible. Why did we never met with with each other? Why did we never met with other? civilizations and one of the explanations for this paradox involves a lot of filters evens on the universe that prevent this but some scientists Try to explain this by saying that there is a higher level civilization in civilization with a high intelligence that is preventing this from happening it is preventing us from meeting with other civilizations and in the game the way that these civilizations are represented is by the player's enemies and especially By the games boss, which is the paradox So in this video, we'll see how did I manage to make this boss and this boss battle? Actually, we'll just talk about the boss pattern, which is The way that the boss behaves a window windows the the boss will shoot when will the boss use the super attack When will the boss just slap when it will die and stuff like this and for that We use the building animation tree because it has a building state machine Finite state machine in which we can manage everything that we need to make this boss pattern. So without further those Let's get started So I have the the boss seen open here and Something that you need beforehand is the animations that will define the boss behavior And something interesting that you must think about is that these animations will kind of represent the boss states We won't need to represent and encapsulate these states in the script You can basically encapsulate all the behaviors through the animations because you can set properties you can call methods so you can consider that each animation is a state by itself and Basically what you are going to be doing is transition between each of these states So now with that state you can see that I have a lot of animations here Deriving the setup, which is the animation that will basically reset everything to its default arriving die idle and left hand attack the left hand laser the super attack, which is this mouth attack But with that with all these resources done and this will depend on your way to design your boss Basically what we are going to do is to add an animation tree the animation tree Request that we set up an animation player, which by default we are going to use the the current animation player here This is what controls everything in this box. So I will set up this one animation player and We also have to set up the tree root. This is what will We'll control which kind of animation tree you're trying to set up You can set up a blank tree. You can set up a blank space and but for our purpose We are going to set up a animation node state machine. This is what we want Now that we have this blank canvas we must set up every transition and every state that we want to the The character in this case the boss to to be in so let's start with the setup as I say This will reset everything to its defaults which is what I want by in the beginning of the the game and To ensure that this will be auto-played just as in the animation player as you can see This is an autoplay animation here We can use the we can to go this option to go autoplay this animation on start So this is the first thing that will played when this animation tree starts to to play Then I wanted to play the Arrival animation and here comes the the interesting part. We have two states right now So we need to transition to transit to the next one. How do we do that? By holding shift and dragging from one state or from one animation to another we create a transition and If you click on the transition you can see in the specter that we have some properties and the way you can transit automatically to the next animation is by Toggling the the auto-advanced property. This will make sure that it will transit to the to the next animation Automatically, but we can set up the switch mode as well in my case for my boss I just use the at-end switch mode This will make so that when this animation finish it will automatically Transit to the next one in this case the arrival the rise then in my case after The boss arrives, which is this animation where the boss grabs the screen and comes from the from deep from the deep space all The way to to the screen After that, I want the boss to center the position on the screen. So move to center Same thing when this finishes it will automatically transit to the move to center So I'll set this at the end auto-advanced and After this after the character after the boss moves to to the center of the screen I wanted to start the idle and mission and same thing I will transit from the move to center to the idle Automatically at the end Now after some attacks I want the after some idling after some time idling I want the boss to start attacking but here comes the interesting part since we have the left hand attack and the right hand attack Which one should the the boss do which one should the boss perform after it? It triggers the idle Now we have to make some logic We have to add some logic layer on top of this of this state machine, right? So before we actually dive into the The logic the scripting part. Let me explain something to you We'll start by just Transiting to the left hand attack, which is this left slap So I will add a new transition here shift and Drag it to the left hand attack and you can see that we have this advanced condition The advanced condition is a string that you can set up and once you set this condition to true It will automatically it will basically trick trick this auto advance to be on This is exactly how they explain this turn on auto advance when this because it when this condition is set So what we are going to do is to give it a name. So let's say left slap and I will do the same thing for the the right hand attack the advanced condition will be right slap and Well after the character finished the the left hand attack it will automatically transition back to the idle So immediate will set this to at end auto advance and here I also want this to happen on At end but here is when the immediate can be useful So let's say your character may have performed the idle animation three times and you want it to immediate trigger an attack This is not my case, but you can leave the switch mode at immediate But I will switch it to at end Then at the end when the left slap is true, it will perform the left hand attack so let's start by This is something that I think that I will make a contribution to the good at repository because I Think that this is something that is missing in the animation tree I will start by adding a script to it. It can be a bidding script and Basically, the only thing that this will do is to give a better interface to other other classes to interact with the animation tree because what happens is that We don't have a nice an easy way to set the value of a condition So the the way that we are going to do is the following We will get a transition. We'll get the the condition name which should be a string and the value So this is the complex part because in order to set the the value of this condition if we go to the animation tree and we Go to Parameters conditions. We have the left slap here available to set on and off the right slap as well But in order to access these conditions, we had to go through this path This note path so parameters slash conditions slash left slap So to prevent other classes to knowing all this path We are just going to encapsulate the access to these conditions to this method So we are going to just call the set and Copy this parameters slash conditions Slap slash And then we are going to add the conditioning condition name and past the value So let me just verify this is correct parameters Conditions I missed a and here Conditions and the conditioning. So this is the interface that we are going to use to set the conditions, right? Now we can actually give the logic So for the logic, I am going to attach a script to the boss and it won't be a bidding script Something that we are going to to set up here is what will trigger the the left slap for instance What will trigger the the attack of the the boss for my boss? I use something that I call to show it. So for instance, I have an attack to show So now let's let's design the the actual boss behavior, right? So I think that I will add some comments here Okay, so for the design of these boss, I want these behavior here Every two idle animations the boss will attack it will perform a slap by default It will perform the laser animations every seven damage taken and a special attack a special attack Every seven damage taken and the health is below 30% It will die if the health depletes, right? So let's start by setting up the tree showed for the idol for the attack, right? So we'll have an attack tree shows Which by default will be One right so after one animation it will perform the second one and then it will slap or attack and we'll also need a Verbal to store which is the current value how many idle animations the character already performed. So Var I don't count By default, it's zero We need something to to iterate on this idle count. So let's create a method to increase idle Count which will Basically just increase this I don't count Plus one I don't write Plus one and it will verify if the idol count Is greater than the tree showed so attack tree showed if so, it will reset the idle to zero and And I will leave this commented, but it will call them a attack method So we might already have this right. So let me create the that tech method And we are just going to pass right now, but just so we have a breakpoint here statement So I forgot that if statement And this so how we will how will we increase this how we will call this method here so we can Increase the the counting of the idol in the idle animation At the end, I will take rid of that at the end. I will tell it to call a method on the boss that is called Increase idle count So every time the idol finishes, we will have the idol count increase it, right? Yeah You may ask yourself why we are not using the animation finished and checking if the if the animation that just finished Is the idol is because since the idol is a loop animation the animation finish Signal is not called This is I think that this is a bug but some people say it's an expected behavior So the best way is to just add this at the end to add a method call at the end So if we test this, let's see. Oh Something that you must activate is set the animation tree active, right? So let's do that and test this Okay, I don't one two Yeah, we are calling the attack method. So this is already working, right? So this is already working It's left by default. So the next thing that we are going to do is to create an array with two With two values, which is the the left the left slap and the right slap So we can randomize which one we are going to use for the the boss attack set Which I will also create a variable for that. So a constant Slap Slaps yes, no left slap and Right slap right slap And we are going to have a text set The variable that's called a text set This is which attack the character will use because at the end of the attack method We are going to use that to call to set the condition on the animation tree. So that's set By default, I think that I will set this to be the slaps by default So by default it will use this this attack set Now what you are going to do here I need a reference to the animation tree bar mission tree and Oh, yeah, we are going to On the ready function We need to call the randomized method just so we can sort out the the random factors so we don't always have a Random palette a random pattern. So by calling the randomized pattern The randomized method we prevent that from happening And right here what we are going to do is to have a attack Verbal attack Which by default is new And what we are going to do is to Go to the attack set The I think that we can call this in Online, right? So we are going to get the attack set a random integer That will be a random value Going to the the size of this attack set was this array that set That size So this is basically randomizing a value and modulating it by the random By the the size of this array and this is how we can get integer In random integer values So Next what we need to do is to actually call the Tracklist set the the condition on the animation tree. So a new tree that's set condition Attack True This is basically what we we need for for this to to Make what we want But there is one thing that we need to to do because if this is Set true and we don't make it go back to false. The character will keep slapping all the time Let's let me show you what what I Want to say by that. So one two slap And it went slap again And slap again so Oh, it is not calling the the right the right slap But we we want this to to be done only when the the idle count is greater than Than the attack tree should write So we want this to to be back to To false and this can be done in the animation itself. So Left hand attack at the end of this animation. I will add a property track on the Animation tree And on the left slap So it will set this to false So it won't go back indefinitely And we are going to do the same for the right hand attack Add a track property track animation tree Right slap And a third key I think that for the for the setup transition here We can set it immediate because we don't need it to to go all the way To the end to to play the arrive animation Yeah, like this to slap And it's not coming back probably because we don't yeah, we didn't set the transition here the end Also advanced So let's see One two slap one two slap Yeah, so let me just see if the left one is also working seems like the Only the the right one is in plate So I think that something that you can use to to debug this is to always make this window always on top And pause the the game going to the remote scene and see if these No, both of them are false So it's basically just yeah the left one just played. So it's just a a bad design a bad Random random factor now With that we have everything we need to set up the the boss pattern. So From now on, I will just basically finish all of these All of these conditions here And I will be right back with everything set so you can see the the whole script Something interesting that I want to show you is as you can see The way that it will trigger the laser attacks Is if the hurt count is greater than the laser to show And the hurt count increases when the character takes damage, right? So when the health changes So how will you how will we test this if we don't have a player hurting the enemy? Well, we can basically test the scene make this This window always on top and as I said Uh, we just have to go to the remote to the boss healthier decrease it by a bit Just so we can see if the laser yeah, so now we have the lasers working And this is how you can debug this the features This method this technique without actually having the the player on board So seems like we finished all the conditions So every two idle animations the boss will attack. This is what we have here It will idle once then twice and then it will start the attacking It will slap by default. So the attack set is set to slap We have all the attack sets here The super true showed which is a float it is basically just a percentage of the maximum health So it will first see if it can perform a laser to show which is meant to be after nine damage taken It increases the hurt count by one. So this is what Tells if it should perform a laser attack or not every time the the character got hurt it will increase this Actually, I think that this could be here. I don't know If it can't perform a laser attack and the max the the current health is equal or below Or lower than the maximum health multiplied by the super true shows This means uh when the character got its health below 30 percent It will start to use the super attack and after that we just set the attack to the current attack set and Pick randomly one of the the attacks inside of this array inside of this list In the case of the supers we just have the the mouse and Lastly If the health the the please which is when it reaches zero It would tell the animation tree to trigger the the death Transition which as you can see essentially Everything but the mouse attack which i'm setting right now Transits to the die to the die attack to the die state the death state So if we try to play this level three Hopefully this will work. So, uh Firstly, I have to set this on the level three to play the boss So we have the boss there. Okay, everything is working slap attack Slap attack one two three four five six seven Yeah, we have the The laser now. We don't have the feedback of the damage, but Yeah, we have the the lasers Let's manually decrease the the boss health with boss health. So I think that 10 will be enough And if I play this Oops Yeah, mouth attack Now let's kill this bastard And the death animation So that's it That's how you can set up a boss pattern or a boss behavior pattern using good Using essentially animations a little bit of code just enough to to make the transition to trigger the transitions And of course the animation tree with the the state machine With the state machine brute node So all of these is possible thanks to the patronage firstly And I will really really appreciate if you guys could like support me on either patreon or buy a crying The the game on each I put all the links in the description. This is what makes all of this stable. This is what Allow me to produce more of this content. So if you like this content Support me. So that's it. Thank you so much for watching. Keep developing and the next time