﻿1
00:00:04,500 --> 00:00:05,250
‫Hello and welcome.

2
00:00:05,250 --> 00:00:08,310
‫This lecture, we're adding a health bar, as you can see in the bottom left here.

3
00:00:08,310 --> 00:00:14,610
‫We're also making our player a lot tougher than the enemy so that we can go around and actually shoot

4
00:00:14,610 --> 00:00:18,410
‫up lots of enemies and kill them off before our health depletes.

5
00:00:18,410 --> 00:00:21,240
‫So let's dive in and see how to make that health bar.

6
00:00:21,720 --> 00:00:25,950
‫So at the moment, we've got no way of knowing whether we have enough health left.

7
00:00:25,950 --> 00:00:30,240
‫As a player, how long have we got left to play based on our current amount of health?

8
00:00:30,240 --> 00:00:31,110
‫Now let's do this.

9
00:00:31,110 --> 00:00:33,840
‫I would like to introduce the health bar to our hood.

10
00:00:33,840 --> 00:00:37,440
‫So we're going to do this by going over to our HUD widget.

11
00:00:37,440 --> 00:00:43,770
‫If it's not already open on your ED and we're going to look for in the palate the progress bar and bring

12
00:00:43,770 --> 00:00:44,730
‫in this progress bar.

13
00:00:44,730 --> 00:00:46,080
‫Now, why a progress bar?

14
00:00:46,080 --> 00:00:51,480
‫Because actually it has all the attributes of a health bar as well, namely that if we scroll down in

15
00:00:51,480 --> 00:00:58,290
‫the details pane to the percentage, then you can see that by changing that percentage, which is actually

16
00:00:58,290 --> 00:01:03,420
‫a number between zero and one, so slightly confusingly named, you can see that we get our bar fill

17
00:01:03,420 --> 00:01:05,160
‫up and drain away.

18
00:01:05,160 --> 00:01:11,940
‫So what we're really going to want to do is start at a percentage of one and then drain it down until

19
00:01:11,940 --> 00:01:15,030
‫we reach percentage of zero, which point our play is going to die.

20
00:01:15,870 --> 00:01:16,980
‫So that's the aim.

21
00:01:16,980 --> 00:01:22,530
‫What I want to do here is also go ahead and change the fill style.

22
00:01:22,530 --> 00:01:28,410
‫So we're going to fill it up a little bit and then look at the fill image and change.

23
00:01:28,410 --> 00:01:30,300
‫Let's see if we can change that tint.

24
00:01:31,440 --> 00:01:36,330
‫To something like a bit of green, typical health color there.

25
00:01:36,330 --> 00:01:37,830
‫And then just to make it super obvious.

26
00:01:37,890 --> 00:01:40,390
‫What we've got here is indeed health.

27
00:01:40,410 --> 00:01:46,380
‫I'm going to add a text block, label it health and going to go and stick that next to our health bar

28
00:01:46,530 --> 00:01:47,430
‫like so.

29
00:01:48,100 --> 00:01:53,440
‫And then selecting both of these components, I want to anchor them to the bottom left so they move

30
00:01:53,440 --> 00:01:56,470
‫with the bottom left edge of our screen.

31
00:01:56,470 --> 00:01:57,550
‫So that's what I'm going to do.

32
00:01:57,580 --> 00:02:02,140
‫It's gone and change the anchor defaults and I'm actually going to move them both a little bit close

33
00:02:02,140 --> 00:02:04,330
‫to that bottom left edge.

34
00:02:04,660 --> 00:02:07,480
‫And I'm going to compile this and let's go and have a play.

35
00:02:07,480 --> 00:02:11,860
‫If we have full screen, you can see the health bar is right there at the bottom left, though obviously

36
00:02:11,860 --> 00:02:15,940
‫it isn't currently representing our health at all.

37
00:02:16,030 --> 00:02:22,840
‫So to do that, what we're going to do is expose a function from Ashe through to character, CPP to

38
00:02:22,840 --> 00:02:26,950
‫blueprint so that we can get this in the Uag widget.

39
00:02:26,950 --> 00:02:32,860
‫So I'm basically going to copy the blueprint pure that we have for is dead, but instead of returning

40
00:02:32,860 --> 00:02:38,560
‫a boolean, we're going to return a float, which is going to be this percentage between zero and one,

41
00:02:38,560 --> 00:02:44,380
‫not technically a percentage, more of a fraction, but hey, and we're going to call it the get health

42
00:02:44,380 --> 00:02:44,980
‫percent.

43
00:02:44,980 --> 00:02:50,410
‫And we are going to want it to be both blueprint, pure and const, because it shouldn't, when we call

44
00:02:50,410 --> 00:02:56,380
‫it, change this class in any way, then we're going to go ahead and control shift p, create the implementation

45
00:02:56,650 --> 00:03:00,400
‫and what we want to return is the health as a percentage here.

46
00:03:00,400 --> 00:03:02,860
‫So think about it, a little mini challenge for you.

47
00:03:02,860 --> 00:03:07,780
‫How would you do calculating health here as a percentage of the total health?

48
00:03:08,110 --> 00:03:08,800
‫Welcome back.

49
00:03:08,800 --> 00:03:15,310
‫So let's see if you had a go, it would be health divided by max, health as simple as that, because

50
00:03:15,310 --> 00:03:17,260
‫when we have our max health, it's going to be one.

51
00:03:17,260 --> 00:03:21,460
‫When we've got zero health, it's going to be zero and everywhere in between.

52
00:03:21,460 --> 00:03:24,250
‫So let's go back over to the editor and compile.

53
00:03:24,250 --> 00:03:29,470
‫Then we're going to go over into our HUD UI and somehow we need to get hold of that character.

54
00:03:29,650 --> 00:03:36,460
‫So what we're going to do is go to our progress bar and then scroll down to where we had that percentage

55
00:03:36,460 --> 00:03:37,330
‫property.

56
00:03:37,330 --> 00:03:39,760
‫And next to it you can see there's a button called bind.

57
00:03:39,760 --> 00:03:45,820
‫If you drop down that and create binding, then this is going to create a function whose job it is to

58
00:03:45,820 --> 00:03:47,500
‫get that percentage value.

59
00:03:47,500 --> 00:03:51,550
‫And every time this returns a different value, it's going to update the UI.

60
00:03:51,880 --> 00:03:53,290
‫So that's fairly straightforward.

61
00:03:53,290 --> 00:03:54,250
‫It's called get percent.

62
00:03:54,250 --> 00:03:55,240
‫Let's give it a better name.

63
00:03:55,240 --> 00:04:00,910
‫I'm going to click on it, go to the details and rename it to Get Health like so.

64
00:04:01,210 --> 00:04:05,830
‫And then what we need to do is somehow get hold of our character.

65
00:04:05,860 --> 00:04:12,820
‫Now the way we can do this is, first of all, this UI is attached to the player controller, so already

66
00:04:12,820 --> 00:04:14,110
‫we can get hold of the play controller.

67
00:04:14,110 --> 00:04:16,900
‫And then from the play controller we can get it's controlling --.

68
00:04:16,900 --> 00:04:22,480
‫And in fact, if you just search for pawn, you can see that there is a get owning player pawn which

69
00:04:22,480 --> 00:04:23,650
‫directly does this.

70
00:04:23,650 --> 00:04:27,610
‫It goes ahead and gets the owning player, then it gets the pawn that it is controlling.

71
00:04:27,610 --> 00:04:33,820
‫And then from there, what we need to do is a cast to the shooter character in order to have access

72
00:04:33,820 --> 00:04:35,410
‫to the function we just created.

73
00:04:35,410 --> 00:04:43,120
‫And then from there we can get the health percent and we can just go and funnel that in to our return

74
00:04:43,120 --> 00:04:49,330
‫node and make sure we pass in our execution pin from the cast shooter character.

75
00:04:49,540 --> 00:04:52,780
‫Then I'm going to go ahead and compile and save that and hit play.

76
00:04:52,780 --> 00:04:58,150
‫And what we should see is a health bar 100% and then going down as we get shot, I was a little bit

77
00:04:58,150 --> 00:04:58,870
‫slow to see that.

78
00:04:58,870 --> 00:05:05,290
‫So I'm going to go and do that from the main level viewport hit play health bar at one, then it goes

79
00:05:05,290 --> 00:05:06,790
‫to half, then you die.

80
00:05:06,940 --> 00:05:09,970
‫So that's all happening a little bit too quickly.

81
00:05:09,970 --> 00:05:14,710
‫So I'd like to challenge you to increase only the player's health, not the A's health.

82
00:05:14,710 --> 00:05:19,180
‫I want to have the feel of the level be that you two shot kind of kill the enemy.

83
00:05:19,240 --> 00:05:25,660
‫But then your player has a lot more health and it takes a lot more shots off the AI to actually get

84
00:05:25,660 --> 00:05:28,030
‫you to come down because you're a big, strong hero.

85
00:05:28,150 --> 00:05:32,650
‫So the idea here is to create a child for the player.

86
00:05:32,650 --> 00:05:37,900
‫So this is going to be a child of the character class, but not just of the character class, probably

87
00:05:37,900 --> 00:05:40,240
‫already of that blueprint class.

88
00:05:40,240 --> 00:05:42,610
‫You're going to have to override a few different variables.

89
00:05:42,610 --> 00:05:48,220
‫Namely, the max health is going to be higher for the player and maybe you want a different mesh to

90
00:05:48,220 --> 00:05:54,220
‫differentiate you from all those enemies around you towards a video and see if you can have a go at

91
00:05:54,220 --> 00:05:55,180
‫this challenge.

92
00:05:56,340 --> 00:05:56,850
‫Okay.

93
00:05:56,850 --> 00:05:57,330
‫Welcome back.

94
00:05:57,330 --> 00:06:02,640
‫So we're going to go up to the content folder and we're going to find ourselves the character.

95
00:06:02,640 --> 00:06:03,780
‫We've got BP shooter character.

96
00:06:03,780 --> 00:06:09,510
‫I'm going to right click on that and I'm going to create a child blueprint class here, which is going

97
00:06:09,510 --> 00:06:15,360
‫to be a BP underscore player shooter character like so.

98
00:06:15,360 --> 00:06:20,190
‫And now opening up this blueprint, it's going to have all of the same properties of its parent blueprint

99
00:06:20,190 --> 00:06:22,020
‫because those were already set in the parent.

100
00:06:22,020 --> 00:06:24,330
‫But now we can choose to override a few things.

101
00:06:24,330 --> 00:06:27,540
‫The first thing I'm going to override is the mesh.

102
00:06:27,540 --> 00:06:28,410
‫So we're starting off.

103
00:06:28,410 --> 00:06:29,460
‫This is a red mesh.

104
00:06:29,460 --> 00:06:31,560
‫I think that's good for the enemies.

105
00:06:31,560 --> 00:06:35,010
‫But what I would like is the green mesh for my hero.

106
00:06:35,010 --> 00:06:37,770
‫So it's going to be super obvious that he's a different guy.

107
00:06:38,190 --> 00:06:45,030
‫Then we're going to go over to the root or to the class defaults and change up the max health.

108
00:06:45,030 --> 00:06:50,460
‫So I want him to have roughly ten times as much health as the enemies in this level.

109
00:06:50,460 --> 00:06:52,530
‫So I'm going to go ahead, compile and save that.

110
00:06:52,530 --> 00:06:56,940
‫And then one more thing we've got to do is go and change our blueprint.

111
00:06:56,940 --> 00:07:04,830
‫So we're going to go and find the BP KML gain mode and we're going to change the default -- class

112
00:07:04,830 --> 00:07:11,310
‫from the BP shooter character to the BP player shooter character because we've already got our shooter

113
00:07:11,310 --> 00:07:14,790
‫I placed in the world and then we're going to go ahead and hit play.

114
00:07:14,790 --> 00:07:17,940
‫And you can see we've got ourselves a different character.

115
00:07:18,060 --> 00:07:19,260
‫He's got a different look.

116
00:07:19,260 --> 00:07:24,930
‫And when he's getting shot at, we're getting the health bar going down much more slowly and I can to

117
00:07:24,930 --> 00:07:26,910
‫short kill off the enemy.

118
00:07:26,910 --> 00:07:31,320
‫But it still can be quite challenging if you place enough enemies in your scene.

119
00:07:31,320 --> 00:07:32,310
‫So that's it for this lecture.

120
00:07:32,310 --> 00:07:39,930
‫We've seen how we can add a health component with binding and with a progress bar component.

121
00:07:39,930 --> 00:07:44,700
‫In the next lecture, we're going to be looking a little bit again at animation in order to get our

122
00:07:44,700 --> 00:07:48,510
‫player able to aim up and down with the mesh.

123
00:07:48,540 --> 00:07:49,260
‫I'll see you there.

