BP Scripting - Character Health

13 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€95.03
List Price:  €133.05
You save:  €38.01
£79.15
List Price:  £110.82
You save:  £31.66
CA$139.67
List Price:  CA$195.55
You save:  CA$55.87
A$153.55
List Price:  A$214.98
You save:  A$61.42
S$134.39
List Price:  S$188.16
You save:  S$53.76
HK$778.22
List Price:  HK$1,089.54
You save:  HK$311.32
CHF 88.36
List Price:  CHF 123.71
You save:  CHF 35.34
NOK kr1,105.21
List Price:  NOK kr1,547.34
You save:  NOK kr442.12
DKK kr708.87
List Price:  DKK kr992.45
You save:  DKK kr283.57
NZ$170.45
List Price:  NZ$238.64
You save:  NZ$68.18
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳11,959.01
List Price:  ৳16,743.10
You save:  ৳4,784.08
₹8,452.40
List Price:  ₹11,833.70
You save:  ₹3,381.29
RM446.45
List Price:  RM625.05
You save:  RM178.60
₦168,042.19
List Price:  ₦235,265.79
You save:  ₦67,223.60
₨27,819.88
List Price:  ₨38,948.94
You save:  ₨11,129.06
฿3,466.55
List Price:  ฿4,853.31
You save:  ฿1,386.76
₺3,454.83
List Price:  ₺4,836.90
You save:  ₺1,382.07
B$580.99
List Price:  B$813.41
You save:  B$232.42
R1,812.36
List Price:  R2,537.39
You save:  R725.02
Лв185.85
List Price:  Лв260.20
You save:  Лв74.35
₩140,106.88
List Price:  ₩196,155.24
You save:  ₩56,048.35
₪373.41
List Price:  ₪522.79
You save:  ₪149.38
₱5,905.80
List Price:  ₱8,268.36
You save:  ₱2,362.56
¥15,438.71
List Price:  ¥21,614.81
You save:  ¥6,176.10
MX$2,034.25
List Price:  MX$2,848.03
You save:  MX$813.78
QR364.93
List Price:  QR510.92
You save:  QR145.98
P1,367.12
List Price:  P1,914.02
You save:  P546.90
KSh12,923.70
List Price:  KSh18,093.70
You save:  KSh5,170
E£4,964.56
List Price:  E£6,950.58
You save:  E£1,986.02
ብር12,476.97
List Price:  ብር17,468.25
You save:  ብር4,991.28
Kz91,223.61
List Price:  Kz127,716.70
You save:  Kz36,493.09
CLP$97,372.26
List Price:  CLP$136,325.06
You save:  CLP$38,952.80
CN¥724.09
List Price:  CN¥1,013.76
You save:  CN¥289.66
RD$6,035.83
List Price:  RD$8,450.41
You save:  RD$2,414.57
DA13,357.64
List Price:  DA18,701.23
You save:  DA5,343.59
FJ$226.99
List Price:  FJ$317.80
You save:  FJ$90.80
Q772.55
List Price:  Q1,081.60
You save:  Q309.05
GY$20,937.04
List Price:  GY$29,312.70
You save:  GY$8,375.65
ISK kr13,828.61
List Price:  ISK kr19,360.61
You save:  ISK kr5,532
DH999.72
List Price:  DH1,399.66
You save:  DH399.93
L1,820.82
List Price:  L2,549.22
You save:  L728.40
ден5,848.08
List Price:  ден8,187.54
You save:  ден2,339.46
MOP$802.33
List Price:  MOP$1,123.29
You save:  MOP$320.96
N$1,815.10
List Price:  N$2,541.22
You save:  N$726.11
C$3,682.57
List Price:  C$5,155.75
You save:  C$1,473.17
रु13,507.81
List Price:  रु18,911.48
You save:  रु5,403.66
S/379.77
List Price:  S/531.69
You save:  S/151.92
K402.86
List Price:  K564.02
You save:  K161.16
SAR375.38
List Price:  SAR525.55
You save:  SAR150.16
ZK2,769.51
List Price:  ZK3,877.43
You save:  ZK1,107.91
L472.94
List Price:  L662.13
You save:  L189.19
Kč2,407.85
List Price:  Kč3,371.09
You save:  Kč963.24
Ft39,078.98
List Price:  Ft54,712.13
You save:  Ft15,633.15
SEK kr1,102.90
List Price:  SEK kr1,544.10
You save:  SEK kr441.20
ARS$100,263.16
List Price:  ARS$140,372.43
You save:  ARS$40,109.27
Bs693
List Price:  Bs970.23
You save:  Bs277.22
COP$441,313.30
List Price:  COP$617,856.28
You save:  COP$176,542.97
₡50,820.06
List Price:  ₡71,150.12
You save:  ₡20,330.05
L2,528.86
List Price:  L3,540.51
You save:  L1,011.64
₲783,733.33
List Price:  ₲1,097,258.01
You save:  ₲313,524.68
$U4,278.05
List Price:  $U5,989.44
You save:  $U1,711.39
zł413.19
List Price:  zł578.49
You save:  zł165.29
Already have an account? Log In

Transcript

Welcome back everyone in this video we are going to be taking a little time out from scripting our blueprint actors here. I'm gonna jump on over to our First Person BP blueprints first person Character Blueprint. Find your way on over here. The reason we're going to be working in here is because the goal of this video is to add some variables and a function necessary for creating the backbone for the health system. In our simple game, we got the steam jet and the spinning fan coming up in just a little bit that we want to have damage our player. But before we can damage the player, we kind of need to have some sort of a concept of health on our character, which is why we are starting here.

Alright, so find your way on down to the My blueprints panel and we're going to add some variables so click this plus variables button. First one We are going to add is going to be called health max. And I'm going to change this on over to a float variable. Then I am going to duplicate that one selecting it's selected Ctrl W, and this one is going to be called health currents. I also want it to be a float variable. And actually something I should have done before I duplicated that I wanted to show you that you can actually create categories for your variables here.

So starting back at my health max over in the Details panel. I'm going to create a category to put these in by simply clicking over here. And let's call this attributes. And you can see how we now have a category called attributes down in the my blueprints area. And then I'm going to select my health currents and I'm going to put that into the attribute Why don't have to actually put in the value attributes I can click from this drop down box and choose attributes haha. All right, we need one more variable here.

So I will right click in duplicate and this one is going to be called health percentage. All right, well so with that let's Compile and Save. So we can set some default values for all these starting with health max. I'm going to set that to be 100 Health current, I will set that to be 100. We'll start out at full health and then health percentage I'm going to set to be 1.0 because 1.0 equals 100%. Okay, next we are going to create a function to do some health updating calculations like what to do do eventually if we get hurt or healed, all right, so come on over to the functions section of your mind blueprints tab and we are going to create a brand new function.

And when we do, that's going to create a whole new graph over here and we need to give our function a name. I'm gonna call this up date, health like so. And I do want to have an input here. So with this update health node selected right here, gonna click this plus button, and we're going to add a new parameter and this is going to be called health modifier. Make this be not a Boolean, but a float. And what we're going to do straight away is we're going to bring in our health currents variable added to our graph, we're going to get it and we are going to add these together.

So it doesn't matter which one of these you drag out of just going to drag out a health modifier and add a plus symbol, and we want to do float plus float. Okay, and then what we want to do is we need to set our health current little shortcut here that you can take instead of dragging and dropping and then deciding whether you want to set it or get it. If you hold down the Alt key while you left click and drag, you will automatically bring in a setter. Okay, I'm just going to jump out of this function really quickly because this May all look a little confusing. We are creating a function here and this we add In an input called health modifier now, I thought you said inputs were on the left hand side of a node, Mr. quandra. Well, they are actually.

So if I jump into our Event Graph, and I was to bring in this function know that we are creating, you can see that our function puts this health modifier on the left hand side of this function node that we are creating. So it's a little unintuitive. To me anyways, it a little confusing that back in our update health function that we are creating, we added in inputs that is currently on the right hand side. So just know that when you're creating these functions, it's almost like it goes like this and creates a function out of that with that health modifier input right there being on the left hand side. Anyways, we're gonna get rid of this for the time being in our Event Graph. Let's jump back to our update health function.

You double click on that if you're lost Okay, next thing I want to do is I want to drag out of our current or health current, and I want to look for a node called clamp float. I want to make sure that this value never gets below zero or above 100. So this will ensure that it never does. Okay, I'm out of this we're going to get some value and I'm going to drag out of this and look for a divide symbol. So you can do float divided by float. Now what are we going to divide by here we're going to divide by the health Max and you can drag and drop this right onto the pin to automatically link it up.

That's pretty cool. Okay, next we are going to clamp that float one more time. Drag out here, do a clamp float. And here we want to make sure that the value is going to be between zero and one. And this we are going to set into our health percentage. So I'm going to hold down alt, left click and drag to bring in the center for that.

And that's why we want to clamp this value between zero and one, right. So just kind of backing things up here. Let's say we our current health is 100. And our health modifier is actually negative 50. Maybe we get hit by something, suddenly our health current is going to be 50. So we'll come into here and it will say yes, health 50 is valid between zero and 100.

So it outputs 50. And then we'd want to divide that by our health Max 50 divided by our health max which is 100 would be 0.5, which is 50%. So So 0.5 would be input into here, and that is a valid number between zero and one. So 0.5 would be set as our health percentage. And this number right here, we are eventually going to output to some HUD on the screen to drive a health meter of sorts. That will be pretty cool.

Something else I want to put in between this wire right here to make sure that all this stuff happens is I want to drag out a wire and type in print string because I want to see this value outputted to the screen so that everything is looking good. So let's continue this by bringing this into here. And let's drag out of here. This is essentially our updated health value and plug it into our in string right here. What that's going to do is it's going to convert this float variable into a string string, that's what this guy is right here. Because the print string only takes in a string variable right there, that just converts it.

Okay, so then what do we want to do here we're almost getting done with this we're going to drag out of our health percentage right here. And we are going to do a search for less than, sorry less than or equal to float less than or equal to float. Now in courses pass, I always have a lot of students kind of mess up, they're less than or greater than sign. So make sure the alligator mouth there for the lesson sign is pointed off to the right, okay. We want to check if it is less than or equal to zero, and if it is, drag off the here we'll do a branch and hook that up. If that is true, our health is less than or equal to zero.

And again, this should clap it so it never gets below zero. But if it's zero, we are going to drag out of here and a D stroy. Actor. That means we are going to destroy ourselves our First Person character because target is self first person, character. All right, if in fact, is not true, we're going to drag a wire off and we are going to play a sound. We're going to do play sound to D which is basically like a menu sound.

It's not going to be located anywhere in the world and have you know depth to it. We're then going to slot in the sound here and I like VR underscore teleport cue. So this is just gonna be like a damaged sound like boom, you got hit, right? Okay, so let me just back this up here. So you can see Everything that we have created here in our function. Hey guys just wanted to interrupt the original recording of this video for one quick update, I made a mistake in the original recording and I am going back and fixing this so I am recording this at a later date to fix my wrong.

One thing I did wrong in the original recording is is very first clamp float node this guy right here, we need to move this before our setting of our health current variable. So note this change and please make this updated change or you may find some problems with your health system as you get rolling on. So make this change right here. We're going to take our health current, we're going to add it to a health modifier and we're going to clamp that between zero and 100. And I'm just gonna break some wires here. The result of this is going to be plugged into our setting of the health current.

So we want to make sure that our health current is originally clamped between zero and 100 before it's even set. Okay, so then the output of this we want to go into this dividing of the health max. This whole print string, you don't really need it, but if you want to keep seeing it, you can plug your health current into this as well. And that will keep showing you what your health your current health value is when you are damaged. But that is the one change that we wanted to make here. So note this rewiring and I'll try to fit this all on screen here.

So this clamp float this first one, we have to clamp this before we set it into our health current. And then out of this health current. This is where we're going to divide by our health max to then determine what our health percentage value should be. So let me just see if I can squeeze wheezes on screen really quickly here. So in case you need to pause the video, you can make sure that this is all corrected. Okay, so with that I am going to Compile and Save.

And then I'm going to hand it back off to the original video to finish this video off. And then I'm just going to finish this off by compiling in saving. Now note I'm in the next videos we're going to worry about hurting our character and also we're not worrying about responding after destroying the actor at this time. This is all just prep work for our next lesson we'll worry about responding later. All right, that's gonna do it all for this one guys. We will see you in the next one.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.