Unreal Engine 5 RPG Tutorial Series - #5: Player Stats - Health, Stamina and XP
Summary
TLDR在这个Unreal Engine 5的教程视频中,我们继续深入角色扮演游戏(RPG)系列的制作。今天,我们将从玩家状态开始,包括生命值、耐力、经验值和等级等。我们会创建一个新的蓝图类,作为组件添加到第三人称角色中,以保持组织的整洁。我们将设置当前生命值、最大生命值、当前耐力、最大耐力、经验值、最大经验值和等级等变量,并将它们分类以便于管理。接下来,我们会创建一些功能,如减少生命值和增加生命值,以及检查生命值是否降至零以下时玩家的死亡状态。此外,我们还会设置默认值,如初始的生命值和耐力为100,经验值为0,以及所需的经验值来提升等级。最后,我们将开始在用户界面(UI)中实现这些状态,创建一个新的小部件蓝图,并添加一个画布面板来放置进度条,以可视化玩家的生命值和耐力。
Takeaways
- 🚀 开始制作RPG系列教程,将创建玩家状态系统,包括健康、耐力、经验值和等级等。
- 📚 通过创建一个新的蓝图类(actor component),来组织玩家状态,使其与第三人称角色分离,以保持代码的整洁。
- 🔢 设置了玩家状态的基本变量,包括当前健康值、最大健康值、当前耐力、最大耐力、经验值、最大经验值和等级。
- 📉 创建了减少健康值的函数,包括根据受到的伤害来更新当前健康值,并在健康值为零或以下时触发玩家死亡。
- 📈 制作了增加健康值的函数,用于在玩家升级时增加最大健康值,并允许当前健康值逐渐恢复。
- 💪 设计了管理耐力的函数,包括减少耐力和增加最大耐力,以及在耐力耗尽时限制玩家的某些动作。
- 🎮 通过在第三人称角色蓝图中添加组件和调试键,可以在运行时测试和调整玩家状态。
- 🖥️ 为UI界面创建了一个主HUD(头部显示器)小部件蓝图,并在画布面板上布局了健康和耐力的进度条。
- 🔴 调整了健康进度条的颜色和位置,以匹配参考游戏《刺客信条:起源》的UI设计。
- 🔵 同样为耐力进度条设置了颜色和尺寸,并确保其在UI中的布局与健康进度条协调。
- ✅ 通过将玩家状态与UI元素绑定,实现了在游戏运行时动态更新健康和耐力进度条的百分比。
- 📈 在玩家状态蓝图中实现了文本显示,用于实时显示当前的健康和耐力值。
Q & A
在Unreal Engine 5的RPG系列教程中,玩家状态系统包括哪些基本属性?
-玩家状态系统包括生命值(Health)、耐力(Stamina)、经验值(XP)和等级(Level)等基本属性。
为了在Unreal Engine 5中创建玩家状态,需要创建哪种类型的蓝图?
-需要创建一个Actor Component类型的蓝图,这样可以通过组件的形式将其添加到第三人称角色中。
在设置玩家状态的变量时,生命值和耐力的变量类型是什么?
-生命值和耐力的变量类型是浮点数(float),这样可以支持小数点,使得数值更精确。
如何在游戏中实现玩家生命值的减少?
-通过创建一个名为'Decrease Health'的函数,并将其与一个输入值(代表受到的伤害)相连接,通过这个函数可以减少玩家的当前生命值。
当玩家生命值降至零或以下时,游戏中会发生什么?
-当玩家生命值降至零或以下时,玩家角色将会死亡,这通常会触发角色的死亡动画(Ragdoll)和一些特定的效果。
如何在游戏中实现玩家生命值的增加?
-通过创建一个名为'Increase Health'的函数,该函数会接收一个输入值,并将其添加到最大生命值(Max Health)中,从而实现生命值的增加。
在创建UI界面时,如何将玩家的状态信息展示给玩家?
-通过创建一个Widget Blueprint,并在其中使用Canvas Panel、ProgressBar和Text等UI元素来展示玩家的当前生命值、耐力和其他状态信息。
在UI界面中,如何根据玩家的当前生命值更新生命条的百分比?
-通过将当前生命值除以最大生命值,得到一个从0到1的数值,然后将这个数值作为ProgressBar的百分比参数来更新生命条的显示。
在教程中,如何确保UI界面在游戏开始时显示?
-在第三人称角色的蓝图中,在Begin Play事件中创建并添加HUD Widget到视口(Viewport),从而确保UI界面在游戏开始时显示。
在教程中,如何实现玩家状态的实时更新?
-通过在玩家状态变更的函数中调用UI界面的更新函数,如更新生命条的百分比和文本显示,确保玩家状态的实时更新。
在Unreal Engine 5中,如何为玩家状态系统添加调试功能?
-可以通过在第三人称角色蓝图中添加Debug Key功能,通过按键触发特定的玩家状态变更,如增加或减少生命值,以便于调试和测试。
Outlines
😀 创建角色状态蓝图
本段介绍了如何在Unreal Engine 5中创建一个新的蓝图类,用于管理角色的状态,如生命值、耐力、经验值和等级。通过创建一个Actor Component蓝图,将该组件添加到第三人称角色中,以保持组织结构。同时,设置了当前生命值、最大生命值、当前耐力、最大耐力、经验值、最大经验值和等级等变量,并为它们创建了不同的类别以便于管理。
🔧 定义健康和耐力的增减功能
本段详细说明了如何创建减少健康值的函数,包括设置函数输入参数以接收伤害值,并根据伤害值更新当前生命值。同时,还介绍了如何检查生命值是否降至零或以下,以触发角色死亡的逻辑。此外,还创建了增加最大生命值的函数,并通过输入参数来实现生命值的增加。
📊 实现健康和耐力的UI显示
本段讲解了如何在用户界面上实现健康和耐力的进度条显示。首先创建了一个画布面板,并添加了进度条以表示健康和耐力的状态。接着,通过设置锚点和位置,将进度条放置在屏幕的适当位置,并调整了进度条的大小和颜色。最后,通过绑定进度条的百分比来动态显示当前的生命值和耐力值。
🖥️ 将UI与游戏逻辑绑定
本段描述了如何将之前创建的UI元素与游戏逻辑相绑定。首先,在第三人称角色蓝图中添加了玩家状态组件,并设置了调试键以便于测试。然后,通过编写蓝图逻辑,实现了在受到伤害时更新健康条和文本显示的功能。此外,还介绍了如何将最大生命值和耐力值的变化反映在UI上。
🎮 测试和调整UI显示
本段主要讲述了如何通过测试来验证UI显示的准确性。通过在第三人称角色蓝图中添加组件,并使用调试键来模拟增加和减少健康值的操作,检查UI上的健康条和文本是否能够正确更新。同时,还提到了如何处理UI上显示的负数问题,并预告了下一期视频将解决这些问题,并继续介绍经验值和等级系统。
🔄 完善玩家状态的UI和逻辑
在本段中,完成了玩家状态UI的剩余部分,并确保了所有功能正常工作。首先,对健康和耐力的UI进行了最终调整,包括设置百分比文本和绑定当前值。然后,通过在第三人称控制器中增加体力,测试了UI的更新情况。最后,预告了下一期视频将继续完善玩家状态,并开始介绍战斗系统。
Mindmap
Keywords
💡Unreal Engine 5
💡Blueprints
💡Player Stats
💡UI
💡Health Bar
💡Stamina
💡XP and Leveling
💡RPG Series
💡Actor Component
💡Progress Bar
💡Widget Blueprint
Highlights
教程介绍了如何在Unreal Engine 5中创建RPG系列游戏中的玩家状态系统,包括健康、耐力、经验值和等级。
通过创建一个新的蓝图类,作为Actor Component,来组织和添加到第三人称角色中,以保持事物的组织性。
设置了玩家状态的变量,如当前健康、最大健康、当前耐力、最大耐力、经验值、最大经验和等级。
创建了用于减少健康值的函数,并根据受到的伤害输入值来更新当前健康。
实现了一个检查,如果玩家健康值降至零或以下,则玩家将死亡。
创建了增加健康值的函数,允许在角色升级时增加最大健康值。
为健康和耐力条设置了默认值,并定义了经验值和最大经验值,用于升级所需的经验值。
创建了用于减少和增加耐力的函数,并设置了相应的边界条件。
实现了一个函数,用于在玩家恢复时逐渐增加健康值,而不是立即设置为最大健康值。
创建了一个新的小部件蓝图,用于在用户界面上显示玩家的状态,如健康和耐力条。
在用户界面中使用了进度条来可视化健康和耐力的当前状态。
通过绑定和事件,将玩家状态的变化实时更新到用户界面上。
在第三人称角色蓝图中添加了玩家状态组件,并在游戏开始时初始化了HUD小部件。
通过按键调试功能,可以在游戏运行时手动测试健康和耐力的变化。
在HUD中添加了文本显示,以实时显示当前的健康和耐力数值。
教程最后提到,接下来的视频中将继续完善玩家状态系统,并开始探讨经验值和等级系统。
整个教程强调了在Unreal Engine 5中创建和实现玩家状态系统的逻辑和UI展示的重要性。
Transcripts
what's up guys welcome to new Unreal
Engine 5 tutorial and today we are
continuing with the RPG Series today we
will start with the player stats
basically Health stamina XP level and so
on it will start to structure the you
know the system and basically start
displaying some things in the UI it's
going to be a very easy beautiful so
let's get started
[Music]
alright so the first thing that we have
to do is go into Blueprints and we're
gonna create a new blueprint class over
here and it's going to be an actor
component so basically it's gonna be on
a separate blueprint that will basically
add it as a component into our third
person character and basically it would
just keep things more organized I
wouldn't have a huge you know event
graph and a lot of functions in our main
players so it will be more organizers
okay so let's click on actor component
and this will be bpc so a blueprint
component then this can be underscore
player stats and now we can go ahead and
open this guy up all right so we have to
basically start setting up some
variables over here so the first one is
going to be basically current health so
it's going to be current uh actually
it's gonna be on Capital C Uh current
health and then this is gonna be
basically a float great so now we're
going to create a new variable and this
will be the max
help over here great so now we have the
health over here the current health and
the max now we need to set up the
current stamina
current stamina there we go and now the
max stamina three and again they're
gonna be flows so they're gonna be
basically numbers with decimals so they
can be more accurate okay and now we're
gonna need basically XP
and then we're gonna need
uh Max XP
and then we're gonna need
level
great I know level is going to be an
integer and then we can keep XP and Max
XP as if load great so we have all the
variables set up let's go ahead and
create some categories so we can have
things uh more organized so let's go
ahead and select both current health and
Max Health actually we can only select
one at once so you select Corner Hill
I'm gonna go into category
now we can write here health so it's
going to be the health categories go
into max health and now we can go into
drop down and select the one that we
have just created Health here and now
it's going to current stamina and just
type stamina
and now we can go into max stamina and
plus stamina and now XP type XP
and then in Max XP just type XP and now
I'm gonna go ahead and select level and
also put it as XP and so they're pretty
much from the same category they will
link together a lot great so now it's a
bit more organized you can see like
Health stamina XP all the player stats
um join together and separate at the
same time great so let's start grading
some functions and the first one is
going to be basically
um decrease health so when we take
damage
from our player we'll go ahead and
access this component and then code the
function that will decrease our health
so let's go into functions create new
health shouldn't be decrease
health
great so what we want to do let's go
ahead and get the current health and set
it okay so we'll be basically overriding
this over here so we want to go ahead
and say hey we want to get our current
health right now and decrease it by an
incoming value so this will be the
damage taken so for example if we have
right now like a hundred of health and
we decreased you know 10 we'll have 90.
so now we'll be setting that 90 into our
new current health okay now the thing is
that this damage needs to depend on how
much we're receiving
so what we can do is directly plug it as
an input in our function so later on
when we call it when we are you know
affected by damage when we call this
function we can directly pass it as an
input value so this is going to be the
uh basically uh just damage all right
and it's going to be again a float so
let me go ahead and put this a bit to
the left over here to the right so it's
a bit more organized okay yeah so
basically the hook current health
decreases by B damage and then set it so
now this will be the new uh current
health field here so now we have to bank
a branch over here and what we have to
do is basically
um check if our health is zero or below
zero if so our player has to die so what
we have to do over here is basically get
the current health and then say well it
is
um less equal okay so if it's less than
equal than zero
so we drew over here well our player
will go ahead and die if not it will be
false so what we're going to do is
basically click on the decrease health
over here and create an output and this
will be a Boolean which is going to be
um basically is
player
that
okay and now in true we will go ahead
and set this to be true but on false it
will set to be false so now later on in
our third person character when we call
this function and access the component
we'll get a return to this Boolean over
here and then depending if it's dead or
not in there we'll activate Ragdoll and
the effects that we need and so on
great so that's pretty much the decrease
Health done we are now going to go to
the increased health so imagine that we
level up and we want to increase our Max
health so our character will have more
Health instead of 100 let's say more
let's go ahead and create a function for
it now first of all let's set the
current health of the variable by
default to be 100 okay because we wanted
to set it uh to be 100 and the same with
Max Health we want to start the game
basically with a hundred of health and
again with the stamina you're going to
do the same let's do a 100 MX Tamina 100
so it's going to be basically a default
value so it will start off course you
can customize this as you want but I
recommend you don't have to just bring
100 and then in XP well you'll have zero
XP Max XP is going to be basically the
amount of XP needed to level up
so let's say that now we have zero so if
both here in Max XP for example again
100 will basically need 100xp to go into
the next level and now by default it
will be level one so there we go we have
all the default values over here so now
let's go ahead and continue on creating
the uh increased health so increase
health function
again if I know how to type correctly
great so this is going to be very
similar but we have to do the opposite
basically so let's get current health
and set it over here
okay and now we also need to get a Max
tell H3 yes it's gonna be myself
so when we increase the health what we
want to do is not directly increase the
current help that we have right now it's
going to be basically the max Health
that we can and then later on slowly
regenerate okay so if it makes sense so
what we can do is just get the current
Max Health then add the value that we
want which again will be an input and
then this will be the new Max Health
which is basically what we did with the
decreased Health but as you can see
inverted and this time with the max
Health great and now what we have to do
is actually not put really any condition
because we don't have any boundaries
really for Max Health maybe if we want
to increase it by a thousand we can okay
it's just the max Health as can be any
High number that we want okay so really
we don't have to do anything now in here
let's selected and we change the input
to be you know I don't know uh
uh incremention
I don't know that makes sense but Health
incremention you know you can put
whatever value makes sense for you okay
and there we go now if you want you can
go and set the current health to be
directly the new Max health so it will
out to generate two so it will not you
will not need to wait until it generates
but I will go ahead and delete this as
we want to go ahead and wait slowly
until slowly until it basically
regenerates okay
great so now let's go ahead and move on
to the stamina so here we have the
functions over here so we now want to go
ahead and create a stamina again the
category we'll go ahead and put it on
the health
for both so everything is nice and
organized right let's go ahead and
create a new function and again decrease
stamina
go ahead and get the current stamina and
set it so basically we want to get the
current stamina that we have right now
and basically decrease it by the amount
incoming which I guess will be basically
and here it was damage well in here we
can say
um
stamina depleted I think it's that's how
you you say it and then we can plug it
into current stamina okay which is again
what we did with decreased Health but
instead of the with the health basically
with a stand and now in here we need
boundaries because we are decreasing
health so
stamina sorry so we want to do is get
the current health
and be like okay so if this is less or
equal than zero
it will mean that we cannot longer run
so we just want to create an output
and this will be
um stamina
uh
not stamina left
okay and now we want to plug the intrude
so hey we are not any we don't have any
stamina left so later on in the player
controller we'll say that you cannot run
anymore or attack anymore until it
generates again and in defaults we'll do
the opposite untick it great and now we
want to go into uh increased stamina so
create a new one
right and now I want to do is get the
max stamina and set it okay and it's
going to be the same pretty much that we
did with increased Health very simple
just get the max stamina when I get it
then basically add a value and this will
be the incoming value here so I guess we
could say
um incoming
or added added stamina
it makes more sense and now that will be
the new Max Diamond over there great and
we don't need anymore again you can go
ahead and auto set the current stamina
to be automatically the max one now this
will depend on what you want for example
if you call increased stamina
um so this will be the max I mean okay
from when you level up well
do basically maybe want to Auto Select
the the current stamina you have and you
know put it into the max but maybe not
so it will basically go ahead and depend
now what we have to do now is basically
do the same but with the current stamina
and the current health so actually sorry
about that but this is gonna be
basically increase
um let's change the name
if I can come on break come on here so
select it here and go here this will be
basically Max health and uh Max stamina
oh that's the description
I don't know oh we need to select the
notes sorry so we're going to increase
stamina you'll hear sorry about that
please Max them and again we're gonna
apply it into the category stamina
so yeah sorry about the confusion there
I I've even confused myself
but we want to that was the Maxima so I
was referring like for example when you
level up I want to have more stamina
later on but now we need to actually do
the uh like incrementing and so for
example when you recover your health
until you get into the next of the
health value and so on if it makes sense
so we want to create a new function
which will be basically increase and
just overall the health and this will be
in the health value over here
so we want to basically get the current
health and basically set it and what we
want to do is basically get the current
health again not Health sorry
and then we want to decrease the
incoming value over here so uh sorry
increase increase I'm going crazy here
increase the incoming value so uh this
will be basically I added to values
let's plug it into the first one and
then delete that one will be the added
health
there we go and now this will be the new
health now what we have to do is make
sure that it is not going outside
outside our bonds of the max health so
we have to do basically a branch over
here it's basically say well is current
health
um bigger or equal
uh well sorry it will be only bigger
so is our current stamina bigger than
our Max health so as a coordinate
stamina but current health so is it
bigger well if it's bigger what we have
to do is set the current health
to directly be the max health
because we don't want to get into the
bounce so we automatically set it to be
the maximum and if not it will be okay
inside the bounce okay so now we can
compound type and now let's do the same
for the stamina so create a new function
this will be just increase stamina
and now we want to do is get the current
stamina and set it
and I want to get our current stamina
get it and then add the new values to
plug it in here added stamina
there you go and now we can plug that
into the new Setter over here so this
will be our new stamina and again we
have to do the check over here so make a
branch basically we need to get our
current stamina and say hey these are
current stamina bigger than our Max
stamina
so we have to do is automatically set
the current stamina
to be the max them because we want to
keep keep it in the belt if not it's
okay
great so we have all the health and
stamina done the only thing left is to
click here and put the stamina category
great so later on we'll continue with
the XP but now let's go ahead and start
actually implementing this in our UI
so let's go here and let's go into
content UI and right click and go into
user interface and create a new widget
blueprint so this will be a normal user
widget and it'll be wgwb underscore and
this will be basically our main HUD
so let's go ahead and open this up
so the palette will go ahead and search
a canvas panel and add it into the
hierarchy so now we can start placing
our UI over here so we want to do is
basically get a progress bar let's go
ahead and drag it just in the scene
great well in the C9 in the panel you
understand me anyway let's go into
anchors and the thing is that Assassin's
Creed Origins which is the game that we
are basing up this RPG game it's gonna
be uh having the health on the bottom
part Center over here so let's go ahead
and place the anchor right over there
and now what we can do is get the
position X to be zero
and Y to be zero so now it will be here
great so this is basically just the
offset really and now the size we want
to change this don't worry we'll Place
good the offset but the size X is
basically the size horizontally and size
y vertically so we want maybe to have it
a bit thinner so in the Y we'll go ahead
and half this into 20. now this you know
customizing it as you want but then in
next uh size X we'll go ahead and put it
like for example 500 so we want kind of
a Long Bar as it is on the Assassin's
Creed reference now in alignment we're
gonna add 8.5 in next and then a
8.5 in y so be perfectly in the center
because not it was basically in the
corner and now we want to do is have a
upset on the position y of let's say 100
maybe no that's yeah exactly but it's
going to be negative
so now as you can see basically we're
having our health bar exactly place
where we need values on the widget over
here now you manually can drag them but
I don't recommend to drag it you know I
recommend to place it like that great so
now what we can do is add a percent just
to visualize how it would look so for
example you can add 0.7 so the values
will basically go from this progress bar
from 0 to 1 okay so because the values
goes from 0 to 1 later on because our
values goes from zero to our Max Health
what we'll do is basically divide the
the number by the max health and we will
obtain a range from zero to one great so
for example we just plug this points on
here just to visualize a bit the UI and
now we can change the field color and
opacity to a reddish one as you can see
so just press ok now later on in the
series we will customize a UI with
custom images and brushes and stuff in
here in this Tau with the if your image
background images but in here we only
gonna basically make the main structure
so we are not gonna get into that right
now but of course we will do in the
future
anyway let's go ahead and compounds it
now let's go ahead and do the same but
with the stamina so first of all I think
I'm going to do is get the progress bar
and change the name to be basically uh
sorry stamina now uh health bar
okay and now we will keep this as is
bevel because you will see now there are
two options of basically assigning this
health at runtime first of all we can
directly make a binding for a percent so
basically
um pretty much on every frame
it will be getting the the value from
where we say and applying it over here
right on the graph of the widget
but another thing that we can do is go
into the player stats and on here when
we directly for example increase the
health we can call The Witcher and then
set the new uh
basically values okay which is the thing
that we're going to do okay because it's
going to be more practical we are only
gonna call it when we need it and so on
so it's going to be a bit more let's say
clean so
um let's first of all go ahead and do
the stamina bar too so duplicate this
this is going to be the change the name
into stamina bar and then we are right
gonna go ahead and change the fill color
to a
kind of yellowish one and now we can
again uh change a bit the anchors over
here so basically for this position X to
be zero and then this to be maybe 70
minus 70 sorry a negative number so now
it's right on the bottom what we want to
do is make a bit thinner so it's going
to be a bit less
um bigger than the health bar so we can
do is go into this size
um Y and change this to be for example
15 or even 10 yeah even 10 I like that
and now you can have here the stamina
and the health now later on we'll
probably customize this like I mentioned
before this is just to get a bit of the
sense of the of how it would look and
stuff you know great so make sure that
seminar bar is set as its variable two
okay great so now let's go ahead and
make sure that this widget goes goes
ahead and appears on the screen
so we have to do is go into the third
person guide to blueprint and basically
open up
and we're going to do is go into the
begin play so when the game starts right
after it does all the input uh context
and stuff we want to go ahead and save
this note which is great widget
and now we want to choose the widget
that we have just created which is the
HUD and then the online player we can
just say that's gonna be the get player
controller and now the return value will
do is create a variable so later on from
our
um component we can access it so we can
just right click promote variable and
this will be the HUD widget we'll go
ahead and name it like that and now
we'll have to do is get this and then
add it into the viewport so it will
basically add it just into the player
screen let's go ahead and comment this
and say well I create widget
and there we go and now let's go ahead
and get the comment color
and copy and paste over here now one of
you commented me that I did not realize
that there's actually like presets that
you can push and so in probably the next
episode we'll go ahead and create a
piece of preset so we have to copy and
paste the color every time you know but
anyway so now if I press play you will
see that indeed we have the UI over here
and it is perfectly aligned like we like
we mentioned before great so now we need
to basically apply the values over here
and so on and so on so what we have to
do is go into the player stats and
basically let's begin with the uh
decrease health so let's go from up to
down
so what we can do is write over here
before we
basically finish our value is go and
basically get the owner
okay so basically we'll be getting the
owner and what we want to do is
basically cast to our third person
character
but what we can do instead of basically
doing every time we can just go into the
event graph and do this at the begin
play and then save our owner as a
variable so we don't have to get the
owner and cash in in every uh basic
function we can just do it once so we
want to do is go here and get the owner
and then we want to cast to the third
person character
and we plug this in and down here in the
output we can just promote this to a
variable and this will be our player
character
lbb
great so now
like that great we can just go into
decrease health
and right on here we can just get our
character
sorry get it and then basically get the
HUD
all right and now we can do is basically
get our
um health bar
a lot of Getters here and then basically
um set the percent okay so in progress
set percent
and now we can plug this in
and basically this will be the new value
over here
great so now we'll do the same with the
max Health but we're going to do is just
copy this because it's going to be more
handy so I'll copy that go into quiz
help bar and right at the end I'm gonna
paste this
and then put this over here so the same
with increase uh the health now the
things that we have to do one more thing
we cannot directly place the percent so
we'll do one that basically that in a
second but it's going to increase health
and on here
um
go ahead and just
place it uh here no actually it has to
be at the end so here
hit that and then false it will directly
go here
so this will be the new current health
so it's basically plug that
on here
great
uh so we have the health done great so
we have to do like I mentioned before is
for example in the decreased Health the
values goes from 0 to 1. so we cannot
directly pass the current health so we
have to do is divide it
over here by our Max health so we're
going to get my health we're going to
explode here and now it will converted
and the same in the increased Health we
have to go and basically divide this
value
and then assign it by our Max health
great
and now in the max increase Max Health
we basically just really have to uh just
passing the normal current value and
then divided by the max health and it
will automatically you know basically
update the the length of the health bar
okay
great and we'll need to do the same with
the stamina but let's first of all check
that everything is working so first of
all of course if I press play we are not
calling this function so we cannot check
it so how can we check it what we can do
is basically go into the third person
character and first of all let's add the
component so in our case it will press
BBC player stats there we go and now we
can also see all the values here so
that's cool but what we're going to do
is basically go
and create some debug uh keys so if we
search for debug key we can now use some
keys so for example let's say that when
we press zero we will do something so we
can get our player stats component and
what we can do is say for example I just
say for example increase health
and we want to increase it by 10.
so actually set this for example to be
one okay the normal key one
instead of the num kit and now when I
press one you can see that it adds the
value now I believe that it didn't add
it correctly because it just filled up
the whole bar
um so let's go ahead and just check so
we are basically adding for example
let's say one okay instead of uh
so yeah you can see that it's already
checking it so uh this is because sorry
I am so stupid the current health right
now is set 200 but let's say that's
gonna be 70.
now it's adding one okay sorry about
that it was my mistake so if I had a 10
now you can see that when I press three
times it will fill up the whole bar
great sorry about that that was my
mistake anyway so now if we say increase
Max Health instead
okay
and let's say that's going to be by 10
too you'll see that
when I press one
the the health bar will increase and and
it looks like the value is decreasing
but it's not basically the health bar
the range is getting bigger so the value
in comparison with the aspect ratio is
decreasing
but it's only the health bar which is
the increase in so it might look right
right now we are decreasing the value
but it's not a craze okay it's not the
case that's not the case anyway so for
example instead of increased health I
can say also decrease health and now
a plug 10
it would go ahead and actually decrease
the health okay now it's actually
decreasing the health okay
um so for example instead we can do a
branch and then we can destroy the
player so you can basically just realize
what is happening so if I press one
see it destroy the player when we get
into that so it's actually doing that
the other one wasn't
anyway
so you can see that everything is
working right now great cool really
really cool let's go ahead and add one
more thing into our HUD and I will go
ahead and I think I'll leave this well
welcome to the stamina and I'll leave
this episode because it's gonna be a lot
so we're gonna go into the health bar
and get a text and basically put it over
here
and now the anchor is going to be here
and actually I'm gonna reset the
position so everything is nice and clean
so the alignment is going to be 0.5 and
0.5
and now the position y will basically
will be over here
and now the font if we change the size
we can make it smaller okay so let's say
it's going to be for example 10 and the
lineman will be in the middle now we can
get also the size and basically make it
smaller so it is a bit better it also be
basically our value so for example if we
put 70 this would mean that we have 70
of health so basically this is exactly
what we want so we can use preview this
so now what we can do is put this here
and say health
text and then put it as a variable so
now we can go into the player stats and
then we can go into degrees health
and also what we can do now is basically
get the help bar so the widget and then
get the health text
and then set the text
okay not the tooltip
but set the this the text
I know there's a lot of notes here but
you know if we want to keep everything
organized and More in control we don't
have to directly bind all this and it's
a bit more
um useful
so what we can do is just pass here the
uh basically the text so
what we can do is just um get the the
current health
and pass it here and now when we
decrease it they will basic update and I
can just copy this go into the increase
Max health
and then also paste it here
and then put the target to be the widget
and then
copy this and then go into quiz health
and then also we can delete the
print and put this here
and I get the the widget
uh you will see that um when I basically
press one
it will update the the text too
so cool everything is going ahead and
working let's quickly go ahead and do
the same with the stamina so it's going
to player stats let's go into degrees
stamina right before this I want to do
it's basically get the cutter blueprint
and get the HUD widget and then we want
to get the stamina bar and they want to
go ahead and set the percent
and this is going to be basically let's
take all this input to the right and
this is going to be the current stamina
divider by the max time
and now we can pass this as a value
and I can get basically this let's copy
um compile and paste it go into increase
Max stamina
and paste it and now Inc I go into just
increased stamina
and then basically paste it at the end
but remember to connect the false too
because now it will only happen in one
of the cases
and we have to sorry we need to get the
with the widget I forgot about that
this
I'm going to key
put it here
and then here so this last part of the
tutorial maybe was a bit more tedious a
bit more complicated but it's actually
just simple it's just getting the value
just passing it here you know
so now if we were to go into the third
person controller and basically uh
increase stamina instead so in here two
five for example
now you will see that this stamina
increases
now again we want to go into the stamina
I may put this to be 50. so it's not the
whole so now we press play
now I think that we are also going to do
is go into the player stats and
basically copy this of the set
percentage and go into the van graph and
basically set over here and we will go
into the decreased health
and copy this two over here
so why I am basically all this all this
so the percent text and we'll paste it
after
then and now we'll get the current
health unplug it here so when the game
starts it will automatically get the
values and then fill them over here and
you can see already everything is going
ahead and working now we got into -20
um don't worry about that we'll face the
negative ranges over here
um you can see that we also got an error
because we're dividing negative numbers
and stuff basically in the gives a
decrease health
even though we are doing the negative uh
part over here we're still subtracting
so don't worry we'll fix it in the next
episode but that's it guys if you found
it so helpful I will share your video
and subscribe to my channel I have lots
of Unreal Engine 5 tutorials so if you
want to go ahead and check it out go
ahead during the Discord service you can
go ahead and share your progress and ask
any questions and in the next episode
we'll continue with the player stats
we'll go ahead and fix this two things
over here and then we'll go ahead and
start with the
um basically with the XP and leveling
and stuff and then we made make the UI
bit prettier I will see maybe that's for
the next episode but very soon basically
we'll start with the comment like as
soon as we finish with the basics of the
players stats we'll begin with the
combat so I'm very excited about all
this so with all that said go ahead and
like videos subscribe to my channel and
without said bye bye
foreign
[Music]
Browse More Related Video
![](https://i.ytimg.com/vi/7P4U5wmONKI/hq720.jpg)
Unreal Engine 5 RPG Tutorial Series - #6: Damage and Stamina
![](https://i.ytimg.com/vi/2brno65Gr-8/hq720.jpg)
How to make a DOOM CLONE in Unity || E1M4 Player Health and Armor
![](https://i.ytimg.com/vi/xjffkO3sIEU/hq720.jpg)
Simple Inventory (PART 1: Adding Items to Player Inventory)
![](https://i.ytimg.com/vi/TuiDgXCarP0/hq720.jpg)
Unreal Engine 5 RPG Tutorial Series - #4: Assassinations
![](https://i.ytimg.com/vi/ugiNsb9pc8k/hq720.jpg)
Unreal Engine 5 RPG Tutorial Series - #14: Equipment System
![](https://i.ytimg.com/vi/zbbWk851IXk/hq720.jpg)
Unreal Engine 5 RPG Tutorial Series - #10: Sword Trace Damage and Hit Reactions
5.0 / 5 (0 votes)