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
€93.07
List Price:  €130.30
You save:  €37.23
£79.62
List Price:  £111.47
You save:  £31.85
CA$136.60
List Price:  CA$191.24
You save:  CA$54.64
A$151.87
List Price:  A$212.63
You save:  A$60.75
S$135.20
List Price:  S$189.29
You save:  S$54.08
HK$781.33
List Price:  HK$1,093.90
You save:  HK$312.56
CHF 90.72
List Price:  CHF 127.01
You save:  CHF 36.29
NOK kr1,092.46
List Price:  NOK kr1,529.50
You save:  NOK kr437.03
DKK kr694.20
List Price:  DKK kr971.90
You save:  DKK kr277.70
NZ$167.15
List Price:  NZ$234.02
You save:  NZ$66.86
د.إ367.25
List Price:  د.إ514.16
You save:  د.إ146.91
৳10,946.16
List Price:  ৳15,325.07
You save:  ৳4,378.90
₹8,342.71
List Price:  ₹11,680.13
You save:  ₹3,337.42
RM473.95
List Price:  RM663.55
You save:  RM189.60
₦123,487.65
List Price:  ₦172,887.65
You save:  ₦49,400
₨27,847.21
List Price:  ₨38,987.21
You save:  ₨11,140
฿3,679.53
List Price:  ฿5,151.49
You save:  ฿1,471.96
₺3,232.18
List Price:  ₺4,525.18
You save:  ₺1,293
B$511.10
List Price:  B$715.57
You save:  B$204.46
R1,851.52
List Price:  R2,592.21
You save:  R740.68
Лв181.98
List Price:  Лв254.78
You save:  Лв72.80
₩135,881.87
List Price:  ₩190,240.05
You save:  ₩54,358.18
₪371.60
List Price:  ₪520.25
You save:  ₪148.65
₱5,713.97
List Price:  ₱7,999.79
You save:  ₱2,285.82
¥15,308.41
List Price:  ¥21,432.39
You save:  ¥6,123.98
MX$1,693.57
List Price:  MX$2,371.07
You save:  MX$677.49
QR364.01
List Price:  QR509.63
You save:  QR145.62
P1,365.33
List Price:  P1,911.52
You save:  P546.18
KSh13,468.65
List Price:  KSh18,856.65
You save:  KSh5,388
E£4,794.02
List Price:  E£6,711.82
You save:  E£1,917.80
ብር5,699.43
List Price:  ብር7,979.43
You save:  ብር2,280
Kz83,741.62
List Price:  Kz117,241.62
You save:  Kz33,500
CLP$94,755.52
List Price:  CLP$132,661.52
You save:  CLP$37,906
CN¥723.62
List Price:  CN¥1,013.10
You save:  CN¥289.48
RD$5,785.38
List Price:  RD$8,099.76
You save:  RD$2,314.38
DA13,457.99
List Price:  DA18,841.73
You save:  DA5,383.73
FJ$225.30
List Price:  FJ$315.43
You save:  FJ$90.13
Q775.21
List Price:  Q1,085.33
You save:  Q310.11
GY$20,876.73
List Price:  GY$29,228.26
You save:  GY$8,351.52
ISK kr13,989.60
List Price:  ISK kr19,586
You save:  ISK kr5,596.40
DH1,008.69
List Price:  DH1,412.20
You save:  DH403.51
L1,771.31
List Price:  L2,479.90
You save:  L708.59
ден5,730.13
List Price:  ден8,022.42
You save:  ден2,292.28
MOP$803.11
List Price:  MOP$1,124.38
You save:  MOP$321.27
N$1,860.85
List Price:  N$2,605.27
You save:  N$744.41
C$3,673.63
List Price:  C$5,143.23
You save:  C$1,469.60
रु13,311.40
List Price:  रु18,636.50
You save:  रु5,325.09
S/375.46
List Price:  S/525.66
You save:  S/150.20
K383.63
List Price:  K537.10
You save:  K153.47
SAR375.03
List Price:  SAR525.05
You save:  SAR150.02
ZK2,685.42
List Price:  ZK3,759.69
You save:  ZK1,074.27
L463.14
List Price:  L648.42
You save:  L185.27
Kč2,328.17
List Price:  Kč3,259.54
You save:  Kč931.36
Ft36,248.95
List Price:  Ft50,749.98
You save:  Ft14,501.03
SEK kr1,083.98
List Price:  SEK kr1,517.62
You save:  SEK kr433.63
ARS$87,816.53
List Price:  ARS$122,946.66
You save:  ARS$35,130.12
Bs689.12
List Price:  Bs964.79
You save:  Bs275.67
COP$389,940.87
List Price:  COP$545,932.82
You save:  COP$155,991.94
₡50,893.45
List Price:  ₡71,252.86
You save:  ₡20,359.41
L2,475.75
List Price:  L3,466.15
You save:  L990.40
₲747,391.81
List Price:  ₲1,046,378.43
You save:  ₲298,986.62
$U3,833.15
List Price:  $U5,366.56
You save:  $U1,533.41
zł402.67
List Price:  zł563.75
You save:  zł161.08
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.