Unreal Engine 5 RPG Tutorial Series - #5: Player Stats - Health, Stamina and XP

Gorka Games
25 Feb 202333:48

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

00:00

😀 创建角色状态蓝图

本段介绍了如何在Unreal Engine 5中创建一个新的蓝图类,用于管理角色的状态,如生命值、耐力、经验值和等级。通过创建一个Actor Component蓝图,将该组件添加到第三人称角色中,以保持组织结构。同时,设置了当前生命值、最大生命值、当前耐力、最大耐力、经验值、最大经验值和等级等变量,并为它们创建了不同的类别以便于管理。

05:01

🔧 定义健康和耐力的增减功能

本段详细说明了如何创建减少健康值的函数,包括设置函数输入参数以接收伤害值,并根据伤害值更新当前生命值。同时,还介绍了如何检查生命值是否降至零或以下,以触发角色死亡的逻辑。此外,还创建了增加最大生命值的函数,并通过输入参数来实现生命值的增加。

10:02

📊 实现健康和耐力的UI显示

本段讲解了如何在用户界面上实现健康和耐力的进度条显示。首先创建了一个画布面板,并添加了进度条以表示健康和耐力的状态。接着,通过设置锚点和位置,将进度条放置在屏幕的适当位置,并调整了进度条的大小和颜色。最后,通过绑定进度条的百分比来动态显示当前的生命值和耐力值。

15:03

🖥️ 将UI与游戏逻辑绑定

本段描述了如何将之前创建的UI元素与游戏逻辑相绑定。首先,在第三人称角色蓝图中添加了玩家状态组件,并设置了调试键以便于测试。然后,通过编写蓝图逻辑,实现了在受到伤害时更新健康条和文本显示的功能。此外,还介绍了如何将最大生命值和耐力值的变化反映在UI上。

20:03

🎮 测试和调整UI显示

本段主要讲述了如何通过测试来验证UI显示的准确性。通过在第三人称角色蓝图中添加组件,并使用调试键来模拟增加和减少健康值的操作,检查UI上的健康条和文本是否能够正确更新。同时,还提到了如何处理UI上显示的负数问题,并预告了下一期视频将解决这些问题,并继续介绍经验值和等级系统。

25:04

🔄 完善玩家状态的UI和逻辑

在本段中,完成了玩家状态UI的剩余部分,并确保了所有功能正常工作。首先,对健康和耐力的UI进行了最终调整,包括设置百分比文本和绑定当前值。然后,通过在第三人称控制器中增加体力,测试了UI的更新情况。最后,预告了下一期视频将继续完善玩家状态,并开始介绍战斗系统。

Mindmap

Keywords

💡Unreal Engine 5

Unreal Engine 5(虚幻引擎5)是一款由Epic Games开发的游戏引擎,它被广泛用于创建和开发各种类型的游戏。在视频中,它作为教程的背景,说明了教程是关于如何使用这款引擎来开发角色扮演游戏(RPG)系列的。

💡Blueprints

Blueprints(蓝图)是Unreal Engine中的一种可视化脚本系统,允许开发者通过图形界面而非传统编程来设计游戏逻辑。视频中提到创建新的蓝图类,用于管理玩家的统计数据,如生命值、耐力、经验值和等级。

💡Player Stats

Player Stats(玩家状态)指的是游戏中玩家角色的各种属性,如生命值、耐力、经验值和等级。视频中的教程专注于如何构建和显示这些玩家状态,是角色扮演游戏设计的核心部分。

💡UI

UI(用户界面)是指用户与游戏交互的界面。在视频中,UI设计涉及到如何在屏幕上显示玩家的生命值和耐力条,以及如何通过蓝图动态更新这些信息。

💡Health Bar

Health Bar(生命值条)是游戏中显示玩家当前生命值的视觉元素。视频中详细说明了如何在Unreal Engine中创建和调整生命值条的大小、位置和颜色,以及如何将其与玩家的实际生命值数据绑定。

💡Stamina

Stamina(耐力)是玩家在游戏中执行动作(如跑步或战斗)时消耗的一种资源。视频教程中包括了如何创建和管理玩家的耐力值,并在UI上显示耐力条。

💡XP and Leveling

XP(经验值)和Leveling(等级系统)是角色扮演游戏中常见的机制,玩家通过获得经验值来提升等级,从而增强角色的能力。视频中提到了设置XP和等级系统,这是玩家成长和游戏进度的关键部分。

💡RPG Series

RPG Series(角色扮演游戏系列)指的是一系列以角色扮演为主题的游戏。视频中的教程是关于如何使用Unreal Engine 5开发这样的游戏系列,包括玩家状态管理和UI设计。

💡Actor Component

Actor Component(演员组件)是Unreal Engine中的一个概念,它允许开发者为游戏世界中的Actor(实体)添加特定的功能或行为。视频中创建了一个用于管理玩家统计数据的Actor Component。

💡Progress Bar

Progress Bar(进度条)是一种常见的UI元素,用于直观显示玩家的状态或任务的完成度。在视频中,进度条被用来表示玩家的生命值和耐力,通过编程动态更新以反映玩家的实际状态。

💡Widget Blueprint

Widget Blueprint(控件蓝图)是Unreal Engine中用于设计和创建自定义用户界面元素的工具。视频中使用Widget Blueprint来创建和管理游戏中的HUD(头部显示器),包括生命值条和耐力条。

Highlights

教程介绍了如何在Unreal Engine 5中创建RPG系列游戏中的玩家状态系统,包括健康、耐力、经验值和等级。

通过创建一个新的蓝图类,作为Actor Component,来组织和添加到第三人称角色中,以保持事物的组织性。

设置了玩家状态的变量,如当前健康、最大健康、当前耐力、最大耐力、经验值、最大经验和等级。

创建了用于减少健康值的函数,并根据受到的伤害输入值来更新当前健康。

实现了一个检查,如果玩家健康值降至零或以下,则玩家将死亡。

创建了增加健康值的函数,允许在角色升级时增加最大健康值。

为健康和耐力条设置了默认值,并定义了经验值和最大经验值,用于升级所需的经验值。

创建了用于减少和增加耐力的函数,并设置了相应的边界条件。

实现了一个函数,用于在玩家恢复时逐渐增加健康值,而不是立即设置为最大健康值。

创建了一个新的小部件蓝图,用于在用户界面上显示玩家的状态,如健康和耐力条。

在用户界面中使用了进度条来可视化健康和耐力的当前状态。

通过绑定和事件,将玩家状态的变化实时更新到用户界面上。

在第三人称角色蓝图中添加了玩家状态组件,并在游戏开始时初始化了HUD小部件。

通过按键调试功能,可以在游戏运行时手动测试健康和耐力的变化。

在HUD中添加了文本显示,以实时显示当前的健康和耐力数值。

教程最后提到,接下来的视频中将继续完善玩家状态系统,并开始探讨经验值和等级系统。

整个教程强调了在Unreal Engine 5中创建和实现玩家状态系统的逻辑和UI展示的重要性。

Transcripts

play00:00

what's up guys welcome to new Unreal

play00:02

Engine 5 tutorial and today we are

play00:04

continuing with the RPG Series today we

play00:06

will start with the player stats

play00:08

basically Health stamina XP level and so

play00:10

on it will start to structure the you

play00:12

know the system and basically start

play00:14

displaying some things in the UI it's

play00:16

going to be a very easy beautiful so

play00:18

let's get started

play00:20

[Music]

play00:22

alright so the first thing that we have

play00:23

to do is go into Blueprints and we're

play00:26

gonna create a new blueprint class over

play00:28

here and it's going to be an actor

play00:29

component so basically it's gonna be on

play00:31

a separate blueprint that will basically

play00:33

add it as a component into our third

play00:35

person character and basically it would

play00:37

just keep things more organized I

play00:39

wouldn't have a huge you know event

play00:41

graph and a lot of functions in our main

play00:43

players so it will be more organizers

play00:45

okay so let's click on actor component

play00:47

and this will be bpc so a blueprint

play00:50

component then this can be underscore

play00:52

player stats and now we can go ahead and

play00:55

open this guy up all right so we have to

play00:59

basically start setting up some

play01:00

variables over here so the first one is

play01:03

going to be basically current health so

play01:05

it's going to be current uh actually

play01:07

it's gonna be on Capital C Uh current

play01:10

health and then this is gonna be

play01:12

basically a float great so now we're

play01:15

going to create a new variable and this

play01:16

will be the max

play01:18

help over here great so now we have the

play01:20

health over here the current health and

play01:22

the max now we need to set up the

play01:24

current stamina

play01:26

current stamina there we go and now the

play01:30

max stamina three and again they're

play01:33

gonna be flows so they're gonna be

play01:35

basically numbers with decimals so they

play01:37

can be more accurate okay and now we're

play01:39

gonna need basically XP

play01:42

and then we're gonna need

play01:44

uh Max XP

play01:47

and then we're gonna need

play01:49

level

play01:51

great I know level is going to be an

play01:53

integer and then we can keep XP and Max

play01:55

XP as if load great so we have all the

play01:58

variables set up let's go ahead and

play02:00

create some categories so we can have

play02:01

things uh more organized so let's go

play02:04

ahead and select both current health and

play02:05

Max Health actually we can only select

play02:07

one at once so you select Corner Hill

play02:10

I'm gonna go into category

play02:11

now we can write here health so it's

play02:14

going to be the health categories go

play02:16

into max health and now we can go into

play02:17

drop down and select the one that we

play02:20

have just created Health here and now

play02:22

it's going to current stamina and just

play02:24

type stamina

play02:26

and now we can go into max stamina and

play02:28

plus stamina and now XP type XP

play02:32

and then in Max XP just type XP and now

play02:36

I'm gonna go ahead and select level and

play02:37

also put it as XP and so they're pretty

play02:40

much from the same category they will

play02:41

link together a lot great so now it's a

play02:44

bit more organized you can see like

play02:45

Health stamina XP all the player stats

play02:48

um join together and separate at the

play02:50

same time great so let's start grading

play02:52

some functions and the first one is

play02:55

going to be basically

play02:56

um decrease health so when we take

play02:58

damage

play02:59

from our player we'll go ahead and

play03:01

access this component and then code the

play03:03

function that will decrease our health

play03:04

so let's go into functions create new

play03:06

health shouldn't be decrease

play03:08

health

play03:09

great so what we want to do let's go

play03:12

ahead and get the current health and set

play03:14

it okay so we'll be basically overriding

play03:17

this over here so we want to go ahead

play03:19

and say hey we want to get our current

play03:21

health right now and decrease it by an

play03:25

incoming value so this will be the

play03:27

damage taken so for example if we have

play03:29

right now like a hundred of health and

play03:31

we decreased you know 10 we'll have 90.

play03:34

so now we'll be setting that 90 into our

play03:36

new current health okay now the thing is

play03:38

that this damage needs to depend on how

play03:41

much we're receiving

play03:42

so what we can do is directly plug it as

play03:46

an input in our function so later on

play03:48

when we call it when we are you know

play03:51

affected by damage when we call this

play03:53

function we can directly pass it as an

play03:55

input value so this is going to be the

play03:57

uh basically uh just damage all right

play04:01

and it's going to be again a float so

play04:02

let me go ahead and put this a bit to

play04:04

the left over here to the right so it's

play04:06

a bit more organized okay yeah so

play04:09

basically the hook current health

play04:10

decreases by B damage and then set it so

play04:12

now this will be the new uh current

play04:15

health field here so now we have to bank

play04:17

a branch over here and what we have to

play04:19

do is basically

play04:21

um check if our health is zero or below

play04:24

zero if so our player has to die so what

play04:28

we have to do over here is basically get

play04:30

the current health and then say well it

play04:33

is

play04:34

um less equal okay so if it's less than

play04:37

equal than zero

play04:39

so we drew over here well our player

play04:41

will go ahead and die if not it will be

play04:43

false so what we're going to do is

play04:46

basically click on the decrease health

play04:47

over here and create an output and this

play04:50

will be a Boolean which is going to be

play04:52

um basically is

play04:54

player

play04:56

that

play04:58

okay and now in true we will go ahead

play05:00

and set this to be true but on false it

play05:04

will set to be false so now later on in

play05:06

our third person character when we call

play05:08

this function and access the component

play05:10

we'll get a return to this Boolean over

play05:13

here and then depending if it's dead or

play05:15

not in there we'll activate Ragdoll and

play05:17

the effects that we need and so on

play05:20

great so that's pretty much the decrease

play05:21

Health done we are now going to go to

play05:24

the increased health so imagine that we

play05:26

level up and we want to increase our Max

play05:28

health so our character will have more

play05:30

Health instead of 100 let's say more

play05:32

let's go ahead and create a function for

play05:34

it now first of all let's set the

play05:36

current health of the variable by

play05:38

default to be 100 okay because we wanted

play05:40

to set it uh to be 100 and the same with

play05:43

Max Health we want to start the game

play05:45

basically with a hundred of health and

play05:48

again with the stamina you're going to

play05:49

do the same let's do a 100 MX Tamina 100

play05:53

so it's going to be basically a default

play05:55

value so it will start off course you

play05:57

can customize this as you want but I

play05:59

recommend you don't have to just bring

play06:00

100 and then in XP well you'll have zero

play06:03

XP Max XP is going to be basically the

play06:07

amount of XP needed to level up

play06:10

so let's say that now we have zero so if

play06:13

both here in Max XP for example again

play06:15

100 will basically need 100xp to go into

play06:19

the next level and now by default it

play06:21

will be level one so there we go we have

play06:23

all the default values over here so now

play06:25

let's go ahead and continue on creating

play06:27

the uh increased health so increase

play06:30

health function

play06:32

again if I know how to type correctly

play06:35

great so this is going to be very

play06:37

similar but we have to do the opposite

play06:39

basically so let's get current health

play06:41

and set it over here

play06:43

okay and now we also need to get a Max

play06:46

tell H3 yes it's gonna be myself

play06:50

so when we increase the health what we

play06:53

want to do is not directly increase the

play06:56

current help that we have right now it's

play06:58

going to be basically the max Health

play07:00

that we can and then later on slowly

play07:03

regenerate okay so if it makes sense so

play07:06

what we can do is just get the current

play07:07

Max Health then add the value that we

play07:11

want which again will be an input and

play07:13

then this will be the new Max Health

play07:15

which is basically what we did with the

play07:18

decreased Health but as you can see

play07:19

inverted and this time with the max

play07:22

Health great and now what we have to do

play07:25

is actually not put really any condition

play07:27

because we don't have any boundaries

play07:29

really for Max Health maybe if we want

play07:33

to increase it by a thousand we can okay

play07:35

it's just the max Health as can be any

play07:37

High number that we want okay so really

play07:39

we don't have to do anything now in here

play07:41

let's selected and we change the input

play07:42

to be you know I don't know uh

play07:46

uh incremention

play07:48

I don't know that makes sense but Health

play07:51

incremention you know you can put

play07:53

whatever value makes sense for you okay

play07:55

and there we go now if you want you can

play07:57

go and set the current health to be

play08:01

directly the new Max health so it will

play08:04

out to generate two so it will not you

play08:07

will not need to wait until it generates

play08:09

but I will go ahead and delete this as

play08:12

we want to go ahead and wait slowly

play08:14

until slowly until it basically

play08:16

regenerates okay

play08:18

great so now let's go ahead and move on

play08:20

to the stamina so here we have the

play08:22

functions over here so we now want to go

play08:25

ahead and create a stamina again the

play08:27

category we'll go ahead and put it on

play08:29

the health

play08:30

for both so everything is nice and

play08:32

organized right let's go ahead and

play08:33

create a new function and again decrease

play08:38

stamina

play08:40

go ahead and get the current stamina and

play08:43

set it so basically we want to get the

play08:45

current stamina that we have right now

play08:47

and basically decrease it by the amount

play08:50

incoming which I guess will be basically

play08:53

and here it was damage well in here we

play08:56

can say

play08:57

um

play08:58

stamina depleted I think it's that's how

play09:03

you you say it and then we can plug it

play09:05

into current stamina okay which is again

play09:07

what we did with decreased Health but

play09:09

instead of the with the health basically

play09:11

with a stand and now in here we need

play09:13

boundaries because we are decreasing

play09:14

health so

play09:16

stamina sorry so we want to do is get

play09:18

the current health

play09:20

and be like okay so if this is less or

play09:22

equal than zero

play09:24

it will mean that we cannot longer run

play09:26

so we just want to create an output

play09:28

and this will be

play09:30

um stamina

play09:32

uh

play09:34

not stamina left

play09:38

okay and now we want to plug the intrude

play09:41

so hey we are not any we don't have any

play09:45

stamina left so later on in the player

play09:47

controller we'll say that you cannot run

play09:49

anymore or attack anymore until it

play09:51

generates again and in defaults we'll do

play09:53

the opposite untick it great and now we

play09:56

want to go into uh increased stamina so

play09:58

create a new one

play10:01

right and now I want to do is get the

play10:04

max stamina and set it okay and it's

play10:06

going to be the same pretty much that we

play10:07

did with increased Health very simple

play10:09

just get the max stamina when I get it

play10:12

then basically add a value and this will

play10:15

be the incoming value here so I guess we

play10:17

could say

play10:18

um incoming

play10:21

or added added stamina

play10:24

it makes more sense and now that will be

play10:26

the new Max Diamond over there great and

play10:28

we don't need anymore again you can go

play10:30

ahead and auto set the current stamina

play10:32

to be automatically the max one now this

play10:35

will depend on what you want for example

play10:37

if you call increased stamina

play10:40

um so this will be the max I mean okay

play10:43

from when you level up well

play10:46

do basically maybe want to Auto Select

play10:49

the the current stamina you have and you

play10:52

know put it into the max but maybe not

play10:54

so it will basically go ahead and depend

play10:58

now what we have to do now is basically

play11:01

do the same but with the current stamina

play11:03

and the current health so actually sorry

play11:07

about that but this is gonna be

play11:08

basically increase

play11:11

um let's change the name

play11:13

if I can come on break come on here so

play11:16

select it here and go here this will be

play11:18

basically Max health and uh Max stamina

play11:23

oh that's the description

play11:26

I don't know oh we need to select the

play11:28

notes sorry so we're going to increase

play11:30

stamina you'll hear sorry about that

play11:32

please Max them and again we're gonna

play11:34

apply it into the category stamina

play11:38

so yeah sorry about the confusion there

play11:39

I I've even confused myself

play11:42

but we want to that was the Maxima so I

play11:44

was referring like for example when you

play11:45

level up I want to have more stamina

play11:47

later on but now we need to actually do

play11:49

the uh like incrementing and so for

play11:52

example when you recover your health

play11:54

until you get into the next of the

play11:56

health value and so on if it makes sense

play11:58

so we want to create a new function

play12:00

which will be basically increase and

play12:03

just overall the health and this will be

play12:06

in the health value over here

play12:09

so we want to basically get the current

play12:10

health and basically set it and what we

play12:13

want to do is basically get the current

play12:16

health again not Health sorry

play12:18

and then we want to decrease the

play12:20

incoming value over here so uh sorry

play12:23

increase increase I'm going crazy here

play12:25

increase the incoming value so uh this

play12:29

will be basically I added to values

play12:30

let's plug it into the first one and

play12:32

then delete that one will be the added

play12:35

health

play12:38

there we go and now this will be the new

play12:39

health now what we have to do is make

play12:42

sure that it is not going outside

play12:43

outside our bonds of the max health so

play12:46

we have to do basically a branch over

play12:48

here it's basically say well is current

play12:50

health

play12:53

um bigger or equal

play12:56

uh well sorry it will be only bigger

play12:58

so is our current stamina bigger than

play13:01

our Max health so as a coordinate

play13:05

stamina but current health so is it

play13:07

bigger well if it's bigger what we have

play13:10

to do is set the current health

play13:14

to directly be the max health

play13:18

because we don't want to get into the

play13:19

bounce so we automatically set it to be

play13:21

the maximum and if not it will be okay

play13:24

inside the bounce okay so now we can

play13:27

compound type and now let's do the same

play13:29

for the stamina so create a new function

play13:31

this will be just increase stamina

play13:34

and now we want to do is get the current

play13:37

stamina and set it

play13:40

and I want to get our current stamina

play13:42

get it and then add the new values to

play13:46

plug it in here added stamina

play13:50

there you go and now we can plug that

play13:52

into the new Setter over here so this

play13:55

will be our new stamina and again we

play13:57

have to do the check over here so make a

play13:58

branch basically we need to get our

play14:00

current stamina and say hey these are

play14:03

current stamina bigger than our Max

play14:05

stamina

play14:07

so we have to do is automatically set

play14:10

the current stamina

play14:12

to be the max them because we want to

play14:15

keep keep it in the belt if not it's

play14:18

okay

play14:19

great so we have all the health and

play14:21

stamina done the only thing left is to

play14:24

click here and put the stamina category

play14:28

great so later on we'll continue with

play14:30

the XP but now let's go ahead and start

play14:32

actually implementing this in our UI

play14:36

so let's go here and let's go into

play14:38

content UI and right click and go into

play14:41

user interface and create a new widget

play14:43

blueprint so this will be a normal user

play14:45

widget and it'll be wgwb underscore and

play14:49

this will be basically our main HUD

play14:51

so let's go ahead and open this up

play14:53

so the palette will go ahead and search

play14:55

a canvas panel and add it into the

play14:57

hierarchy so now we can start placing

play14:59

our UI over here so we want to do is

play15:02

basically get a progress bar let's go

play15:05

ahead and drag it just in the scene

play15:07

great well in the C9 in the panel you

play15:09

understand me anyway let's go into

play15:11

anchors and the thing is that Assassin's

play15:13

Creed Origins which is the game that we

play15:15

are basing up this RPG game it's gonna

play15:17

be uh having the health on the bottom

play15:20

part Center over here so let's go ahead

play15:21

and place the anchor right over there

play15:23

and now what we can do is get the

play15:25

position X to be zero

play15:27

and Y to be zero so now it will be here

play15:30

great so this is basically just the

play15:33

offset really and now the size we want

play15:36

to change this don't worry we'll Place

play15:39

good the offset but the size X is

play15:41

basically the size horizontally and size

play15:44

y vertically so we want maybe to have it

play15:47

a bit thinner so in the Y we'll go ahead

play15:49

and half this into 20. now this you know

play15:52

customizing it as you want but then in

play15:54

next uh size X we'll go ahead and put it

play15:57

like for example 500 so we want kind of

play15:58

a Long Bar as it is on the Assassin's

play16:02

Creed reference now in alignment we're

play16:04

gonna add 8.5 in next and then a

play16:09

8.5 in y so be perfectly in the center

play16:12

because not it was basically in the

play16:14

corner and now we want to do is have a

play16:16

upset on the position y of let's say 100

play16:19

maybe no that's yeah exactly but it's

play16:23

going to be negative

play16:24

so now as you can see basically we're

play16:26

having our health bar exactly place

play16:29

where we need values on the widget over

play16:31

here now you manually can drag them but

play16:34

I don't recommend to drag it you know I

play16:36

recommend to place it like that great so

play16:38

now what we can do is add a percent just

play16:41

to visualize how it would look so for

play16:43

example you can add 0.7 so the values

play16:46

will basically go from this progress bar

play16:48

from 0 to 1 okay so because the values

play16:52

goes from 0 to 1 later on because our

play16:55

values goes from zero to our Max Health

play16:57

what we'll do is basically divide the

play17:00

the number by the max health and we will

play17:02

obtain a range from zero to one great so

play17:05

for example we just plug this points on

play17:07

here just to visualize a bit the UI and

play17:09

now we can change the field color and

play17:11

opacity to a reddish one as you can see

play17:13

so just press ok now later on in the

play17:16

series we will customize a UI with

play17:18

custom images and brushes and stuff in

play17:21

here in this Tau with the if your image

play17:23

background images but in here we only

play17:26

gonna basically make the main structure

play17:28

so we are not gonna get into that right

play17:31

now but of course we will do in the

play17:34

future

play17:35

anyway let's go ahead and compounds it

play17:37

now let's go ahead and do the same but

play17:39

with the stamina so first of all I think

play17:42

I'm going to do is get the progress bar

play17:44

and change the name to be basically uh

play17:46

sorry stamina now uh health bar

play17:49

okay and now we will keep this as is

play17:52

bevel because you will see now there are

play17:54

two options of basically assigning this

play17:57

health at runtime first of all we can

play17:59

directly make a binding for a percent so

play18:03

basically

play18:04

um pretty much on every frame

play18:07

it will be getting the the value from

play18:09

where we say and applying it over here

play18:11

right on the graph of the widget

play18:14

but another thing that we can do is go

play18:17

into the player stats and on here when

play18:20

we directly for example increase the

play18:22

health we can call The Witcher and then

play18:25

set the new uh

play18:27

basically values okay which is the thing

play18:30

that we're going to do okay because it's

play18:31

going to be more practical we are only

play18:34

gonna call it when we need it and so on

play18:36

so it's going to be a bit more let's say

play18:38

clean so

play18:40

um let's first of all go ahead and do

play18:42

the stamina bar too so duplicate this

play18:44

this is going to be the change the name

play18:46

into stamina bar and then we are right

play18:50

gonna go ahead and change the fill color

play18:52

to a

play18:54

kind of yellowish one and now we can

play18:57

again uh change a bit the anchors over

play19:00

here so basically for this position X to

play19:02

be zero and then this to be maybe 70

play19:05

minus 70 sorry a negative number so now

play19:08

it's right on the bottom what we want to

play19:11

do is make a bit thinner so it's going

play19:12

to be a bit less

play19:15

um bigger than the health bar so we can

play19:16

do is go into this size

play19:18

um Y and change this to be for example

play19:20

15 or even 10 yeah even 10 I like that

play19:23

and now you can have here the stamina

play19:26

and the health now later on we'll

play19:28

probably customize this like I mentioned

play19:30

before this is just to get a bit of the

play19:32

sense of the of how it would look and

play19:34

stuff you know great so make sure that

play19:36

seminar bar is set as its variable two

play19:39

okay great so now let's go ahead and

play19:42

make sure that this widget goes goes

play19:45

ahead and appears on the screen

play19:47

so we have to do is go into the third

play19:50

person guide to blueprint and basically

play19:52

open up

play19:53

and we're going to do is go into the

play19:55

begin play so when the game starts right

play19:58

after it does all the input uh context

play20:01

and stuff we want to go ahead and save

play20:03

this note which is great widget

play20:05

and now we want to choose the widget

play20:07

that we have just created which is the

play20:08

HUD and then the online player we can

play20:10

just say that's gonna be the get player

play20:13

controller and now the return value will

play20:15

do is create a variable so later on from

play20:18

our

play20:19

um component we can access it so we can

play20:22

just right click promote variable and

play20:24

this will be the HUD widget we'll go

play20:27

ahead and name it like that and now

play20:29

we'll have to do is get this and then

play20:30

add it into the viewport so it will

play20:32

basically add it just into the player

play20:34

screen let's go ahead and comment this

play20:36

and say well I create widget

play20:41

and there we go and now let's go ahead

play20:43

and get the comment color

play20:45

and copy and paste over here now one of

play20:49

you commented me that I did not realize

play20:51

that there's actually like presets that

play20:52

you can push and so in probably the next

play20:55

episode we'll go ahead and create a

play20:56

piece of preset so we have to copy and

play20:58

paste the color every time you know but

play21:00

anyway so now if I press play you will

play21:03

see that indeed we have the UI over here

play21:06

and it is perfectly aligned like we like

play21:09

we mentioned before great so now we need

play21:11

to basically apply the values over here

play21:12

and so on and so on so what we have to

play21:15

do is go into the player stats and

play21:18

basically let's begin with the uh

play21:20

decrease health so let's go from up to

play21:22

down

play21:23

so what we can do is write over here

play21:26

before we

play21:28

basically finish our value is go and

play21:31

basically get the owner

play21:34

okay so basically we'll be getting the

play21:36

owner and what we want to do is

play21:38

basically cast to our third person

play21:40

character

play21:42

but what we can do instead of basically

play21:44

doing every time we can just go into the

play21:46

event graph and do this at the begin

play21:48

play and then save our owner as a

play21:52

variable so we don't have to get the

play21:54

owner and cash in in every uh basic

play21:57

function we can just do it once so we

play21:59

want to do is go here and get the owner

play22:03

and then we want to cast to the third

play22:06

person character

play22:08

and we plug this in and down here in the

play22:10

output we can just promote this to a

play22:13

variable and this will be our player

play22:15

character

play22:17

lbb

play22:19

great so now

play22:23

like that great we can just go into

play22:25

decrease health

play22:26

and right on here we can just get our

play22:27

character

play22:29

sorry get it and then basically get the

play22:32

HUD

play22:33

all right and now we can do is basically

play22:36

get our

play22:39

um health bar

play22:40

a lot of Getters here and then basically

play22:43

um set the percent okay so in progress

play22:46

set percent

play22:48

and now we can plug this in

play22:50

and basically this will be the new value

play22:52

over here

play22:53

great so now we'll do the same with the

play22:55

max Health but we're going to do is just

play22:57

copy this because it's going to be more

play22:59

handy so I'll copy that go into quiz

play23:01

help bar and right at the end I'm gonna

play23:03

paste this

play23:05

and then put this over here so the same

play23:08

with increase uh the health now the

play23:11

things that we have to do one more thing

play23:13

we cannot directly place the percent so

play23:15

we'll do one that basically that in a

play23:17

second but it's going to increase health

play23:19

and on here

play23:22

um

play23:24

go ahead and just

play23:25

place it uh here no actually it has to

play23:28

be at the end so here

play23:31

hit that and then false it will directly

play23:34

go here

play23:35

so this will be the new current health

play23:39

so it's basically plug that

play23:43

on here

play23:45

great

play23:46

uh so we have the health done great so

play23:48

we have to do like I mentioned before is

play23:50

for example in the decreased Health the

play23:52

values goes from 0 to 1. so we cannot

play23:56

directly pass the current health so we

play23:59

have to do is divide it

play24:02

over here by our Max health so we're

play24:05

going to get my health we're going to

play24:08

explode here and now it will converted

play24:10

and the same in the increased Health we

play24:13

have to go and basically divide this

play24:16

value

play24:20

and then assign it by our Max health

play24:24

great

play24:25

and now in the max increase Max Health

play24:29

we basically just really have to uh just

play24:32

passing the normal current value and

play24:35

then divided by the max health and it

play24:39

will automatically you know basically

play24:42

update the the length of the health bar

play24:45

okay

play24:46

great and we'll need to do the same with

play24:48

the stamina but let's first of all check

play24:50

that everything is working so first of

play24:52

all of course if I press play we are not

play24:55

calling this function so we cannot check

play24:56

it so how can we check it what we can do

play24:59

is basically go into the third person

play25:01

character and first of all let's add the

play25:03

component so in our case it will press

play25:05

BBC player stats there we go and now we

play25:08

can also see all the values here so

play25:10

that's cool but what we're going to do

play25:12

is basically go

play25:14

and create some debug uh keys so if we

play25:17

search for debug key we can now use some

play25:21

keys so for example let's say that when

play25:23

we press zero we will do something so we

play25:26

can get our player stats component and

play25:29

what we can do is say for example I just

play25:31

say for example increase health

play25:34

and we want to increase it by 10.

play25:37

so actually set this for example to be

play25:39

one okay the normal key one

play25:42

instead of the num kit and now when I

play25:44

press one you can see that it adds the

play25:46

value now I believe that it didn't add

play25:49

it correctly because it just filled up

play25:50

the whole bar

play25:52

um so let's go ahead and just check so

play25:54

we are basically adding for example

play25:55

let's say one okay instead of uh

play25:59

so yeah you can see that it's already

play26:00

checking it so uh this is because sorry

play26:03

I am so stupid the current health right

play26:06

now is set 200 but let's say that's

play26:08

gonna be 70.

play26:11

now it's adding one okay sorry about

play26:15

that it was my mistake so if I had a 10

play26:18

now you can see that when I press three

play26:21

times it will fill up the whole bar

play26:23

great sorry about that that was my

play26:25

mistake anyway so now if we say increase

play26:29

Max Health instead

play26:31

okay

play26:32

and let's say that's going to be by 10

play26:33

too you'll see that

play26:36

when I press one

play26:39

the the health bar will increase and and

play26:42

it looks like the value is decreasing

play26:45

but it's not basically the health bar

play26:48

the range is getting bigger so the value

play26:51

in comparison with the aspect ratio is

play26:54

decreasing

play26:55

but it's only the health bar which is

play26:58

the increase in so it might look right

play27:00

right now we are decreasing the value

play27:02

but it's not a craze okay it's not the

play27:04

case that's not the case anyway so for

play27:07

example instead of increased health I

play27:09

can say also decrease health and now

play27:12

a plug 10

play27:14

it would go ahead and actually decrease

play27:17

the health okay now it's actually

play27:18

decreasing the health okay

play27:21

um so for example instead we can do a

play27:23

branch and then we can destroy the

play27:25

player so you can basically just realize

play27:27

what is happening so if I press one

play27:30

see it destroy the player when we get

play27:32

into that so it's actually doing that

play27:34

the other one wasn't

play27:36

anyway

play27:37

so you can see that everything is

play27:38

working right now great cool really

play27:41

really cool let's go ahead and add one

play27:43

more thing into our HUD and I will go

play27:46

ahead and I think I'll leave this well

play27:48

welcome to the stamina and I'll leave

play27:50

this episode because it's gonna be a lot

play27:51

so we're gonna go into the health bar

play27:53

and get a text and basically put it over

play27:56

here

play27:57

and now the anchor is going to be here

play27:59

and actually I'm gonna reset the

play28:01

position so everything is nice and clean

play28:04

so the alignment is going to be 0.5 and

play28:07

0.5

play28:09

and now the position y will basically

play28:12

will be over here

play28:14

and now the font if we change the size

play28:16

we can make it smaller okay so let's say

play28:19

it's going to be for example 10 and the

play28:21

lineman will be in the middle now we can

play28:23

get also the size and basically make it

play28:26

smaller so it is a bit better it also be

play28:28

basically our value so for example if we

play28:31

put 70 this would mean that we have 70

play28:34

of health so basically this is exactly

play28:36

what we want so we can use preview this

play28:39

so now what we can do is put this here

play28:41

and say health

play28:42

text and then put it as a variable so

play28:46

now we can go into the player stats and

play28:49

then we can go into degrees health

play28:50

and also what we can do now is basically

play28:53

get the help bar so the widget and then

play28:56

get the health text

play28:59

and then set the text

play29:02

okay not the tooltip

play29:04

but set the this the text

play29:08

I know there's a lot of notes here but

play29:09

you know if we want to keep everything

play29:11

organized and More in control we don't

play29:13

have to directly bind all this and it's

play29:15

a bit more

play29:16

um useful

play29:18

so what we can do is just pass here the

play29:20

uh basically the text so

play29:24

what we can do is just um get the the

play29:26

current health

play29:28

and pass it here and now when we

play29:32

decrease it they will basic update and I

play29:34

can just copy this go into the increase

play29:36

Max health

play29:37

and then also paste it here

play29:42

and then put the target to be the widget

play29:45

and then

play29:47

copy this and then go into quiz health

play29:50

and then also we can delete the

play29:53

print and put this here

play29:56

and I get the the widget

play29:58

uh you will see that um when I basically

play30:02

press one

play30:03

it will update the the text too

play30:06

so cool everything is going ahead and

play30:08

working let's quickly go ahead and do

play30:10

the same with the stamina so it's going

play30:12

to player stats let's go into degrees

play30:14

stamina right before this I want to do

play30:18

it's basically get the cutter blueprint

play30:22

and get the HUD widget and then we want

play30:26

to get the stamina bar and they want to

play30:29

go ahead and set the percent

play30:31

and this is going to be basically let's

play30:34

take all this input to the right and

play30:36

this is going to be the current stamina

play30:38

divider by the max time

play30:43

and now we can pass this as a value

play30:45

and I can get basically this let's copy

play30:48

um compile and paste it go into increase

play30:50

Max stamina

play30:52

and paste it and now Inc I go into just

play30:56

increased stamina

play30:58

and then basically paste it at the end

play31:01

but remember to connect the false too

play31:04

because now it will only happen in one

play31:05

of the cases

play31:06

and we have to sorry we need to get the

play31:10

with the widget I forgot about that

play31:12

this

play31:13

I'm going to key

play31:16

put it here

play31:17

and then here so this last part of the

play31:19

tutorial maybe was a bit more tedious a

play31:21

bit more complicated but it's actually

play31:24

just simple it's just getting the value

play31:26

just passing it here you know

play31:29

so now if we were to go into the third

play31:31

person controller and basically uh

play31:33

increase stamina instead so in here two

play31:39

five for example

play31:41

now you will see that this stamina

play31:43

increases

play31:45

now again we want to go into the stamina

play31:48

I may put this to be 50. so it's not the

play31:52

whole so now we press play

play31:55

now I think that we are also going to do

play31:57

is go into the player stats and

play32:00

basically copy this of the set

play32:02

percentage and go into the van graph and

play32:04

basically set over here and we will go

play32:06

into the decreased health

play32:09

and copy this two over here

play32:13

so why I am basically all this all this

play32:16

so the percent text and we'll paste it

play32:20

after

play32:21

then and now we'll get the current

play32:22

health unplug it here so when the game

play32:25

starts it will automatically get the

play32:27

values and then fill them over here and

play32:30

you can see already everything is going

play32:32

ahead and working now we got into -20

play32:36

um don't worry about that we'll face the

play32:38

negative ranges over here

play32:41

um you can see that we also got an error

play32:42

because we're dividing negative numbers

play32:44

and stuff basically in the gives a

play32:47

decrease health

play32:48

even though we are doing the negative uh

play32:53

part over here we're still subtracting

play32:55

so don't worry we'll fix it in the next

play32:57

episode but that's it guys if you found

play32:59

it so helpful I will share your video

play33:01

and subscribe to my channel I have lots

play33:03

of Unreal Engine 5 tutorials so if you

play33:04

want to go ahead and check it out go

play33:05

ahead during the Discord service you can

play33:07

go ahead and share your progress and ask

play33:08

any questions and in the next episode

play33:11

we'll continue with the player stats

play33:13

we'll go ahead and fix this two things

play33:15

over here and then we'll go ahead and

play33:17

start with the

play33:18

um basically with the XP and leveling

play33:21

and stuff and then we made make the UI

play33:25

bit prettier I will see maybe that's for

play33:27

the next episode but very soon basically

play33:29

we'll start with the comment like as

play33:31

soon as we finish with the basics of the

play33:33

players stats we'll begin with the

play33:35

combat so I'm very excited about all

play33:37

this so with all that said go ahead and

play33:38

like videos subscribe to my channel and

play33:40

without said bye bye

play33:42

foreign

play33:47

[Music]

Rate This

5.0 / 5 (0 votes)

Related Tags
Unreal Engine 5RPG系列玩家状态游戏开发UI设计教程角色系统健康条耐力条经验值
Do you need a summary in English?