‫Hello and welcome.
‫This lecture, we're adding a health bar, as you can see in the bottom left here.
‫We're also making our player a lot tougher than the enemy so that we can go around and actually shoot
‫up lots of enemies and kill them off before our health depletes.
‫So let's dive in and see how to make that health bar.
‫So at the moment, we've got no way of knowing whether we have enough health left.
‫As a player, how long have we got left to play based on our current amount of health?
‫Now let's do this.
‫I would like to introduce the health bar to our hood.
‫So we're going to do this by going over to our HUD widget.
‫If it's not already open on your ED and we're going to look for in the palate the progress bar and bring
‫in this progress bar.
‫Now, why a progress bar?
‫Because actually it has all the attributes of a health bar as well, namely that if we scroll down in
‫the details pane to the percentage, then you can see that by changing that percentage, which is actually
‫a number between zero and one, so slightly confusingly named, you can see that we get our bar fill
‫up and drain away.
‫So what we're really going to want to do is start at a percentage of one and then drain it down until
‫we reach percentage of zero, which point our play is going to die.
‫So that's the aim.
‫What I want to do here is also go ahead and change the fill style.
‫So we're going to fill it up a little bit and then look at the fill image and change.
‫Let's see if we can change that tint.
‫To something like a bit of green, typical health color there.
‫And then just to make it super obvious.
‫What we've got here is indeed health.
‫I'm going to add a text block, label it health and going to go and stick that next to our health bar
‫like so.
‫And then selecting both of these components, I want to anchor them to the bottom left so they move
‫with the bottom left edge of our screen.
‫So that's what I'm going to do.
‫It's gone and change the anchor defaults and I'm actually going to move them both a little bit close
‫to that bottom left edge.
‫And I'm going to compile this and let's go and have a play.
‫If we have full screen, you can see the health bar is right there at the bottom left, though obviously
‫it isn't currently representing our health at all.
‫So to do that, what we're going to do is expose a function from Ashe through to character, CPP to
‫blueprint so that we can get this in the Uag widget.
‫So I'm basically going to copy the blueprint pure that we have for is dead, but instead of returning
‫a boolean, we're going to return a float, which is going to be this percentage between zero and one,
‫not technically a percentage, more of a fraction, but hey, and we're going to call it the get health
‫percent.
‫And we are going to want it to be both blueprint, pure and const, because it shouldn't, when we call
‫it, change this class in any way, then we're going to go ahead and control shift p, create the implementation
‫and what we want to return is the health as a percentage here.
‫So think about it, a little mini challenge for you.
‫How would you do calculating health here as a percentage of the total health?
‫Welcome back.
‫So let's see if you had a go, it would be health divided by max, health as simple as that, because
‫when we have our max health, it's going to be one.
‫When we've got zero health, it's going to be zero and everywhere in between.
‫So let's go back over to the editor and compile.
‫Then we're going to go over into our HUD UI and somehow we need to get hold of that character.
‫So what we're going to do is go to our progress bar and then scroll down to where we had that percentage
‫property.
‫And next to it you can see there's a button called bind.
‫If you drop down that and create binding, then this is going to create a function whose job it is to
‫get that percentage value.
‫And every time this returns a different value, it's going to update the UI.
‫So that's fairly straightforward.
‫It's called get percent.
‫Let's give it a better name.
‫I'm going to click on it, go to the details and rename it to Get Health like so.
‫And then what we need to do is somehow get hold of our character.
‫Now the way we can do this is, first of all, this UI is attached to the player controller, so already
‫we can get hold of the play controller.
‫And then from the play controller we can get it's controlling --.
‫And in fact, if you just search for pawn, you can see that there is a get owning player pawn which
‫directly does this.
‫It goes ahead and gets the owning player, then it gets the pawn that it is controlling.
‫And then from there, what we need to do is a cast to the shooter character in order to have access
‫to the function we just created.
‫And then from there we can get the health percent and we can just go and funnel that in to our return
‫node and make sure we pass in our execution pin from the cast shooter character.
‫Then I'm going to go ahead and compile and save that and hit play.
‫And what we should see is a health bar 100% and then going down as we get shot, I was a little bit
‫slow to see that.
‫So I'm going to go and do that from the main level viewport hit play health bar at one, then it goes
‫to half, then you die.
‫So that's all happening a little bit too quickly.
‫So I'd like to challenge you to increase only the player's health, not the A's health.
‫I want to have the feel of the level be that you two shot kind of kill the enemy.
‫But then your player has a lot more health and it takes a lot more shots off the AI to actually get
‫you to come down because you're a big, strong hero.
‫So the idea here is to create a child for the player.
‫So this is going to be a child of the character class, but not just of the character class, probably
‫already of that blueprint class.
‫You're going to have to override a few different variables.
‫Namely, the max health is going to be higher for the player and maybe you want a different mesh to
‫differentiate you from all those enemies around you towards a video and see if you can have a go at
‫this challenge.
‫Okay.
‫Welcome back.
‫So we're going to go up to the content folder and we're going to find ourselves the character.
‫We've got BP shooter character.
‫I'm going to right click on that and I'm going to create a child blueprint class here, which is going
‫to be a BP underscore player shooter character like so.
‫And now opening up this blueprint, it's going to have all of the same properties of its parent blueprint
‫because those were already set in the parent.
‫But now we can choose to override a few things.
‫The first thing I'm going to override is the mesh.
‫So we're starting off.
‫This is a red mesh.
‫I think that's good for the enemies.
‫But what I would like is the green mesh for my hero.
‫So it's going to be super obvious that he's a different guy.
‫Then we're going to go over to the root or to the class defaults and change up the max health.
‫So I want him to have roughly ten times as much health as the enemies in this level.
‫So I'm going to go ahead, compile and save that.
‫And then one more thing we've got to do is go and change our blueprint.
‫So we're going to go and find the BP KML gain mode and we're going to change the default -- class
‫from the BP shooter character to the BP player shooter character because we've already got our shooter
‫I placed in the world and then we're going to go ahead and hit play.
‫And you can see we've got ourselves a different character.
‫He's got a different look.
‫And when he's getting shot at, we're getting the health bar going down much more slowly and I can to
‫short kill off the enemy.
‫But it still can be quite challenging if you place enough enemies in your scene.
‫So that's it for this lecture.
‫We've seen how we can add a health component with binding and with a progress bar component.
‫In the next lecture, we're going to be looking a little bit again at animation in order to get our
‫player able to aim up and down with the mesh.
‫I'll see you there.