Transcripts
1. 1.01 Introduction: In this course, we're going
to learn how to develop a multiplayer first
person shooter using blueprints in Unreal
engine Five by recreating a game similar to the
iconic game Counter Strike. This course contains everything you need to know to
get started with multiplayer first person
shooter game development in Unreal Engine Five. Including how to add
multiplayer FPS movement. How to make a team
selection screen. How to pick up and drop weapons. How to make an FPS inventory. How to equip a
pistol and a rifle. How to shoot using
different weapon types. How to calculate and display the correct
amount of bullets. How to reload a weapon. How to add health and armor. How to deal damage
to other players. How to reward round points
for the winning team. How to respond players. How to update game UI values
correct in multiplayer. And finally, how to add visual effects and sound
effects in multiplayer. I'll also provide to you the
finished project so that you can inspect it as you wish while following the course. At the end of this
course you'll be able to confidently create your own multiplayer
first person shooter from scratch in
hon real engine five. I hope you'll join me
in this course today. And remember that I'm
always here to support you throughout the course
and I hope to see you soon.
2. 1.02 Downloading Unreal Engine 5: To download Unreal Engine Five, you first have to go to Epic Games.com And inside of here, there is a blue button up
here to the top right. You have to click on it and it will download the
Epic Games launcher. You can see here,
it's installing now. However, I have
already installed it, so just go ahead and install
it when this is finished. And here I have opened up the Epic Games launcher and
it will ask you to sign in. I already have an
Epic Games account, so I'm going to sign in
with my Epic Games account. If you don't have one, you can
go ahead and sign up here. It's for free, or you can sign in with all of
the other methods. However, I'm going to sign in
with my Epic Games account. Once you have signed
into the launcher, you will be inside of this page. Go ahead and click on Honoral
Engine here to the left. Go ahead and click on
the library tab up here, and you will see the
engine versions. This is Honoral Engine, and if you don't see anything, you might have a gray box here if this is the first
time you are inside of here. But if you don't get a gray box, you can click on
this plus button up here and you will get one. Then you can select
the number and select which version of Unreal
Engine you want to install. Now you can see I have
already installed Unreal Engine 5.2 However, if you have a later version, if you're watching this in
the future and you have 5.3 or 5.21 and so on, just go ahead and install it. You can follow along and
nothing has changed. But for this course,
I'm going to install the newest
Unreal engine five. And then we are ready to
jump into the next lesson.
3. 1.03 Creating a New Project: Let's go ahead and launch
Unreal Engine Five. When Unreal Engine
five has launched, this window will appear, so you can see your
recent projects. And if you don't have
any recent projects, this one will be empty. But here you can see mine. And what we want to do,
we want to click on the Games tab because
we are creating games. But you can also see on
Real Engine Five can be used to make film and
video architecture, automotive and simulation
as well. Very cool. But for us, we're
going to create games. So I'm going to go
in the Games tab. In the Games tab,
you can see you can select between
different templates. For example, if you want to make a first person shooter
like we are doing, you can select the
first person template. If you want to make
a third person game, you can select this
one and so on. So you can see you can select between different
cool templates. However, all of these
templates can be done by you. You can actually create
a blank project, and you can build
everything from scratch and create all
of these templates. If you know what you're
doing for my courses, I'd like to start with a blank project
with nothing in it. Because I want to teach you how to build a
game from nothing. I don't like to start with
these templates here. And again, you can
create all of this from a blank project if you
know what you're doing. So let's start with
a blank project because I want to teach
you every single thing. Starting from a blank project, we are going to select Blueprint as our programming language. And the target platform
is desktop quality. Preset is set to maximum. As for the data content,
if you have this, I'm going to remove it so
we don't have anything. Again, I want to start
with nothing and then go ahead and select where you want to save the project. So I'm going to click
here and select a folder. And then go ahead and
give your project the name for this game. I'm just going to call it Counterstrike because it's
the type of game we're doing. We're not copying it 100% I'm also doing
some custom things. But it will be much more like counterstrike for this
multiplayer shooter. Go ahead, give it a name, and let's go ahead and
click on Create Project. Once the project
has been created, here we are inside
of Unreal Engine. Let's go ahead in the
next lesson and take a look at the overview
of Unreal Engine.
4. 1.04 Unreal Engine 5 Overview: Before we start
with our project, let's take a quick overview of how Unreal Engine is built Up. Here in the middle,
we have the viewport, and this is where you
see your game visually. In the viewport, you can hold
your right mouse button. When you hold your right
mouse button in the viewport, you can see you can look
around inside of the viewport. Now when you hold your right mouse button and you click on W, you move forward in the world. When you click on,
you move back, When you click on D,
you move to the right. And when you click on A,
you move to the left. Remember to hold the right
mouth button when you do this. So hold the right mouse button and the left mouse
button at the same time. Then you can see you
can actually move with your mouse alone, like this. You can also hold your
left mouse button alone and move it
forward and backward. And you can see you can
look like this as well. There are different moving
techniques inside of here. The next one is holding
the right mouse button, and then you can click
on to move down, or you can click on to move up. Of course, the last
thing here we have is if you scroll with
your mouse button, you can zoom in and
zoom out as well. These are all the moving
techniques, and that was it. The main one I use is I hold the right mouse button
and I click on S DNA. I just move around in
the world like this. I usually don't use
the other methods, this is the most
used one for me. So you can try to just hold the right mouse
button, click on, just try to navigate around, just have a feel
of what it feels like to move around
inside of this world. Over here, we have
different buttons inside of the viewboard, clicking up here, the
most important one is this one called
the game view. And this one hides
icons in the game. And this is useful for if you have so many
icons in the game. Remember when you build a game. So if you click on one of the
items that you have inside of the world and you just
click on your keyboard, actually take you to that item. You can see here if I click on, on my keyboard, this is the
shortcut for the game view. If I click on, I hide the icons. And this is very cool because
I want to see my game, what it looks like truly
without any icons. And you can click again
to show them here. The next one we have
is the immersive mode, and this will make your
Viewport full screen. Clicking on 11, that is
the shortcut for it. It makes the game
in full screen. And then I can click
on to hide the icons. And I can try to see
what my level looks like without being annoyed
by all of these icons. Click on again to show them clicking on 11 to
minimize the Viewpoard. Again, let's just jump over to these tools
very important. The first one is
called a Select tool. Clicking on this, you can select different items in the world. I don't use this too much, I actually use these three. I never select this, actually. If now that I'm
thinking about it, I never select this. However you might
find a use for it. But clicking on the
Q on the keyboard, you can see they have shortcuts if you hold the mouse over them. Clicking on Q, you
select the select tool, and clicking on W on the keyboard will
select the move tool. Selecting the move
tool, you can see if I select one of the icons, for example, I get these arrows. So you can see we
have a green arrow, we have a blue arrow and
a red arrow as well. With the move tool,
we can move items. And you can click on
one of the arrows. And you can move it
here on this axis. On this axis as well. And on this axis as well. Here to the right, you can see in the
details panel, it actually shows you details
about the selected item. If you select one of them, you can see it changes the
details about this item. For example, here if
I select this one and you can also see what
it's called in the Outliner. The Outliner basically shows you all of the items that you
have inside of this world, inside of this level
here that we have. This is what is inside of it. All of these
landscape things that you can see here is just
this world, you can see. It consists of blocks. When you select it, you can see it is also
selected here in the Outliner. When I select this
one in the view part, it is also selected
here in the Outliner. All of these things that
you can see here is actually something that
is inside of your world. When I select this, you can
see it's called the skylight. It's light from the sky. And you can see details
about the skylight, for example, how intense it is. For example, you
can increase it. Let's say I want to write three. And you can see my level is
more intense in lighting. And I can click here and click one again or
right one again, and then it is back to normal. You can change things here. What I wanted to
show you here with the move tool is
when you move it, you can see it is also changing the location in
the details panel. If I move it, you can see it's changing values in the z value here when I move it this way and also when
I move it this way. But for the pivot points, you can see the red one
is actually the X axis. You can see it by holding
the mouse over it. It says X. The green
one is the Y axis, and the blue one is the Z axis. We have the X axis, the Y axis. And the z axis. You can change the location
of them by doing this here. Or you can change the
location by writing a number. For example in the Z, I
can write 200 clicking Inter and it will move up to
the value of 200 in the Z. But you can do, instead
of writing a number, you can also click, click on the number and hold
the mouse and drag. Then you can see you can also change the location
like this as well. If you want to move it in
all directions at once, you can click on this
white ball in the middle. And you can move it in all
directions all at once. If you want to move it in two different directions at once, you can click on the
box in the middle. And you can move it in these two different
directions you have selected. Next, if you click on E on the
keyboard or click up here, simply you will get the
rotation tool, just as it says. You can click here
and rotate the item. Right now it's an icon, so we can't really see
what's happening. But if I click up here, this will add elements. Clicking up here,
going to Shapes, and I'm just going to
add a simple cube. Adding a simple cube, I
can now click on the cube, click E on the keyboard, or select the rotation tool, and I can just rotate this
item around different axis. Again, you can see the
values changing over here for the rotation, and
you can see it here. You can also rotate
it by clicking here, left clicking, and dragging. That will also rotate it. Then we have the
scale tool over here, and as it says it
scales the item. You can scale it in all of
these three directions. Or if you want it to scale uniformly in all
directions all at once, you can click on this
white box in the middle. And it will scale on
all of the directions, all at the same time
when you scale it. You can also see
the values here, how much we scaled it. If you want to reset it, you can actually write 111
that will reset the scale. However, you can also click
on this small arrow here. This will reset the values to default though clicking
on this small arrow, it will go back to default. Over here to the right, you have different snapping tools. You can see when I click on W on my keyboard to select
the move tool, I can move this item. But you can see it's
not moving smoothly. It's snapping to a grid. I can disable this by
clicking on the icon up here. And now I can move
it, and you can see it is now moving smoothly. If I click on it again,
I will enable it. You can also increase and decrease the amount
it is snapping with. If I click on the
number up here, and I can select, for example, 100, so it will snap a lot more. If I drag it now, you can
see it snaps a lot more. This is useful for when
you are, for example, doing level design
and you want items to place like in a pattern
beside each other. What you can do,
for example here, is you can hold Alt
on the keyboard. You can click and drag
while holding Alt. This will copy the item
if I just do it again. I click and I click
and drag again. I click, click and drag. You can see I can
copy the items. And they are now placed in the same distance
between each other. This is how the snapping
tool is useful. I'm just going to reset
it back to ten by normal. You can do this with the rotation and with
the sizing as well. You can see if I
click on to select the rotation tool and I
click on one of them, I rotate, You can see it rotates every ten degrees.
Again, it's up here. I can increase or decrease the amount
it is snapping with, or I can simply click on the icon and I can
rotate it now, freely without any snapping. I'm going to turn it back on. And you can do the same
thing with the scaling. Now over here, you can increase and decrease the camera speed. You can see right
now I am moving inside of my world like this. I can also move a lot slower. Imagine if you have to
focus small detail here, it's very hard to move the
camera to make it look here. What you can do, you
can click up here, increase the camera speed. Now you can move a lot
slower and focus on small, small details inside
of your level. However, if you want to move over to the other
side of the world, this will take forever. You can click up here,
increase the camera speed, and now you can move to the other side of
the world quickly. Again, if you want to move
to a specific element, you can always click on it here. For example, if I want to move, let's say to my directional
light, I can click on it. And I can click on my keyboard. And it will here as well. Now I can decrease
my camera speed again to one by default. And I can move normally
here, just like before. All right, so this was everything inside
of the Viewpoard. Again, the outliner basically shows what is inside
of your level, what you can see visually
here inside of the level. But for now, I'm going
to delete these cubes. So I'm going to click here, hit delete on my keyboard. And also select all of them. And hit Delete on my keyboard. Now up here in the tool bar, we can save the current
level we are in. We can also click here and use the different
tools we have. For example, if we want
to create a landscape, we can use the landscape tool
or foliage, for example. If you want to paint grass
and trees in your level, you can use that as well. However, we're not
going to use this inside of our game
because we are going to create a basic level and
we're also focusing a lot on blueprints and how
we can program our multiplayer first
person shooter. So if you want to focus on creating landscapes
and foliage, please check out
Pixel Helmet.com my website Here you
can find a lot of courses that will
explain this as well. Next over here, a very, very important button is you can add different
things to your level. For example, we created
the Shape, the cube here. You can also create lighting. The lighting that
you can see here, we will also create
from scratch. And you can create the different
lights inside of here. You can also create
visual effects and so on. So you can place
different elements to your level by
using this button. Next we have the
level blueprint. And we will be talking a lot
about blueprints later on, so let's not focus
about this for now. And then we have cinematics, and we will skip the
cinematics for now. Then we have the play button, and if you click on
it, you play the game. And then you can see I am now playing my game
inside of the level. Not much is happening because we don't really have
much inside of here. So I'm going to click on
Escape on my keyboard to exit the play mode by clicking
on these three buttons. You can also select how you
want to play your game. Right now we are playing it
inside of the Viewpoard. Also click here and
open up a new window. And it opened up in
my second screen, you can see now I'm playing
the game in my second window. I can click Escape to exit it. Again, you can select how
you want to play your game. I'm just going to select
their selected Viewpoard. Down here we have
multiplayer settings. We will be working
with that later on. Lastly, if you want to
package your game and release it on Steam or
release it to your friends, you can go ahead
and click up here, Windows for example, and then package the game to release it. Now up here we have
the different buttons. We have the File button, where you can create a new level, you can create a new
project and so on. Very basic in old software
that we have seen. And then in the edit,
the most important thing is the project Settings, and we will be using that a lot. You can see it has a
lot of buttons and it might look a bit confusing if you're new to general engine. However, let's just focus on the most important things
that we need to learn. And you can learn all
of this later on, but for now we are
going to focus on the most important things.
Let's skip it for now. And we will be going a lot
through this in the course. Then in Windows,
very, very cool, you can open different windows inside of our middle engine. For example, this viewport that you can see
here in the middle, you can go to Viewports, And then you can click
on Viewports two, and that will open
a second viewport. Now this is very cool if
you have two screens. I usually do this if I have a camera and I just look
at my game like this, I put it on my second screen
and I can work here as well while I have this view
of my game. So very cool. You can open up
multiple windows here. And it also goes for
the details panel if you want to open a
second Details panel. And you can see here if I
select something in my world, you can see it is
the same details that are displayed
inside of here. So very, very cool that you can open up multiple windows here. In tools, we don't
really have much, so let's skip it for now. In Build, the only
important button here is that you can build the level
and build the lighting. And it will make the
correct shadows and so on, but we will be working with this later when we do the lighting, and at the end we
have the help and you can view the documentation
here as well. Okay. The last thing
I want to go through before we finish here
is the content drawer. And click on the content
drawer down here. This is where all of the files
will be for real engines, for the game you're creating. For example, if you have
textures, if you have music, if you have three D models, all of these files
for your game, they will be down here
in the content drawer. What I like to do,
you can see if I click on the Viewpoard,
it will disappear. If I click here and click again, let's say I'm working
in the Viewpoard, it will disappear again. I find it a bit annoying. What I usually do is I click here and I click Duck in Layout. And it will stay here. And now it's called
the content browser. It is staying here on
my screen all the time. When I work on my game here on the viewpoint,
it never disappears. And it's also a lot nicer for
you to see for this course. Inside of the content browser, I can create folders. If you right click down here, you can create a new folder. For example, you
can give it a name, for example, hello or
something like that. You can also right click the folder and you
can set the color. You can set the
color of the folder. And this is very nice
if you want to stay organized here in
the content browser. Because you can imagine
if you have a large game, you have a lot of files inside of here in
the content browser, if you want to
create a new thing, you can right click over here. You can see on your right click, you can add different
elements to your game. The most important thing, we are going to work
with blueprints. So this one is very huge. And we can also create a
new level, a new material. If we have something
to do with animations, we will be working
with that as well. You can create
that, for example. You can click on one of them and you can see you
have different options. Right now, we don't really
have a skeleton, a player. So I'm going to close it
and create something new. For example, a material. And you can see here it is. If you want to make the
icons smaller or larger, you can click on the
settings and go to thumbnail size and
select a smaller size. Now what you can also do,
you can hold control on the keyboard and you can
use the mouse wheel. So if you zoom in with a mouse wheel while
holding control, because you can increase and
decrease the icons as well. Now I'm going to click on this one and hit
Delete on my keyboard. And just go ahead and
delete it for now. If you're right click again, you can see all of
these elements you can create and add to your game. Again, it looks very, very confusing if you have
never used it before, used on real engine, and
if this is new to you. But again, don't try to focus
on all of these things. Let's just focus on the
most important things and create them
during this course. And I promise you you will
learn all of this slowly. So don't focus on
everything for now. Now, you can also use this Add button as well,
but I never use this. I actually just go into
the folder I want to add something in and I'll
just write click over here. But the same thing, you can also click up here if you wish to. Okay, so that was it for
the Unreal Engine Overview. If you want a more in depth
overview of Unreal Engine, please visit my other courses. I have a complete
beginners guide as well. So with this said, let's just go ahead and
go to the next lesson.
5. 2.01 Game Introduction: Hello Ron. This is
me from the future. And this is the finished
project for this course. And I'm just going
to show you what we're going to do
inside of this course. It's a lot easier sometimes to see the finished product
before you continue. What we are going to do here is create an FPS game from scratch. And literally from scratch, we start with a blank project. And we do everything
from creating the map, the lighting,
importing the weapons, and doing the weapon
equipment and so on. And if I just click on Play here, and you can see the game. So we have some ambient
sound in the background. Some birds, you can
loot weapons here. You can loot this as well. You have it on your
back as you can see here on my shadow. But you can also see it here if I just spawn as another player. You can see it here on
the back of this player. And I can also switch weapons. I can shoot the weapon. There are different
sound effects for each weapon as well. You can also see we have
some effects on the ground. We have bullets calculating. We can reload the weapon. We can hit other
players as well. Yeah, we have health and armor and we have
also round points. We have a lot going on. We can drop weapons. The weapons have weight. And we also have Ragdoll
death and responding. And you also get a
notification when you win the round and lose
the round and so on. A lot of things going on
inside of this game here, but we will go
through it together. And trust me, it will be easy if you just follow
the course here. I'll teach you
everything you need to know to create an FPS game. The good thing about
blueprints is this course, if you follow it fully
and understand it, this course will teach you
not only to make FPS games, but also other games. Because when you
create other games, you're actually using
the same tools. Blueprints is just blueprints. And you just have
like these tools in a toolbox and you create
different things with them. In this case, we're going
to create an FPS game. I hope you'll have fun with me. Let's go ahead and continue, and don't waste any time, and I'll see you
on the next one.
6. 2.02 Creating a New Map: To create a new
map. Let's first go ahead and create a
new folder over here. I'm going to right click
on the content folder. I'm going to click
on New Folder, and let's call this one Maps. Then inside of here,
let's right click here. And let's go ahead and click
on Level for this level. Usually for maps I call them map as a prefix
because later on we can actually search for elements here and it will be
easier for us later on. So I usually give
my files prefixes. I call this one map and
let's just call it main. This is our main map. Now we can double
click this map. And now it asks us if we also want to save
this level here. And I'm just going
to remove this. I only want to save my new map And clicking
on Safe Selected. And now I am inside
of my new map. And you can see it's very
dark inside of here, and in the outliner
there is nothing. And it is dark because
there is no lighting. There are no assets
in our level yet, and we have to add them
in our next lessons.
7. 2.03 Importing Environment Assets: For the environment assets, we are going to use a pack
from the Marketplace. If you open up the
Epic Games Launcher, and inside of here you click on the Marketplace tab When you're inside of
the Marketplace. Marketplace has a lot of cool items that you
can use for your game. You can also see they
have free for the month. It's worth taking a look at, but for now in the products, let's search for grid. If you just write Grid
here and you press Enter, and then over here in the max
price, you click on Free. And then you see this one called Super Grid Start up Pack. This is what we
are going to use. So if you click on
it and then it will say download here if you
haven't downloaded it yet. And when you
download this asset, you can create a project. You can click on this button
called Create Project. And then you have to select
where you want to save it and just go ahead
and click on Create. You can also select what version you want
to create it for. Right now it is
set to 5.1. It is. Okay, you don't need a version
5.1 in order to use this, but it is just going to create the latest version
of Honual engine. You don't need to
have it downloaded to use it, so that is okay. I already created it. So if I go back to my library, this is where, like if you create it, it
will appear here. This is the super grit
Stata pack or Unreal Engine 5.1 I'm going to double click
it to open it up Again, you don't need Unreal
Engine 5.1 to open it. You can actually open it with 5.2 or whichever
version you are using. And here it is, it opens
up. You have to wait. If this is the first
time you open it, it has to prepare the shaders. It might take a lot of time when you open
it the first time, sometimes half an hour,
sometimes an hour. But then when it is ready, you can now use the SS here. In order to use assets
from one project to another, you have to migrate files. The way you do this
is you can write, click this super Grid folder, and then you can go
ahead and click on Migrate, and click on Okay. And then you have
to select where do you want to save this file? And I want to save it
inside of my other project. Here I made it in this
multiplier shooter folder and in Counter Strike. And then you have to select the content folder for your
Unreal Engine project. Remember, you have to
select the content folder, You can't save this
in other folders, select the content folder, and also you can't select another folder inside
of the content folder. When you migrate things from
one project to another, you have to select the content folder and just go ahead and click
on Select Folder. And then it will migrate all
of the files that are here, and now it is finished. So I can close this
supergrid down. And if I open up my project, you can see now I have this
Supergrid folder and I can use the assets inside
of here now in my game. Now, before we finish, I'm going to open up the
Epic Games launcher again, because we need something else. Before we continue, I'm going to go ahead and
open up the marketplace. And for the lighting, we
need a Sky over here. If I just search for Sky
again, I click on free. Inside of here, I'm going to use this one called Good Sky. If you click on it again, you can click on Download if you haven't downloaded it yet, and then you can click
on Add To Project, and then you have to
find your project. You can see here, if I go back, it is only available
for 5.1 Currently, I am using 5.2 What you have to do is click
on Ad To Project, and then click on
Show All Projects. And then I can click on my
Counter Strike Project. And then I have to select
the version or the Pac. I'm going to click
here and I'm going to select the latest version
that it is compatible with. It is okay, it's
not going to bug. It is going to work just fine. I'm going to click
on Add To Project, and it will add it
to my project here. So now if I go back
to my project, you can see the good
sky has been added to my project and I
can use it as well. So now that we have imported
the environment assets, let's go ahead in
the next lesson and design the environment.
8. 2.04 Designing the Environment: In order to design
the environment. Right now you can
see the level is dark and it is impossible
to do anything if I go to the super grid and
start a pack and then I go to Source and you can see
we have the meshes folder, for example, if I drag
this box inside of here, you can see it is dark and
we can't see anything. If I click on the
unlit mode over here, changing the lit mode to unlit, now I can see it because we don't really
have lighting and we can't see things when
we are in the lit mode. So I actually don't
like it too much to design in the unlit
mode. You can do that. Of course, you can try to just design the
whole level in lit, because after that, we are
going to add lighting. However, if you wish to
design it in the lit mode, you can just go ahead
and click up here. And go to Lights And add a directional light
just for now. And you can always
change it later. Remember, if you increase the size of this
box, for example, and you think the
sunlight is too bright, you can click on it and you can click on E to take
the rotation tool. And you can always
rotate it around, try to see if you can
get a good angle. And you can also decrease the intensity here
and work from there. But right now, this
is just temporary. We are just going to
design the level, and after that we are
doing the lighting. But I just want to
add this one so I can design my level in
the lit mode as well. All right, so right now I'm just going to delete this box again. And what we are going
to do is we are going to design something like
this for counterstrike. So this is called a map. A map is basically, you have two sides of this map. So the counter
terrorist spawns on one side and the terrorist
will spawn on the other. And there are weapons
they can pick up and they can shoot
each other like that. Just a very, very simple
map and we're just going to design something
like that naturally, a fully copy paste, but something that we
think looks good for now. Let's start with dragging this supercrit plane
into the level. What I like to do
is I like to place it at the location of 000, so the center of the world. And I usually like
to start from here. Very cool. For these assets, you can click on Art to
take the scale tool, and then you can scale them on these different directions. And you can see it creates the plane like that and it creates a level for
you. Very cool. You can scale it on both axes
and then create the ground for the game to
make it easier so you don't have to scale a lot. What you can do is
you can click up here having it scaled
like this first, so that having showing
this box fully. Then you can click up here
for the scaling tool up here. And maybe selecting the scale snap to one, setting it to one. Now if I scale it
this direction, you can see it
scales a whole box, one I scale once.
This is very cool. Instead of doing it
a lot of times now, what you can do
is just scale one time and it creates
that box for you. You can see how
useful it is to use snapping as well for the
level when I scale it. You can see it also scales
here in my Details panel. You can see the numbers go up. You can either scale it this way or you can
scale it this way. Let me actually just
scale it this way. Here you can imagine
if you go down here, this is where the
player is standing. If you want to see how
large this map is, you can also click up here
in the quickly at button two Basics and add a player
starts this player start, I am going to take it
down to the ground first. Something like that.
It will say bad size. If it is inside of the ground, I'm going to move it up.
Something like that. The character is in the size of this Players start almost. This is just a
reference. Now you can see this level
is very small. This is not what
we're going with. We need it to be a lot larger. So I'm going to
click on this plane. I'm going to write 80 for
the x and 80 for the Y. Now I'm going to try to
build this map on here. Of course, for this course, you can always make it smaller. It doesn't matter
what you design. Go ahead and design
your own level again, it doesn't matter what
you design at this stage. Later on, we are
doing the programming with whatever map you design. Just go ahead and
be creative and design your own thing
and have fun with it. When we have created the ground, what you can do is you can
take this box for example. You can place it
here on the ground. And then I'm going to
move it so it snaps here to the edges of
the ground again. For the snapping,
having it put to one, I can now scale it, and
this is just my wall. We're going to scale it all
the way to the other side, just like that, until it
has finished over here. Then what you can do is
you can also scale it upwards to make a wall
something like this. At the scale of 20
for the height. We can always change it later. If we think this is too
small or this is too large. What I can do is I'm actually going to move
it one step here, over here on this box, because I want to have the
other wall here as well. What we can do now
with this wall is I actually want to decrease
the size as well here, now it's outside, decreasing the size by one. Just like that. Now what I can do is
I can hold Alt on my keyboard and I can
rotate while holding Alt. And this will copy the model holding Alt while you rotate. This will copy it. And now I can drag this model
over to this size. I'm just going to
increase my camera speed slightly so I can see
what's happening. And I'm going to go to the unlit mode because now you can see, it's actually difficult to see. And I'm going to move
it just like that. Just snapping it together. Just make sure they
are snapped together. Checking here to
see if everything is good. Everything is good. Again, I'm going to click on E old and then drag to copy it. Not like that. I'm going to
click Control Z, hold Alt. Click and drag to copy it, and then drag it over here
and then snapping it. Maybe it's a lot easier also
to increase this snapping. It's better to control. You can see here, you don't have to move it a lot
before it snaps. This will make it a
lot easier for you. I'm going to do the
same thing here, dragging it to this side, making sure it is
snapping with this wall. Also, making sure that
it looks good over here. Now you can see I have a wall. If I now go to the Lit mode, I can click on this
directional light. I can rotate it slightly. I can see my level. And I can also decrease
the intensity, so it's not that intense. Now we have this level
with the walls. All right? So I want you to design
this level as you wish. You can always place cubes here. You can try to resize them, make some like walls
for the player, so the player is standing here and shooting
the other players. You can try to make cubes,
something like this. You can hold Alt
and drag while you hold Alt to copy it and
maybe place it like this. You can even copy it again. And you can place it beside this one, something like this. And you can also
increase the size, make something like
this interesting. You can always try to make
interesting models as well. You can see here, you can
use all of these assets. You can use ramps as well. You can try to drag this
ramp and you can increase the size of the ramp and the
size of the slope as well. Like this And this way see you can also make
ramps on this level. Try to be very creative
and just design a random level that we can
use to program the game. Now with that said, if
you're not really interested in designing the level and you just want to get started
with blueprints, I have also included
the project for you where the level has been
designed without any code. You can also use that
as well if you wish to. It is really good practice to also design your own levels. Imagine when you're making your own game later
at this stage, you know how to design
your level as well. So I do recommend
just going ahead and have fun with this.
Just design the level. Use maybe an hour or 30 minutes
and then come back here. All right, here I am again. I am back and I have
designed the level. I spent a couple of hours
to just design something interesting and make it look cool when we are
programming the project. Again, I have included
this for you, so you can use it
without any code. So if you don't want to design, here it is, you can use it. However, again, I suggest
that you go ahead, just have fun and design something random
that we can use. You can see here I made a new
folder called marketplace. And inside of here I dragged in the good sky and the
super grid as well. They are here and it is
a bit more organized. As for the level, I'm actually
going to change it to unlit mode to show it to you because the lighting is a
bit annoying right now. Inside of here, you can
see what I have done. For example, I have just
put the boxes together. I was just trying to add some interesting shapes to
this level, the size for it. Again, the ground is still 80 by 80 like we made it before, and the walls are still 20
by 79, just like before. You can see here
all these boxes, they consist of different boxes. You can see this box here added with this box. Again,
just like before. I just used the scaling
tool to scale them up and down and just trying to make interesting shapes for this one. This is the super grid ring. If you click on it, for example, if you click on it here, you can click on this small icon. It will actually take you to the model in
the content browser. So this is the
easy way to do it, and this is the one I have used inside of the
meshes folder. I have also made this ramp. So you can see here I
designed like a ramp. You can go up at here making this ramp and making this wall beside it to
enclose this ramp here. You can see how I made it this ground to just have
some ground here. And this ground as well
beneath this ramp. It's just two ramps
put together and some ground here between them. Just a couple of
walls put together. You can see I spent
some time just to build an interesting level. These are just boxes
you can put together. You can also use these shapes. If you click on this icon, it will take it to you
and it's these cylinders you can place and
then you can scale. Then what you can
do is you can use these ones to put on top of it. You can scale them down
to make them look good. Maybe just take out the
snapping here or just reduce it to something like 0.125
or something like that. And just decrease it and
try to copy paste it all around to make that
interesting shape up here. Okay, but that is what I have
done to design this level. Again, you can download
it if you wish to. I have included it for you. With that finished, remember
to go up here as well. What you can do in the outliner, you can select all of these
that you have designed. And what you can do is you
can select all of them. So click on the first one, hold Shift, and click
on the last one. And then you can click on this folder icon to
make a new folder. And click on two on your keyboard to give
that folder a name. And it will stay
organized like that. Remember, it is
always nice to stay organized down here in
the content browser. Stay organized as well
here in the Outliner. Now, with this level designed, let's go back to the lit mode. And now we are ready
to do the lighting. However, you can see
it is very bright. And when I go to the
directional light and I change it
to something like 0.2 you can see the lighting keeps changing
and it keeps getting bright. So we have to add a
post process volume before we can continue. So let's go over to
the next lesson.
9. 2.05 Post Process Volume: The post process
volume inside of Unreal Engine is
something we can use to change the
image of the game. Just like you can
think of Photoshop, where you add an image to Photoshop and you change
the colors of that image. This is the same thing
here in Unreal Engine, we use a post process volume. That volume can change
the warmth of the level, we can change the color, the saturation, the Bloom
lens flares, and so on. So what we can do
is we can click up here and you can find it in either visual effects and you can see it's called
post process volume. Or you can go to
volumes and then go ahead and create a
post process volume. Two ways to create it. So go ahead and click on it. And if I click on, on my
keyboard to show the icons, you can see this box
here that we created. This is the post process volume. Now inside of here, if
you click on one of them, for example, the Bloom, and you click on the intensity. And let's just increase it to something insane, like five. You can see nothing
really happened, if I said it to one, if I said it to five,
nothing happens. This is because you have to go inside of this post
process volume. You can see if I move
my camera inside of it, the bloom takes effect. If I go outside of this box, you can see the bloom
doesn't take effect, so I have to be inside of this
box for it to take effect. In order to apply this
to the whole level without going in and
out of this box. You can go down here and you can tick the one called
infinite extent. You can tick it and now you can see it applies to
the whole level. What infinite extent does? It just applies it to
the whole level so you don't have to go inside
and outside of the box. Now, what is the use of
it here, for this box? It is, for example, if
you have a dungeon, or let's say I want to go
inside of this building here and I want to change
color. This is what you can do. You can move it, for example, inside of this building. You can move it up here. And
you can even scale it up. You can see if I
move it up here, I can take the scale tool, clicking on R to
take the scale tool, and then I can scale
it on the X, Y, and Z. Just trying to fill in the area I actually
want it to take effect. Let's say for example, I
want it to take effect here. When I move in, when I
move into this dungeon, you can see the bloom, the bloom increases,
now it takes effect. This is the use of it for
not using infinite extent. For example, if you
have an RPG game, you have Dungeons and
you want to change color whenever you are
inside of that dungeon. However, we don't really
have something like that. I want it to apply
to the whole level, so I'm going to click
on Infinite Extent. I'm going to go to
the top, and I'm also going for the scale. I'm going to press on this
button to go back to default. Not really that it matters, but I just wanted to have it default like this,
as you can see here. For example, for
the temperature, you can increase or decrease the temperature and you can change the color of this world. Even the tint, you can increase
and decrease the tint. You can see the
post process volume is just like in Photoshop. You can change the
look of this game. I'm going to click
on these arrows, set them back to
default for now. We're not really going to
play much with it for now. What I want to do is
you can see here, if I remove this intensity
for the Bloom, I click here. You can see for the
sunlight, if I put it to, let's say five very intense, you can see it changes the
light. This is the exposure. If I put it to 0.2
you can see it starts by being dark and then it
increases in lighting. I don't want to do that
because we are creating games, and in games we don't
really do things like that. It is always nice to stay at one lighting when
you are doing lighting. Let's go over to the
post process volume and click on Exposure here. Let's click on the
minimum and maximum EV and set this to one. And set this one to one as well. Now you can see if I click
on the directional light and I set the intensity to
something like three. And now you can see if I
go close, if I go away, if I look at different things, you can see it's
not really changing the light and it
is being static. And this is what
we want for games. Let's go over to the post
process volume for the Bloom. For now, I'm going to click on the Intensity and
set it to zero. It's always nice to have
it to zero to begin with. When you are doing lighting, we don't affect the
lighting by other factors, so the Bloom set it to zero. Also down here,
the image effect, we have something
called a vignette. And a vignette is you can see if I click on it and
you increase it, it creates that dark
bota around your screen. If I just increase the
intensity of the direction, light so you can
see what I mean. If I set it to ten and now clicking on the
post process volume, you can increase and decrease the vignette. Just like that. This is just a cinematic
albot around your image. And I don't want to do
that to begin with. I don't want it to
affect my lighting. Let's put it to zero. You can see if I don't tick it, it's 0.4 by default, you can see it's
actually applied. If I untick it, remember to ticket and set it to zero,
that will remove it. If I go down here just to
make sure there's anything else for the motion blur. People usually don't like motion blur in first
person shoter games. I'm going to click on the amount and set this 120 as well. And with that done, now we are actually ready to do lighting. You can see nothing
is now affecting our lighting When we do the
lighting and see the results, nothing is changing lighting. And you can see when I
move back and forth, the light stays the same. And this is what we want. So let's go ahead
and click on File. And let's click on Save All. And also here in the
post process volume, what you can do is you can click on it, Create a new folder. And let's just click here, click two and call
this one Post Process. Here is the post process volume, and now we are ready
to do the lighting.
10. 2.06 Lighting the Environment: We are now ready to
do the lighting. So what we can do is I'm going to delete this
directional light. Because now we are ready to
start from scratch, okay? The way I do the lighting
is I go up here, go to lights, and first we
add a directional light. So this is our sunlight. And I usually add all of the lights before I
start adjusting them. So here's the sunlight. And clicking over here,
go to lights again. And let's add this one
called a skylight. The skylight is light
coming from the sky, which as you can see here,
it's really dark right now. What we can do is here in
the Marketplace folder, I can click on the Good
Sky we added earlier, and then click on
Blueprint folder. And this Good Sky, you can click and drag it
into the level. And when you place it, you can see that it is inside of here. Again, I want to
make it daytime, but for now I'm not really
going to adjust anything. Then what we can do is
we can click up here. We also have another light, but it is not inside of lights. It is inside of visual effects and it is the sky atmosphere. You can click on that one and then clicking on
this one up here. Going to Visual
Effects again and click on this one called
Sphere Reflection Capture. It's going to capture the reflections inside
of your level. For this one, I'm
actually going to drag it down maybe 2000. And let me just drag it into
the middle of the level. Naturally precise,
it doesn't matter. I'm going to increase this influence radius
to encapsule my level. You can see now it is
encapsuling my level. And it's going to add
reflections around my level. Now up here, you can click again and go to visual effects, actually not visual
effects in the volumes. And we have this one called a light mass importance
volume. Click on that one. Map Importance Volume
is it just tells the engine what is important that you need
to render light on. We need to encapsulgain our
level and tell the engine, this area is really
important for the lighting. Let's do that. Let's place it somewhere here in the middle. Again, it doesn't really matter. I'm going to click or set it
here for the brush settings. You can see in the X. You can click and drag to increase it. You're increasing this box
to encapsul your level. Again, you don't
really need to be precise, just encapsul level. And I'm going to do
that for the Y as well. I'm going to do that
for the Z Xs as well. I'm going to move down here
just to see if it encapsules. And we don't really
need it to be that much here down here. I'm going to increase
it slightly. Actually decrease it
a bit just to make sure that the ground
is here with it. And I'm also making sure that the walls up here are
here with it as well. Again, don't need to be precise, just make sure that it
encapsuls the level. Now we have the
direction, light, the good sky, the
sky, atmosphere, the skylight, the
sphere reflection, and the light mass
inside of our level. What I'm going to do is I'm
going to select all of them. Click on here for this folder, let's call it lighting. And now we are ready to adjust
the lighting for our game. What I usually start
with is I click on the directional light,
which is the sunlight. And what you can do is
you can click on E on the keyboard to select
the rotation tool. And then you can try
to rotate the sun. So you can give it some
nice interesting shadows. This is what you're trying
to do to begin with, just give it some
interesting shadows. You can just rotate it, see where the shadows
are interesting. You can also remove the
snapping clicking up here. And then you can rotate
it freely and just try to put in some interesting
shadows for your game. For me, I'm going to try to rotate it to
something like this. Maybe I'm also
rotating it this way. So it actually casts
shadow this way. And I can always try to
adjust it later on as well. So right now you can see the
shadows are really dark. And I want to change it a bit
so it is easier for me to try to find some
interesting shadows just making it a bit brighter. Clicking on this good sky, I'm actually going
to go up here, and for the time of the day, I'm actually going to change
this one, so it's not stars. I'm going to write 12
in the time of the day. And now you can
see it's daylight. And you can click on
the skylight, go down, click on Recapture
to capture the sky. You can see some colors actually changed here and
it's getting brighter. You can also change the skylight intensity here to make it like five or
something like that. Really crazy right now. But just to find
some interesting shadows that you can work with now, I have rotated in my sun and I am happy with my shadows. Again, I'm going to go to
the skylight and actually click on this arrow and set
it back to one for now. Now that we have the sky, I'm actually going to start
with the good sky. Now click on the Good Sky. For these presets, what I'm
going to do is you can see, you can click on
them and change them here for the style
of the clouds. Again, this is optional, but I'm going to click on
it and select this Cloud B. This is the style of the clouds, for the cloud coverage, I'm going to select Middle. And these are the settings
for the good sky. Not really much to change here. Just to make sure, I'm going to click on the skylight again, go down, click on Recapture, just to make sure
it has the correct Lighting from the
sky. And I'm going to click on Build and
Build all Levels. And this will ensure
that the lighting is actually looking correct.
So go ahead and do that. This will take some time if this is the first
time you're doing it. And you can see the progress here when it is
building the lighting. But as you can see, it will probably take a couple
of seconds for me. Now, when you're finished
building the lighting, it will show you the progress. It's looking just like
before. All right. You can see here if I click
on the skylight now and I increase the intensity of the skylight to
something like three, you can see the shadows
become lighter. And this is what the
skylight is used for. It makes the shadows brighter. If you have the shadows
very dark in your game, you can always increase this in order for your shadows
to become brighter. And it looks a lot
better than before. However, this is actually
usually not this dark. If I have it at
the scale of two, it's not supposed
to be this dark. And also if you look
inside of here, there is something
else going on. This is lumen, the
new lighting system. If you click on this
post process for now, I'm going to minimize
this exposure. If you just go down here
and you find Lumen here, you can see global illumination. Lumen, you can click on it
here and here in the Lumin, global illumination, you
can click on this max distance for this one. If you write zero, you can see it is a lot
brighter than before. If you click on this arrow
to go back to normal, you can see everything
is so dark. And if I write zero again, it is a lot brighter. There is something going
on with this as well. I'm actually going to reduce
it slightly for this one. You can see if you write
100, looks like this. If you write 200, 300, 400500600700900, it begins
to become very dark. I'm actually going to write 700. You can try to
balance it right now, it looks a lot flat, so I'm not going
to go with this. 1 Lumen is really nice and
it gives nice effects and you will see that later when the lighting is looking good, so I don't want it
to look this flat. It is really nice
to have lumen in your scene because the lighting
will get so much better. Instead of removing it all, and let's put it to 200, 300, try to increase
it slightly, but it is still
flat on the ground. I'll keep increasing by 100
until I can see some detail. Now I can actually see
some detail here here. What if I write 700
instead of 600? And this is what it looks like. If I write 800, this will become
really dark here. I'm going to go with
700 with this one, we can always change it later. Okay? So you can
see the difference. If I click here, it
looks like this. If I write 700, it looks a lot
lighter than before. Now you can click on the
skylight and you can increase it slightly
so it's not this dark. For the skylight
right now, it's two. You can write 34, maybe something
like four for now, okay, Maybe something like four. And you can already see it looks a lot
better than before. Before it was one by
default and now it is four. And you can see the
difference here. I'll keep adjusting the
lighting until I'm satisfied. In first person shooters, it's really nice to have corners that are dark because people want
to see each other, they want to shoot each other. And it's not nice to have a dark corner where you
can't see the enemy. Something like this, it
will be really annoying. Let's write four in the
intensity scale here. What I'm going to do also, you can click on the
directional light and you can increase the indirect
lighting intensity. And what that does,
it just bounces some lights on the walls and
it will look a lot better. If you increase it, you
can see the difference. Actually see the
difference here. If I write zero or one like before and if I write
six, you can see the, these walls here are bouncing
light on top of each other. And the environment looks
so much better than before. If right one, right six, you can see the different
on this wall as well. All right, so what I
want to do now is I want to balance the shadows
versus the lighting. So it looks correct.
Before I do this. Now if you click on the
skylight and then you click on this Advanced here in the lighting here
in the skylight, you click on Advanced, you can see something called
a lower hemisphere color. What this is, it
bounces light from the ground to these
walls and environment. Here you can see if
I click on it and I put the light or the
color to something extreme, you can see it is actually
bouncing light from the ground up on
these walls here. Now it is currently black and it doesn't
really make sense because we're not really bouncing
black light on the walls here. To make it more realistic, we have to change the color
to something more correct. Right now, my ground is gray. What you can do here is you can click on the Lit mode up here, you can go to Buffer
Visualization, and then you can
go to Base Color. Now you can see the true
base color of your ground. What you can do, you
can click on it, take the color picker, and then you can select
the color of the ground. I'm going to select
this gray one here. And I'm going to
go back to my sky. If I minimize this,
go to the skylight. Now you can see we have changed the lower hemisphere color. Now if I go back to
the lit mode and I go down and remember
to click on recapture. Because you have to
recapture the lighting. Now it is bouncing
the correct lighting here on these walls. All right, let me
just zoom in here. And I want now to balance the balance between the
shadow and the light. Now if you click on
the directional light and you change the
intensity here, this will increase and
decrease the amount of light. If you go to the skylight
and increase and decrease the amount or
the intensity here, it will increase and decrease
how dark these shadows are. I will start by clicking
on the directional light, and I'm going to
increase the intensity and maybe something like seven. Now if I go over to
the skylight again, you can start with one
and then write 23. You can try to increase
it slightly just to see what it looks like until
you are satisfied, right? I have played around with the intensity for the skylight
and directional light. For the directional light, I put it to six, actually, I'm going to put it
to seven to make it not look like night time. Putting this to seven
for the skylight, I just put it to five again. I just increased it here slightly until I'm satisfied
when I increase it to six. I think it was a bit too bright, so I reduced five. And we can always
change it later. It's not a problem,
but right now, I think it looks nice. We can see what the shadows look like compared
to the lighting. And just comparing it
to the sky as well. Look and see if everything
looks realistic. Take a look inside
of this tunnel to see if everything
is looking good. I don't want it to look very
dark as you can see here. If you click on the post process volume and you go down again to the lumen and for
the max trace distance, if you put it back to 2000, you can see how much it
affects the lighting. It really makes everything dark and you have to
decrease this again. You can write 100 to
see what it looks like, but right now it's really
flat on the ground. If I write 200, 300, 400, you can see it's still looking a lot
flat on the ground. And if we keep
increasing this number, at some point it's going
to look a bit too dark. So I'm going to, again, set it back to 700. And I really like this number, so I'm going to stay here. But this is how I
usually do the lighting. I first try to go to
the directional light. Try to find nice shadows
by rotating the sunlight. And then I'm going to here in the skylight again,
just like before. Click the advanced
button for the light. Go down to the lower hemisphere and change the color
to the ground, so it costs correct lighting
and also for the good sky. We changed a bit
of settings here. Now you can see if I look on
this part and I move away, you can see that all of
a sudden it disappears, the red reflection here. If I move close, you can see it appears
if I move away, you can see there's a bit of a change in the
lighting here. What you can do here
is you can actually play with the lumen distance. You can go back to the
post process volume and you can go down here. And we have something
called Lumen Scene Detail. If you click on the
Lumen Scene Detail, if you click on the Lit mode and then you go to Lumen
and Lumen scene. So in the Lumen scene
you can actually see where Lumen is affecting Lumen. Again is the new
lighting system in Ural engine makes everything
look really nice. Let's take this as an example. If this gets black, you can
see if I move away from it. This means that lumen is not working on this
mesh right now. If I get closer, it will work. This is supposed to
happen because we don't want to have
lumen work all the time because
at some point you don't really need it because
you're too far away. And we don't really need to put heavy performance
on the game. What we can do here in order
to make it work a bit more. You can see if I stand here, I actually wanted to work on some of these models as well. I don't want it to
be this extreme for the Slumencene detail. You can increase it slightly. If you increase it a lot, it's going to work on everything even though you're far away. If you increase it, it's going to take
away some detail. This one by default is, you can see here,
if you increase it, it's going to increase
on the GPU cost. I don't want to
increase this too much, but you can increase
it slightly. I'm going to click
and drag just to increase it slightly until this appear something like 1.2
This is a nice change. You can see it looks like
this when I put it to one, when I put it to 1.2. Also gets the loom in detail
a lot quicker than before. You can see when
we had it to one, at this point it was off. If I put it to 1.2 it is on. If I go back to the lit mode, it is a lot better now. All right, so before
we finish off, let's first click on Build
and Build all levels. And just make sure
that everything is looking correct with the
lighting and the shadows. It's going again to
take some time to build and I'll be back after it
has built the lighting. All right. So now
it has finished building the lighting and
everything is looking good. Now, sometimes for some people the lighting look different. And this is because it
can be because you have to go to the settings
and engine scalability. And right now you can see I am looking at everything
in Epic graphics. And this is because I
have a quick computer. But if you have a slow computer, you might want to use medium for example, or low equality. But low, you can't
see the shadows, but you can use those as well. If you have a slower computer, however, I have a quick one. I'm going to go
with the Epic one. You can always change it later when you are
exporting the game. But Epic is usually
really heavy, so you might want
to go with high for your computer if
it's a bit slower. But as you can see,
this engine scalability also affects the lighting, so you can check that as well. Okay, now for the last step, I'm going to click on
this post process volume. Now what we can do is we can actually change the
colors a little bit. So we can click on
this temperature and you can tick it here. This temperature slighter
and also this tint. So I'm going to reduce
the temperature slightly, so it becomes a bit more bluish. Something like maybe 6,200
very, very slight difference. You can see if I tick it and untick it, this is
what it looks like. Just a slight difference. It makes everything
look a bit colder, more blue then for the
tint, if you increase it, you can see it looks a bit more orangy, some warmth to it. Now, I don't want it
to be this extreme. So if you rise 0.1 you can
see what it looks like and you can tick it and
untick it. The change. However, I think this might
be a bit too much so far. I 0.05 instead NFI
ticket and ticket. This is what it looks like. Okay? So just a very slight
change in the colors. All right, so the last
thing I want to do here, you can see in the
global settings, you can also change things. For example, the saturation. If your game is too desaturated, you can increase
the saturation and everything will become
a lot more saturated. Now you don't have to increase
the setting way too much. For example, you can
put it at 1.1 and there's a slight
saturation on your game. You can see it gives
it a bit more color. However, I'm just going
to stay with one for now. You can also increase the gain
if your game is too dark, so you can increase the gain. All of the game will be a
lot brighter than before. Now for me, I'm going to stay on one for
this one as well. I don't need to
change anything here. What I want to change is I think surfaces are a bit too bright and this is
actually the highlight. If you go to Highlights
up here and you click on, for example, the gain. And you can see here, if you increase and decrease the gain, you increase and decrease
the colors up here. If you just put it to zero, you can actually see
what it affects. This is the
highlight. It affects the highlight up on
top of these models, 5.21 I think this is a bit too bright and
annoying to look at. What you can do is
decrease it slightly, so it's not that bright. And annoying to look at
maybe something like 0.60 0.56 And you can see if you write one,
this is what it looked like. And if I write 0.6 this
is what it looks like. Now I think this looks a
bit better than before, because before it was a
bit too bright on the ice, and writing 0.6 helps
fix that problem. This is what we have
currently inside of a level. Now, for this one, we
can add some bloom. And I'm actually going to add a bit of bloom
here for my level. This is now preference. You can also not add
bloom to your level. Some people don't like bloom inside of first person shores. But for me, I'm just going
to increase it slightly so you can just increase it
and see what it looks like. If you write one, this
is what it looks like. It gives it that dreamy effect. If you write 01, I think one is too extreme. If I put it to 0.6
and you can try to write 00.6 to
see the difference. I think something like
0.6 is the way to go. Not more than that, else it
will be a bit more annoying. Now we can see what it
looks like in here. The lighting looks really good. You can see how it costs
on top of the swells here, and you can also see it
outside of here as well. Try to look inside of here, make sure nothing is dark. You can see the enemy
if I go inside of here. Now if you think this
tunnel is a bit too dark, you can always go inside
of here and click up here. Go to lights, click
on point light, and create a point light here. And you can always place it somewhere here inside
of this tunnel. For this point light,
you can increase and decrease the intensity and
see what it looks like. Now it is a bit too bright
here on this specific area. And I want to smooth it out
because as you can see here, we don't really
have a bulb light. So it will look a bit weird that this lighting
is so bright here. So what you can do is I'm actually going to
decrease the intensity. I'm going to click on Advanced, and here use Inverse
squared Fall off. I'm actually going
to disable it here. Now you can see when you increase and decrease
the lighting, you can now increase
the intensity to be way more than before. You can also decrease
this falloff intensity. And you can see it
lights a bit more on the environment instead of just focusing on this specific area. Now if I go ahead and again
click on the point light. And I'm just going
to let it be here at two for the light
fall off exponent. Then I'm going to decrease the intensity to something
like you can see, it's very, very bright now because
we have disabled, we have put down the light
fall off exponent and we also disabled this
one for the intensity. If you just write
one for example, you can see the difference
if you tuggle it on and off. Just a slight effect
to make sure that we don't have any dark spots
inside of our level. Now you can play around with
the accentuation radius. If you click on, you can
see where it affects. So if you increase and decrease the accentuation radius,
this is what it looks like. I'm just going to put it
to something like 2000, maybe, something like this. If you click on, you can move
it around just like that. Try to place it somewhere
really nice where you don't really see that there is a bulb light inside of here. And try also to play
with the intensity. I think this is way too bright, so if I put it to 0.5 so
it's not too noticeable. And you can click on this
eye to hide it and show it. And you can see
what it looks like, just a slight effect. But you can see
here, if the enemy is standing here
and looking at you, you can see there is
a bit more light. And it's always easier
to see the enemy. And that is nicer to look at. Now, just try to move around the light now that you're
finished placing it. And try to place it in an area where it
makes sense for you. I think summer
light here is nice. I'm going to do the
same thing here. I'm going to hold Alt and
click and drag to copy it. I'm going to place it here
inside of this tunnel as well. Try to place it somewhere
in the middle here. And then I'm going to move
it in this direction. I'm just going to
take a look and see how it is affecting
somewhere like here. It's the same thing
as what you did over here for this
lighting as well. This lighting, it is
in the middle as well. Just making sure
it's in the middle and it is placed here. For the other one,
I'm going to push it slightly just so it looks
like the other light as well. Now that we have placed
the custom light just to make it look a bit
brighter inside of here, I think we are done
with the lighting and this is what the
level looks like now.
11. 2.07 Environment Optimization Tips: Before we can call this
environment finished, we have to take a look at
the optimization as well and make sure that it runs nicely as a game
when we release it. In order to take a look
at the optimization, let's click on the
lid mode up here. Let's go to the
optimization view modes and let's start with this one
called Light Complexity. For the light complexity,
we are basically, as the name says, taking a look at how complex
the lighting is. As you can see here, we
have a gradient here, starting from the dark and blue, and then it goes all
the way up to red, purple, and white. Now if you
are down here at the blue, this is very good performance. If you're out here in
the purple and white, this is heavy performance and
this is bad for your game. But as you can see, our
level is fully blue. And you can see
it's around here. And it's really nicely
optimized lighting wise. This is because we're actually
not using so many lights. We only have the
directional light and then we have the sky light. They are lighting this mainly as you can see, if I go back, if I turn off the
directional light and if I turn off the skylight, you can see
everything gets dark. It's basically actually these two that's lighting
the environment. Now if I go back to
the light complexity area is green. This is because
we added the light bulbs. Remember we clicked up
here in the lights and added a point light.
This is why it's green. This one is more heavy on the performance
compared to this area. However, this is still
low performance. This is really nice. This
is good for your game. You're still in the good area. If I take one of the light
bulbs and this one here, if I take this icon,
this point light, if I hold Alt and
drag to copy it, you can see if I copy it
and I place it outside of these other point lights,
it is good to go. However, if I begin to overlap lights, as
you can see here, it becomes red now. And in the orange area. Now, let's say this was
your level, this is okay. It's not going to
affect your game. This is still very good. However, if your
whole game is red, like this, you might
experience in your game. However, if it's
just a minimal area in your level that is
red, that is okay. That's fine. Now if I
copy paste it again, you can see it becomes
here, purple and white. And if you have
this in your game, this is really bad. When you optimize your game, try to reduce the amount
of lighting you're using. So you can use them away
from each other. Like this, you can overlap some
of them. That is okay. However, do not try to
overlap many lights at once. This will make your game lag. I'm going to delete all of the other point lights
that I made here. This one and this one as well. Right now our level is
really nicely optimized. So let's go over to
the light map density. Right now it is bucked in real engine. Maybe
they will fix it. These flickering black boxes
are not supposed to be here. Maybe they'll fix
it in the future. But for now, just ignore these black flickering lines
in the light map density. What it shows you
here right now, it is blue again. Blue is resolution. And it is good
for your game performance. If something is
very red like this, it is bad for your performance. We're going from blue to red. There is a gradient.
So it goes from blue to slightly green to green, and then goes to orange, and then it goes to red. Right now, what is the
light map density? What the light map density is? You can increase the light map
resolution for each model. And this will increase how detailed your shadow is
looking on the ground. If your shadow is really low
resolution on the ground, this is because the ground
light map resolution is low. This can be a reason for it. What we want to do
is we want to go to the light map density and
we have to increase it. Blue is really low
resolution for a light map. We have to increase the
resolution in order for the shadows to look good
when they hit the meshes, for example. This
is really good. We want to aim for
this green color. What I want to do is I want
to click on this ground. You can find this ground over here in the content browser. However, if you can't find it, what you can do is you
can click on the ground. And you can click on
this icon over here, and it will take you
to that ground mesh. Now let's double
click and open it up here in the details panel. Let's search for a light map. Now you can see the
light map resolution and the minimum light
map resolution. Now I have to click
on something else. I don't see this pink color, just clicking on something else. I can see the blue color
here for the ground. Now if you just increase
the light map resolution to something like usually
we multiply it by two, you can say 128. Now you can see it's less blue. Now if I do it again, I multiplied by two. Now instead of just writing
the number, what you can do, really nice and unreal engine, you can say multiply by
two and then hit Enter. And it's going to do
it automatically. Now you can see it's a higher
resolution than before. Before it was 64 you. Low resolution. Now when
we multiply it by two, multiplied by two, I still
want to multiply it by two, because this is still a low
resolution multiplied by two. Now this is a lot better. I would sometimes stop here because this is
actually also nice. But what I want to do
is just multiply it by two just to see what
it looks like as well. This is the color I usually
go for in my games. This is still in the
low resolution area, but this will make
your shadows look nice while you still keep
your game optimized. I don't like to make my
models very green like this. I like to stay in the
bluish green area. It still looks good
with the shadows. 1024 resolution, light map
resolution for the ground. And remember to copy this
number and paste it in. The minimum light map
resolution as well. And then you can go
ahead and close it down. And it asks you if
you want to apply it. Okay? Then click yes. You have to do that for
all the other models. For example, let's
take another example. Let's click on this one here. This ring here. It's
this ring over here. Double click it, Open it up. Light Map Resolution,
here it is. Now let's click on something else so we can actually
see the color. Let's write times two. It is still low resolution. Let's multiply it by two again. Let's multiply it by two again. This is actually really good. I think it will be too high
if I multiply it by two. You can see now it's
green and orange. This one. It's still
good performance wise. However, I still think this
is too high performance. Remember, the more you increase
the light map resolution, the more it's going to hit
on the frames per second. And performance, I'm
going to say divide it by two and just stay over
here as the maximum. I'm going to copy this
number over here as well. And I'm going to close this down and going to apply it now. Just go ahead and do
it for all the models you are using in the game. I'm going to skip ahead and just try to do it for all the
models that I have here. I finished adjusting
all of them, and as you can see, this
is what it looks like. Now you can see some of them are still very low resolution. For example, this wall here. However, this wall is also this box that looks very green. You can see if I open up the supercrid box and I search
for light map resolution, I can make it higher. For example, multiply it by two again and multiply
it by two again, and this wall will
be high resolution. However, you can see
that these boxes all red and red now. And this is really not good. This is because the more
you scale up an item, the lower resolution it will be. For example, let's actually
go back to 128 before. If I place it here in the level, you can see now it
is looking green. However, if I take the scale
tool and I scale it up, it's going to look
lower resolution. If I scale it more up, you can see it's now looking a lower resolution than before. The more you scale up the item, the lower resolution it will be. However, everything is
looking nice so far. And if I just go back to the lit mode and what
you can do is you can save level and then go ahead and click on Build
and Build all levels. And that is just
to make sure that all the lighting is built, all the shadows are baked and everything is
looking correct. It's going to take
some time here. It's going to take a bit
more time than before because you have increased
the light map density. However, you can
see that the level is still very optimized. So this actually took no time, and it is already finished. The lighting right now is in high resolution here on
the ground than before. It's looking more high
quality than before. This is because we increased
the light map density. Now let's go back here in
the optimization view modes. Then we have the
stationary light overlap. As you can see, we
don't use much. Here we are in the green area. You can see it's very optimized. If we go over to the
shader complexity, again, it's looking really good. Nothing to be worried
about if I go over, actually, I'm just going
over to the quad overdraw. Instead of putting
them together, I'm going to the quad overdraw. And these are the three D
models that you're using. It's going to take a look at how many triangles you
are using per model, and we don't have much. You can see it's really,
really optimized. Your whole level is
currently optimized. And if you go over
to the Lit mode now, now we are finished with the level, everything
is optimized. And if I go to the
frames per second, if I click up here, show
the frames per second. And you should know that 120 FPS is the maximum
here in Unreal. In the viewport here, you have to export your game
out as an EXC file. For example, if you
want to release it on steam and it will be higher FPS, but inside the engine itself, it is locked to a
maximum of 120, right? So everything is really
nicely optimized. The whole level is
running at maximum FPS. And we have optimized
the level as well. So now we are ready to continue.
12. 3.01 Importing the Characters: All right, now it's time
to import the characters. Now, during the course, we are going to import more things. For example, the weapons
and the animations. But let's take it
one step at a time. Let's start with the characters. Let's open up the
Epic Games Launcher. Inside of here, I want you to click on the Marketplace tab. Now inside of the Marketplace, you can find assets that
you can use for the game. You can see they are creating really nice stuff
that you can use. Of course, much of
it is for money. However, what we're going
to do is we're going to click on Browse and
go to Characters. Then we are going to click
on the free here for the max price are free to use. Now inside of here, I am
going to use this one called Military Doc
and Military Silva. However, you can also
use other characters. You can use this
one if you want, you can use this
one if you want. It doesn't really matter.
You can use this one. It's up to you. However I'm
going to use these two, so I'm going to click
on the first one. Then go ahead and
click on Download. If you haven't
downloaded it before, it will say download here. Go ahead and click on Download. Then you can click
on Add to Project. Now you can see
here, this is empty, and this is because it is only compatible with Unreal Engine 4.8 to 4.27 This is
a very old version. It's not even
Unreal Engine Five. However, we can still
use it for our game. Go ahead and click
on Add to Project, and click on Show All Projects. And then you can
select our Project. And now it's saying it
is not compatible with Unreal Engine 5.2 So you have
to select another version. Click over here and select the latest version
of Unreal Engine. Now go ahead and select it. And go ahead and click
on Add to Project. Now it's going to
item to the project, if you see here, if I go
back to my game here, if I click on it, now you
can see it is now inside of the project and I can
use this guy in my game. It's okay if it is
not compatible, we can actually still
use it for the game. Let's go back and let's go to the other one,
this silver one. Again, go ahead and
click on Download. And when you have downloaded it, click on Add to Project,
Show all Projects. Select our Project and select the latest version that
it is compatible with. Go ahead and click
on Add To Project, and it will add this one
to the project as well. Now we have both characters. We have this one military doc. We have this one military silver that we can use for the game. All right, so this is how you import things
from the marketplace. Just download them and
add them to your project. And if they are not compatible, remember to show
all the projects, Select the project,
and also select the version that it
is compatible with. So now that we have
imported the characters, let's move on to
the next lesson.
13. 3.02 Parent & Child Blueprint Classes: Now we are ready to
work with blueprints. Let's make a folder
here, right click. Go to new folder and call this one blueprints inside
of this blueprint folder. Let's right click and
select Blueprint class. Now we are going to
make a character. So I am going to
select this Aca class. However, if you're not familiar with the blueprint classes, the first one is an actor. And the actor is simply just an actor that can
be placed in the world. For example, a table, a chair, a bottle, just a static
actor that is just there. The pawn is something
you can control. For example, if you have a ball rolling around, this
is your player. So you can control that ball in your level because a
pawn can be possessed. Possessed means
that the player can control this blueprint class
with the keyboard and mouse. Now we are going to
create a character because it has the
ability to walk around. You can imagine like a
human being with two arms, two legs walking around. Then you have to
select the character. If your character is simply
a ball rolling around, then it is sufficient
to just go with a paw. However, we have characters, so go ahead and
click on character. And I'm going to call
this one BP Player Base. Now why did I not just
call it BP player? Why did I call it
BP player base? This is what this
lesson is about. It's about parent and
child blueprint classes. Now I'm going to
create it here first. Before I explain it,
let's right click this BP player base and
create child blueprint class. Let's call this
one BP Terrorist. Let's right click it again
and go ahead and call it BP under terrorist. Okay. This is what parent and child
blueprint classes are. Right now. We have, we
created a blueprint class. From that, we write clicked and made a child blueprint class. What this does is if
I change settings inside of this parent
blueprint class, these changes will
be carried over to the counter terrorist
blueprint class and the terrorist
blueprint class. Let's say I went into the
player base inside of here. I went to the character
movement component and then I changed the
maximum walk speed. Let's say I wanted my
character to walk slower. So I went over here
and I wrote 250. I reduced the speed. I clicked on Compile to
save my settings here, and then I went to, you can see now they
have this star. And the star means
they need to be saved. If you click on
Counterterrorist, you can see if I click on the character
movement component, it is also now on 250. It did it automatically. And if I go to the terrorist as well, character
movement component, the maximum Wx piece
is 250 as well. You can see if you change things in the parent
blueprint class, all of its children will
change this setting as well. This will save you
a lot of time. Let's say for
example, Fortnight. If you're playing
Fortnight, let's say you're a developer
of Fortnight. You have this player base and then you have all the skins. In Fortnight, you
have all the skins. All the player skins
that you're controlling. When you change a setting
in the player base, it will change the setting
for all of the skins. Let's say again, for example, the speed they are walking at. Instead of changing
the walk speed for each single
character in fortnight, it is very easy to just go in
the parent blueprint class, change the speed,
and it will take effect on all the
blueprint children. Okay, so that's why we create parent blueprint classes and
child blueprint classes, for example, the movement, we are going to do
the movement with the keyboard inside of the
player base because we don't need to code
the same movement in the counter terrorist and the same movement
in the terrorist. When they have the
exact same movement, they move the same way. Either if you're a
counter terrorist or terris doesn't matter, the movement is the same. And this is why it's better
to do it in the player base, so you just have to do it once. Okay, I'm going to
change the max, walk back to 600 and the player base compiled as you can see in the counter
terrorist and terrorist, they are changed back to 600. This is how we're going to work. We're going to mainly
do things inside of the parent blueprint
clause and when they have specific things
that are not similar, then we are going to do them
inside of the children here. But for now, this is
the basic explanation. Let's save everything and
when everything is saved, let's move on to the next lesson and set up the character.
14. 3.03 Setting up the Character: To set of the character. Let's first start with the terrist over
here on the terris. Let's click on Open
Full blueprint editor. This viewer is shown
to you whenever the blueprint is empty and you open it for
the second time. Then click up here in the Open full blueprint
editor and you'll be back here in the normal view
over here in the viewport. If you click up here in the Components,
click on the Mesh. And then to the right,
you can see that you can add a skeletal mesh asset. Now you can click
on it over here, and you can select
the character. What you can do,
you can also select the folder that
you have imported. And you can click and drag the character into this mesh
component here as well. You can either select
it from here or you can just click and
drag them into here. For example, I'm going
to use this one, the male terrorist,
and I'm going to click and drag this into
here and assign it. As you can see, I'm going to do the same thing for
the terrorist. Double click on it. Open
full blueprint editor inside of here.
Click on the mesh. Go to the viewport, just so I can see what
I'm doing here. Click over here and sells. Select the female.
That is up to you, doesn't really matter
what you choose, but I'm going to
select this one, the male counter
terrorist character. Now you can see
the characters are actually supposed to
be facing this way, where the blue arrow is showing. They are facing the wrong way. Now again, I told you about the parent and child
blueprint classes. Instead of rotating them
both here and here, you can do it all at once
inside of the player base. If I open up the player base
and I go to the view part, I click on the mesh. Click on E on the keyboard
for the rotation tool, and then I actually
have this snapping on. I put this snapping on and I rotated 90 degrees -90 degrees. That will make them
forward this way. If I click on Compile and
I click on each of them, you can see they
are both rotated. This is why it's nice
to have a parent loss. So you can change one setting and it will apply
to all of them. Now what we have to do as well, we have to make the foot of these characters be at the
bottom of the capsule. We can't really do
it inside of here. We have to do it for each
of them. You can do it. Let's actually try.
Let's just do it. Let's click on the mesh. And click on the
skeletal mesh here. Just assign any random
character here. We're not really
going to worry about the character because we are
going to remove it as well. So click on this character. The best way to do this is go to the perspective view here. And click on, Let's start with the front
view, for example. You can zoom in and drag
this character down. Just like that, you can see the capsule is not really
filling this whole character. So what I'm going to do is
clicking on the capsule. And the capsule half height, I'm going to increase
it slightly, something like 93 or
something like that. Click on the character.
I'm actually going to switch to
the right view. I think it's a lot easier to view and just drag
this character. So the foot here
is at the bottom. You can imagine this is the
floor. The floor is here. Where it hits this point, I'm going to drag it down. So the foot is in the
floor just like that. It doesn't have to
be 100 precise. You can always adjust it later. But this is just
a nice start now. It doesn't really have to
fill this whole thing. Collision capsule. This capsule component is usually used for is a collision. For example, in two D
games, three D games, if you want to hit the player, they're going to get hit
through this capsule component. However, in our multiplayer
first person shooter, we are going to create a more advanced collision system for the arms and legs and so on. Because you can
see in this game, if we have this capsule as the collision, when
you hit the player. You can actually hit the player if the bullet is shot here. And that doesn't
really make sense. So we are going to make a more advanced hit
detection system. So that the player will
only be hit if they are actually hit in the
arm and not out here. This one doesn't really
matter too much for now. It doesn't have to
be fully precise, but I'd like to here
in the right view, just make it as best as you can that it hits the
floor like this. If you go to the front view, you can try to reduce
the capsule slightly. It is about his body,
just like that. Okay, let's click
on Compile now. Let's go to the
Counterterrorist. See what it looks like. If
I go to the right view. Front view, take a
look. Looks fine. If I go to the
terrorist compile, just take a look in
the perspective. Take the right view. Just take a look at the counterterrorist. This one looks fine as well. You can see we made the whole thing here
inside of the player base, and now they are applied for all future characters
that we make. Now let's say you want to make another character
in the future. What you need to do
is just right click here and create a new
child blueprint class. Let's say for
example we called it EP and there's a
terrorist called Phoenix. A new character you can go inside of here
and you can click on this guy on this mesh and then you can change it to
that Phoenix character. For example, this female
character could be Phoenix. And you can see how easy it
is to create new characters. All of the settings are applied. Let's say for this character, there are some settings
that need to be changed. Then you can just go inside of this character and just
adjust this character. You can adjust these children blueprint classes just fine. You don't have to just rely
on the player base settings. You can adjust each of
them if you want to. However you can see it's really nice that we have
the basic settings Default Settings
supplied already and it makes our work easier. Now let's close everything. I'm going to delete this one. This was just to show you and I'm going to go back
in the player base, we need to add a camera as well, because right now the
character is there. However, we don't have a camera for the player to look through. We're going to click
on the Mesh here, go to D. Then we're going to add something called
a spring spring. Arm is just a holder
for the camera. Clicking on the spring, go to D and then search for camera. Then you can select this camera. Now you can see we
have a spring arm, and inside of the
spring arm is a camera. Now clicking on the spring, I'm going to click on my
keyboard for the rotation tool, and then I'm going to rotate the camera so it's
behind the character. For now. I'm just
going to drag it up. Just something like, this
doesn't really matter for now. We're going to adjust
the camera later on. But for now I just want to see my character when
I'm inside the game. What you can do
is you can see it here if you, for example. Now you can see it's actually
applied to both of them, the terris and the counter terrorist because
they are children. You can see that both
have a spring arm now, both the terrist and the
counter terist as well. But what you can do is you can click and drag the
counter terrace, for example, into the level. If you click on the character, you can see you
have a view here. And this is because you
just added a camera. You can see what this character is looking like from behind. What I usually do, actually
here in the player base, I'm going to click
on the spring arm. And I'm going to
set the arm length to something like 600, so it's a bit far away
from the character. And then I'm going to click
on the character, and you can see this is
what it looks like. I'd like to develop my
first person shooter this way first and later
on. It's very easy. The difference between
a third person and first person shooter is just that you can click on
the spring arm and set the target arm
length to zero. And then you're actually viewing this game as a
first person mode. But for now, since we're
doing the player movement, I'd like to start with a target arm length of
600 because then we can see all of the movement
that we are making and we can see if we are
doing things correctly. This was it for
sitting of the player. Remember to compile and
save all of your work. And let's move on
to the next lesson.
15. 3.04 Game Mode & Player Controller: Every game that you create. No matter what the game is, you always have a game mode
and a Player controller. Let's click on the
Blueprint folder. Before I do anything, let's actually create a new
folder inside of here, and let's call it Player. I'm going to take all of these
here and add them inside, move them inside of
the Player folder. So we're a bit more organized out here in
the blueprint folder. Let's right click and create
a new blueprint class. Let's select a
Player controller. A Player controller,
what we usually do inside of here is we create the user interface and then we also spawn things
inside of here. For example, if the player
drops a weapon into the world, then we spawn that
weapon into the world, spawning things inside
of the Player Controller and also the UI is inside
of the Player Controller. Let's go ahead and click and
create a Player Controller. And I usually give them a prefix of EC for
player controller, then I call it the
name of the game. The game is counterstrike, I'm just going to
call it under strike, then right click again. Go to Blueprint class and then create a game mode. And usually what the
game mode is for, it creates the rules and
the scoring of the games. For example, how many seconds per round and what
the game mode is, for example, capture
the flag and so on. So go ahead and
create the game mode, and let's call it
GM for game mode. And again, I'm going to call it the name of the game
Hound, A Strike. So what I want you to do is
double click this game mode. And we need some initial
settings inside of here. In the game mode,
you can see we have in the default class defaults, we have the Player
Controller class. This is just the default Unreal
Engine Player Controller. We want to click on it, change it to our own custom player control law
that we just made. The same thing for
the default class. Later on, we are not
going to have anyone, we're going to select none. However, we don't really have a character selection
screen right now. What I want to do
is just spawn as, for example, a terrorist
or a counter terrorist. I'm just going to select
counter terrorist. Later on we are going to
remove it because we will have a character selection screen and you can select what
you want to spawn as. But for now, let's just spawn as a counter terrorist
because we don't have a character
selection screen. Now let's close it down. Let's go to Edit and
Project Settings. Inside of here we have
the maps and modes. In maps and modes, you have
to change the game mode. Right now it's set to
the game mode base, which is just the basic game
mode for Unreal Engine. However, I want to change it
to our own custom game mode. And clicking on this small arrow for the selected game mode, just making sure that the
default point clause is the counter terrorist
we have selected and the player controller
is our own as well. Now if you want to,
you have noticed if you close and
open the engine, it will put you in that
open world default map. You can change this inside
of maps and modes as well. The editors start up map, I can change it to be this map, this map that we created also for the game default map, we can change it to
this one as well. Okay, let's close this down. As the final thing, go ahead and click on
the World Settings. Now if you can't see the tab, you can click on Window and
click on World Settings, and you will be able to see it. So go ahead and click
on World Settings, and in the game
game mode override, click on this one and select
our game mode like this. This is very important
that you do all of this because else you can't spawn the player
inside of the world. Now if I delete this player, this is just someone I just placed in the previous lesson. We have to have a player start before we can actually
spawn inside of here. I'm going to click
up here and go to Basics and select
a Player start. I'm going to click on
G to see the icons. I'm going to move it
down just like that, into the world. Something
like this here. You can see here, if you
put it beneath the ground, it's going to say bad size. Just make sure it's above the ground. Something like this. Now you can click on play, and this should spawn
your character. If it doesn't spawn, please
watch this video again. Make sure the game mode
is inside of the world, setting is inside of the
project settings, and so on. But now you can see we are spawning as the character
and we click on Play. And it's actually looking
cool. This is Lumen. You can see the lumen lightings, actually wolf taking
it from the surface. Okay, so now we have added the game mode and
the player controller. And let's go ahead and do the input mapping context and add movement for the player.
16. 3.05 Input Mapping Context: Let's go ahead and start on the input mapping context where we can add the
player movement. Let's go ahead and go inside
of the player folder. Inside of here, I'm
going to right click and make a new
folder called Input. I just misspelled that input just like that inside of here. Let's open it up, right click, go to Input and create this one called an
input mapping context. Usually I called IMC as a prefix and I'm just
going to call it default. Now, before we can use this, you can see if I open
it up, it is empty. If I click on this plus here
to add a key to my movement, for example, you can
see it says none, and I can't select anything. This is because it
wants an input action. So down here, let's right click, go to input and
select input action. This one we're going
to call movement. Now for this one, I'm
going to open it up. This input action,
the only thing that we really need to change inside of here is
the value type. The value type, you
can click on it and you can see you have
these different options. What we are going to do
is movement forward and backwards for our character
inside of the game. If I put the character
inside of here, character is going to
move back and forth. That is one axis. The character is going to move left and right. That is the second axis. This is why I'm going to
choose an axis two D, because we're moving forward backward and also
left and right, which is the second axis. Then I'm going to save here. Let's go back to the
input mapping context. Now we can click up here and add our input action
that we just made. Okay, let's just
minimize this for now. Instead of here, you
have to assign a key. I want to move forward
with my W key. What you can do is you can
press up here and search for. And then you can see
this is the keyboard. You can select the
W. Another easier method to do it if you
click the plus up here. Now I want to move
backward with my S key. Instead of clicking
over here and writing and finding your S key. Sometimes it can take some time. What you can do is you
can click on this icon, and then you can click on the keyboard that
will assign this key. Now to move left and right, I'm going to two of them
here for the right, I'm going to click here and
click on D for the left. I'm going to click here and
click on A on my keyboard. Now I have those keys. I also want to add is I want
to add the mouse movement. I'm going to create
a new input action. I'm going to go down
here, right click, go to input and create
a new input action. I'm going to call this one Look, looking with the mouse
for this one again, I'm going to open up
the input action. And I'm going to change the
value type to axis two D, because I'm going to look up
and down. That's one axis. And the second axis
is looking left and right axis two D.
Going to click Save. And going back to my
input mapping context, now I can click the
plus up here and I can add my new input
action for this one. Now click on it here
and search for a mouse. And you have this one
called mouse Xy2d. Now also just add the mouse X, and also add another one, and add the mouse Y. You can do that as well. That's the same thing, but
to make it more clean, I'm just going to
click here and search for the mouse and
add this mouse Xy, because we can do
that as well and it will become a lot
cleaner in the code. Now what we want to
do with the movement here with the WK, we are moving
forward with the K, we are moving backwards. However, right now, they're
both moving forward. What we need to do
for the SK to move backwards is in the modifiers you need to click on the plus. Then down here you have to
select this one called negate. This inverts your input. When you click on it
will move backwards. When you have this
negate added it, Negate just means it
does the opposite of what the key does. We have to do the
same thing down here. D is moving to the right, actually, for the
left and right. What we have to do as
well in the modifiers, we have to click here and
select to world space. We have to do the same
thing for the left. Here, we have to click
on the modifiers and select to world space. Now for the left and right, the D is going to the right and the A is going to the left. Now for the left,
we also have to add this modifier called Nick
Gate, just like before. It's going to go the opposite
way of what the D is going. So let's go ahead
and click on Save. Everything is looking fine. And now we are ready to add this input mapping
context to our character. Because now we have
added everything. Everything is looking good. Now if we get some box
with the movement, we can always come back
here and change it. But for now, this
is what we have. And let's delete this character. And let's move on
to the next lesson.
17. 3.06 Adding the Input Mapping Context: Before we can use the
input mapping context and add movement
to the character, we have to add this to our blueprint Clauss. Let's
go ahead and do that. Let's go to the player and let's go inside of
the player base. Inside of here, we are
going to add the movement. When we add the movement here, it's going to apply it
to the children as well. In the parent blueprint
Claus, the player base. Let's go to the event graph. Inside of the event graph, you can click hold the right mouse button and you can pan around inside of here. Now let's go ahead and
select all of those. And hit the lead
on the keyboard. And start from the beginning as the first thing
I'm going to write. Click. And when you write click, you can select between
different functions and events. The first event we're
going to create is called the Begin, Play, Play. Go ahead and select the
event, Begin, Play. And what that does is what should happen if I
begin playing the game? You can write code here If I drag from this execution
pin and I'll let go. And I write print and
use this print string. So this is the simple, simplest function that we
have in Unreal engine. In blueprints, this will just print some
text on the screen. Now if I compile,
I click on play. You can see it says
hello up here. If I click on play again, you can see it says hello. So this just says what should happen if I begin
playing the game? What we want to do is we want
to add the mapping context. The way you do this
is first you have to get the player
controller reference. To do that, let's write click and just search for controller. You can select this one
called Yet controller. We are getting the
controller, however, this one is just the basic default player controller
in Unreal Engine. We have to specify to
Unreal Engine that we're actually talking about this custom player
control that we made. The way we do this is
we contract from here. And we can say cast two, cost two means is
we're trying to get the reference of this
player controller I can drag from here
and say cost two and then you have to give it the name of the
player controller. Player controller, PC. Counterstrike is
what we called it. So go ahead and select it. Now we can access
everything inside of here. Let's say in the
Player controller. If I, for example
add a variable, just call it hello or
something like that. Anything random click on compile inside of
the player base. Now you can see if I drag
from here and write hello, I can see the
variable I just made. Casting is you can
access everything inside of this player controller now because you have
a reference to it, this is what's called
blueprint communication. Because now you are in the
player base and you are communicating with
the player controller and you can access
everything inside of here. The only thing we
want to do inside of here is we want to drag. And then we enhanced, I never remember this
name, it's so long. Enhanced input local
player subsystem. Just write Enhanced
and select it here. From this one we're
going to drag and say add mapping context. Go ahead and add the
mapping context. And remember to connect
your code else it will not work because it's
going to go from the event, it's going to get this
play Controller reference. And then it's going to add this mapping context
to this blueprint. And remember in the mapping
context you have to click here and select the
mapping context you made. Go ahead and click Compile.
And that is actually it. Now you have added the
mapping context to the player and you can now use events
and create the movement. However, in the next lesson, we are going to talk about
blueprint interfaces. I don't really like doing
casting because casting creates hot references in real engine
when you start the game. For example, let's say
you created a full game. You have casted, for example, 100 blueprints in your game. Now it is released on Steam. However, for the hot references, when a player opens up your game before it loads up the main
menu and everything else, it's going to load the
hot references first. If you have, let's say 100, 200 in your game of the casting, it's going to slow down
your game because it needs to load all of
the hot references. It needs to load
all of these first. It can run your game. I'm not saying you
should never use this, because there are cases where it's ridiculous to not use it. However, for this case, what I usually like to do is I like to make a
blueprint interface. And from that we can
communicate with other blueprints without
creating hot references. So let's do that, let's make
our game more optimized. And I'm also trying
to show you how I would do it normally
the advanced way, and I don't really like to
teach you bad ways to do it. Let's try to avoid
casting for now, and let's move on
to the next lesson where we can replace this part.
18. 3.07 Blueprint Interface: Blueprint interfaces are
used instead of costing. For a blueprint communication, we usually use
blueprint interfaces so that we can avoid costing. And as you can see here in the player we did
in the player base, we did this costing and to
avoid hide references that needs to load in the game before the main menu and
slows the game, we create blueprint interface
to avoid these casting. Let's go ahead and create one. And let's see what
it's all about. Over in the blueprint folder, I'm going to write, click
and make a new folder. And I'm going to call this
one interfaces or interface. And let's go into that
folder inside of here. Let's write click, go to Blueprint and select
Blueprint interface. Usually for interfaces, I usually call them t as a prefix. Right now you have to call it what you are trying
to reference to. I'm trying to reference
to my player controller. I'm going to call this
one play controller. I'm going to go
inside of here and this is the blueprint interface. Keep in mind that
blueprint interfaces are usually difficult
for beginners, but try to understand
them and it's actually very easy
to understand. Let's just try to
make one and see what happens inside of a
blueprint interface. You have this view, you can't really do anything
inside of here. You can't drag or do anything. The only thing you can do is
over here in the functions, you can create a function. The function I want to make now if you click two
on the keyboard, you can change the name of this. I just want to call it get
player controller ref. I'm trying, with this function, I'm trying to get the player
controllers reference. So I can avoid this casting here over here. I'm going to click on this function I just made. I'm going to create
an output here. In the outputs, I'm going to select the blueprint class
I'm trying to reference to. Now I'm trying to reference to my Player Controller
PC counterstrike. This is what we called it. And select the object reference. Select here in the variables
you have to select the blueprint class you are
trying to reference to. I'm going to call this
one Player Controller. And now this function is
finished. Very simple. Remember to press
and compile here. Very important and
go ahead and save. Now we have this
simple function. Now what we can do with this
is now let's open up the controller. If I go to
blueprints and I open up the player controller
inside of here, let's open up the
full blueprint editor and then go ahead and
select Class Settings. In the Class Settings down here, you can now add the
blueprint interface. Let's click here and
search for T. Here it is, the interface we just made.
Go ahead and select it. When you select the
blueprint interface, you might notice that over here to the left, you see this tab. Now this is a new tab that just appeared called interfaces. Inside of here, you can
see the function we just made inside of this
blueprint interface. Now it has appeared when you
add the blueprint interface. If you double click this function and you
go inside of it, now you can set
this variable here. We created this player
control variable, but right now it is empty. What we need to do, we
need to drag from this. And then we write self. What does that mean? Let
me actually do it again. Maybe it was too quick.
Dragon from here. And writing self and
then select this one, get a reference to self. What that means is, let me
actually just go back here. We made the blueprint
interface here and we made that function inside of it here for the variables
we selected, the variable we wanted
to reference to. Now inside of the
player control, when we added the interface
through the class settings appeared here. The
function inside of here for this variable
we are writing self. What that means is
we're just telling the engine what this player
controller variable is. Because if I hold control and click here and
disconnect it, the engine will never know
what this variable is. If it stands like
this, it is empty, the variable is empty and you
will get era in your game. But if we do a self reference, what that means is it means this variable is self. Remember we are inside of
the Player Controller. We're basically defining this
Player controller variable. We're telling the engine it is this Player Controller that I am in right now. It is self. Self reference means what Eva, blueprint class I am
inside of right now, which is the Player controller. So we just defined it here. Go ahead and compile and
save what we can do now. Now we are finished with this. Now we can go to the player and let's go ahead
and delete this. What we can do now
is we can drag from the controller and then write the function
that we called it. Here is the name of it. Get
player controller reference, I can drag from here and say get layer. And then you can
see it appears here from the blueprint interface
that we made, It says get player
controller reference. This is the function we just made when it says
message at the end, This means it comes from
a blueprint interface. So go ahead and select it. This icon here, it just
means that it comes from a blueprint interface.
And now we have it. Now we avoid casting, we avoid the hard references, and our game is more optimized
performance wise as well. You can now just go
ahead and connect it. Now it knows that this player controller that
we are referencing to is our PC counterstrike
player controller. Because all this variable in the PC counterstrike we
went ahead and wrote self, it actually now knows what
we are talking about here. This might be a bit confusing
to begin with if you have never used blueprint
interfaces before, but very handy to avoid casting. We just created the
blueprint interface. We then went ahead and selected the blueprint class we
want to reference to. Then inside of the
blueprint class we're trying to reference to, We added that blueprint
interface and this one appeared. Then inside of here we
did a self reference. And from that later now
we can now use it here where we can say
get controller and then get the player
controller reference, just like that and
avoid costing. All right, so that was it
for the blueprint interface. We are going to have more
examples in the future. If this was a bit difficult, please take a look at my
Discord server or take a look at Pixel
Helmet.com I am very, very happy to help you out 2047. So let's go ahead and
click on File Save All. And let's continue
to the next lesson.
19. 3.08 Player Movement: Now that we have added the input mapping context
to the player, we can now do the movement. We have to write the name of the input actions
that we created. The first one I
created was called IA movement. Let's
start with that one. What you can do now here in
the player, you can write, click and write IA movement, the name of the input action. And then you can click on
this event to create it. Remember, this symbol means that this is an event. So go
ahead and create it. Now we have this event and it looks a bit complex,
but not really. It just says to you, when the event is triggered, started, ongoing,
canceled and completed. Nothing too complex here. Now, when is this event triggered? The
event is triggered. If you go to the input
mapping context, remember we added buttons
for our movement. If I click on W, this
movement will be triggered. Now let's see if
this actually works. Because if you have
not added this code, this will not fire
right print string and I just print a simple
message to the screen. If I click on, for example,
I can click on play. And if I click on, you can see it is actually
printing to the screen. Now if I had
disconnected this and I did not add my input
mapping context, and I click on Play
and I click on, you can see nothing is printing to the screen and
it is not working. Remember to add
this to your code. All right, now that this is working, let's do some movement. For the movement for the player, we use a function called Ad
movement input, right click, and write a movement inputs, this is how you add
movement to a character. Let's connect it now. Now
what it's asking for you is, what direction do you want
to move the character in? Now let's do the first one. Move forward and backward. What you can do simply
right click and right. Yet at forward vector, this is the forward vector and we can connect it here
to the world direction. Now, how do we move backwards? We actually don't
need anything else. This is the only thing we need. How is that, how does it know when we walk
forward and backward? This is because of
this scale value. Scale value is one, it's
going to move forward. You can see here,
if I click on play and I click on it moves forward. If I click on right now, it actually also moves forward because this scale
value is set to one. If I set it to minus
one and I click on Play here and I click on, or you can see now
it moves backwards. When this is one,
it moves forward, and when it is minus
one, it moves backwards. This is the action value here. We can right click this
and split the struct pin. Or you can take this and break vector two D. This is
actually the same thing. I'm just going to right click
it and say split structure. Now for this x, you can add
it here to the scale value. Instead, when you click
on, you move forward. When you click on, you move backward because it
will be minus one. Remember in the input
mapping context, you wrote the modifier
here for the, when you press backwards, you wrote or selected Negate, which just inverts the movement. Which means this
will be minus one when you click on the okay. This is the forward
and backward movement. This is now finished now for the left and right,
very, very simple. You can copy this and paste
it and connect it here. Then for the word direction, you can write acorrightvector. And you can connect it now. And now you can connect it for the y over in the scale value. Now remember to
organize your code. You can double click here
to make a reroute node. Just try to stay organized. Double click this one as well. Try to stay organized. Just like that. It's always
nice to stay organized because you can
imagine your code will be very large later on. You can also select
the whole thing and click on C on the keyboard
to create a comment. For example, you can write
WASD movement and so on. For now I'm not going to do it, I'm going to do it a bit later. Yeah, this was the movement. You can now compile
and click on play. But instead of playing
inside of the viewport, I think it's easier for
you for this view it if I play in the editor
in a new editor window, clicking up here,
new editor window, and it's going to
pop up like this. Now I can play now let me actually just make
it a bit larger. Click on play, making it larger. You can see now when I
click on, I move forward. As I move backwards, if I click on D, I
move to the right. And if I click on,
I move to the left. Now I can move my character
with my keyboard. Very, very nice. However, right now we can still
not move the mouse. We need to add the
code for that as well. You can right click here again. We call this one IA
look Input action. We need to use that event. You can now right click
and write a look. And then we can
select that event. Now for looking, we have to use something called add your input, this is looking left and right. And then we have the second
one called a pitch Inputs, This one here, this is moving
or looking up and down. Very simple again, right click here, split
the struck pin. Go ahead and connect the
x here and the Y here. And that was it for
this very simple, for looking up and down and left and right
with the mouse. Let's compile and
let's click on play. And I'm going to move my mouse. You can see I can move
it right and left. I cannot move it up and down. This is actually
in the spring arm. If I click on the spring arm, I have to take this one called
use upon control rotation. Now I can click on Play. And now you can see I can move up and down,
left and right. However, when I
move up and down, it's actually inverted
compared to what I'm used to. I'm not used to move up and
down to the mouse like this. I'm used to have
it the opposite. Let's go to the input
mapping context over here in the mouse Xy here. For the modifier,
I'm going to add a new modifier and right negate, I want to invert my Y movement for the mouse clicking
on the small arrow. For the negate, I'm
going to remove the X and Z. I don't want to
invert the X and Z, I just want to invert the Y. So again, I'm just
going to click on play. And now when I move up and
down, it's actually correct. So now when I move up and
down, it is correct for me. And when I look left and right is also
correct. All right. So this was the movement. And again, if something is the opposite way of what
you're trying to move to, you can always come
in out of here using the negate and try to
invert the movement. And when everything is correct, this was the movement very, very simple for our character. We can now move and
look with the mouse. However, we are
missing the animation. And we are going to work with
that in the next lesson. So go ahead and save
everything, and let's move on.
20. 3.09 Importing the Player Animations: Now that we have finished
the player movement, we are now ready to add some
animations on this website. I have included for you
some course materials. Go ahead and download the
court materials and you'll probably get this course materials folder
as a Sip folder. Just make sure to extract the content from the Sip folder. Now what we can do here is go inside of the Counter
Strike Animations folder. This is an Unreal
Engine project. I've added all the animations for you that you need
to use for the game. If you just go ahead and
open up this project, when you have opened
up this project, this is what you will see. You have this animations folder. Inside of here are all the animations that
you need to make the game. You have some animation offset when you're aiming
the gun and so on. For this one, let's right click the animations folder and
then let's select migrate. By the way. Another tip here. If you right click one
file instead of a folder, the migrate is under
Asset Actions, and then it is here migrate. This is if you want to
migrate just one file, but we want to migrate
the whole folder. Right click and migrate. And just hit okay, here again, let's migrate
it into our content folder. If you go to the multiply
Shooter, this is my folder. It is inside of the cons, strike project and then ins
content inside of content. Here, again, only select
the content folder, select any other folder, else it will not work. Just go ahead and select
the content folder. Select folder, and it
will extract all of the animations or over
to our own project. Now that we have
finished migrating, let's go back to
our own project. Inside of here, you can see we now have the animations project, and we have all of
these animations that we have migrated. Now we are going
to transfer all of these animations to
our own character. And later we can delete these two folders
that we imported. Also, for these two folders, I'm actually going to
click and drag them into the marketplace just to
make it a bit more clean. Sometimes when you drag
folders from one to another, and you can see in the
marketplace, they are now here. However, they're
still over here, and it's just empty folders. It didn't delete.
What you can do, you can select them, hit delete on your keyboard, and you can see it is
object redirectors. You can just ignore that
and go ahead and delete it. Now you can see it's
still not deleting. It happens sometimes
in Unreal Engine. You can right click
the content folder and click Fix up redirectors, and then you can try
to delete again. If it doesn't delete, I usually just go ahead and
close the project. And then I go inside
of my own project here and the content folder and I just delete
them from here. Just make sure that you
have transferred them over to the Marketplace
folder as you can see here. I'm just going to delete these empty folders from
the content folder, and then I'm going to
open up my own folder. Again, this happens
sometimes in Unreal Engine. Okay, so here we are again
inside of the project, and now that we have
imported our animations, and we are going to transfer
them to our own character. And then we are going to remove these two folders later on, but let's move on
to the next lesson.
21. 3.10 Creating IK Rigs: Before we can copy over the animations to
our own character, we have to create
something called an K rig. Let's go over to the blueprints. And let's go to the player
folder here I'm going to right click and make a new
folder called Animations. And then inside of this folder, we can go to animations. Here, down here we
see something called K. Then we have to select this on the yellow
one called K rig. I usually call them, let's
call this one mannequin. Mannequin is the name of the
other character that we are going to copy the animations
from K mannequin. Now you can double
click and inter here. And what you can do
here now you have to select a skeletal mesh
that you want to use. I'm going to use this mannequin here that we need to
copy the items from. You can go ahead and
select this one. You can see it's called in
that references 01 folder. If you can see that information
down there in the link, if you go ahead and click on it. Now this is the Manikin, we are going to create an
IK rig for very simple. Over here in the IK
rig interface you have all of the
animations as you can see here in the
assets browser. If you can double click on them, you can see the
animations here in the IK retargeting window. Here you have to
specify the bones of this character and
then we also have to specify the bones of
our other character. And then that way
we can actually copy animations from this
character to the other one. Because we have
defined the bones and honoral engine knows how
to copy the animations. Now I'm just going to click on reset just to make
them stand still. Here in the IK re targeting. What you have to do is you
have to create a new chain. The first chain we are going to, we're just going to call it head. Go ahead and call it head. Right now we don't need to
select anything, just chain. Just like that. Okay, we
have now one called head. Let's keep adding
the other ones. I'm going to hit a chain again. And this one is going
to be called left, left, And then go ahead and create a new one called, right. Then create a new one, Leg left. Create a new one
called leg, right? Then we can create
a new one called spine and a last
one called roots. Okay, so these are all the
chains that we need to create. Head, left, right leg, left leg, right spine, and root. Now you have to specify where the head starts
and where it ends, the start bone and the end bone. What you can do
here, and a very, very easy way, now
I know it's called. If you search here for neck, then you can select it here
and it ends at the head. Now I know this because I
have done this 100 times. However, if you are
new here or if you have a new character with different bones,
because remember, if you have an artist doing this for you customly in
a three D software, they can call it
whatever they want. You have to know
what it is called. These are just the
names of the bones that usually come in on real engines. I know what they are called. What you can do here
in order to see their names without actually knowing what they are called. Here you can click on actually
Show the Character here. Click on Character and go to Bones and select all Hierarchy. This makes it so you can see all the bones
for this character. What you can do here,
you can click down here. Now you can see it
is called Neck 01. My head starts from neck 01. If I click up here, this
one is called head. The end bone is head. Now
let's do it for the arm left. Now this is the left arm here. If we're standing like this, this is the left arm. If you can click
on the left arm, it starts at the clevical, left over the start bone is Levical left the end over here. It's not really the end
here at the fingers, but where the hand starts, if you click up here, it says hand left. The end bone here. Let's select
had left, just like that. Had left as the end. Now for the right,
it's the same thing. It's just Levi Coal, right? And then hand right
for the leg again, you can try it as an exercise, you can click on it somewhere
up here. This is the thigh. It starts from the thigh here, searching for th I'm
just going to copy this. Thigh left, and I'm going
to paste it over here at the leg right to make it
thigh left. Thigh right. The leg ends down here. If you click on it, it ends at the selecting foot left
and down here, foot right. Now the last one, spine,
this is very easy. It's the middle spine over here. It starts from spine one
and ends at spine three. This one is an easy one. Searching for spine, you
can see it starts from spine one and ends
at spine three. The root is just called root. You can search for roots, just call it root here
as well. Root, root. This is the same thing,
It's just the bone up here, The root bone down here. Now we are finished with
retargeting this character. And what you can do is you can right click the pelvis
here. Very important. Now right click the pelvis
and select set target root. This will stabilize
this character. And go ahead and click on Safe. Okay, now that we are
finished with this one, what we can do now is we can go ahead into the
animations folder. Find your IK Ric you just made. You can right click and then you can actually duplicate this. Let me call this one K player.
This is the player one. Now instead of doing
anything here, what you can do is you can
just select the player. Now for example, you can select
this male undaterroristk. You don't have to do it again. You can see it's already there. Everything is good.
Everything is fine. It's already set as the retarget route because
we did for the other one. We can close this one down, but now we have
these two IK rigs. With that finished,
let's move ahead to the next lesson and
create the IK retargeta.
22. 3.11 Creating an IK Retargeter: Let's now go ahead and
create the IK Targeta. Let's right look
here, two animation. And then select the K C again. And select the second one
called an IK Targeta. Because now we are ready to copy the animations from one
character to another, creating the K retarget. I'm going to call it IKR. Let's just call it
player for now, IKR. Let's open it up. Now it's going to
ask you which IK Rick you want to copy
animations from. I want to copy animations from my mannequin that we
have the animations on. And I want to copy animations to my player just like that. It will add these two characters
for you automatically. Now they are overlapped over
here in the target mesh. Offset the x here. I'm going to click
and drag and just move this character
out of the way, something like 175
here in the x axis. So I can see both of them. Now inside of the IK
tageta, you can see, I can now see all of
the animations down here in the chain or
in the set browser. In the chain mapping,
you can see the chains that we created in order
for it to work correctly. And usually it does it
correctly automatically, just making sure
that the root for the target chain,
which is this one, is the same as the source
root is paired with root, and spine is paired
with spine, and so on. Just making sure that
leg right, for example, is not paired with spine.
That will be wrong. They need to be paired with the same bone or chain
that we created. Usually, Unreal Engine does
that automatically correctly. Let's go over to
the acid browser now, these are the animations. If you click on one of them, for example, let's select
this one walk right? You can see it's almost correct. Actually, I'm going to remove these bones so we can
see it more correctly. If I click on
Character Bones and selected only now
it's almost correct. However, the arms
are very weird, else everything else
seems to work correctly. We can copy it almost however we need to
correct something here. I'm going to click on Stop. I believe. Here,
yes, click on Stop. We'll stop the animation. The reason why it's not
copying correctly is because the position for this character needs to be the same
position for this character. And you can see the arm is
not in the same position. This is why it's creating an era with the arms. In this animation, I'm
going to hit Stop here. What we can do is we can
select one of the bones. Again, click on the character
bones, all in hierarchy. So I can see all the bones, and here they are
for these bones. Now what we can do is
click on Edit mode. Edit Mode makes it possible for us to edit the pose
for this character. Now you can select one of
the bones, for example. You can just try it out, Select this one,
try to rotate it. You can see this one is not
the one you should rotate. You can click on
control Z to go back, and you can select the next one. The next one here. If you just rotate it down, just like that, I think something
like 50 degrees. I think 40 degrees
is a bit too much. Maybe we can just try
-50 degrees this way. For the other one, I'm going
to click the same bone and then rotate it -50 degrees, just like that.
Just like this guy. You can also see this guy has a rotation on
the bone over here. I have to do it
over here as well. I have to click
here on this bone. Then I can rotate it
maybe like 30 degrees. And just try to
compare these two. Also clicking on the other one, rotating it by 30
degrees, just like that. Just try to take a look from top and compare
these two characters. All right, I think
they look the same. Let's try out the animation and see if it's actually working. I'm going to go out
of the edit mode. I'm going to hide
the bones again, just to see what it looks
like without the bones. And then I'm going to click
on one of the animations. For example, let's actually select one where he's
walking or running. That's a bit better to look at. You can see the hands
is a problem right now, and I think that is because we rotated the arms
way too much down. Let's go back again
in the edit mode. I'm going to view all the bones, then I'm going to
click on this bone and rotate the arm
up a little bit. Probably the issue,
we rotated it a bit too much down Now
let's take a look. Let's go back from
the edit mode. Click on the front here, let me just remove
the bone so I can see what it looks like
trying other animations. You can see everything
is working correctly. However, the mistake here
is right now are the hands, they're not really
working correctly. Just to make sure
everything is correct, I'm going to stop the
animations and I'm going to take a look at it from
the perspective view. Here. From the right view. Just taking a look at
these two characters, just making sure that
everything looks correct. Also going to the front view and making sure
that everything is correct in order
to see it better. Here we can click on
the character again, Bones, and then all hierarchy. So we can see all the
bones and here they are. You can see there is
a small difference. If you can click on one of the arms and then set the
snapping for the rotation, I'm going to set it to five
and then go to the edit mode. Then let me just rotate
it here slightly. Then I'm going to rotate it slightly just so it almost
fits the other hand. Something like this here. You can click on the other one, and also not this one,
this one up here. And rotate it so it fits
the other one as well. Now you can go back to
the perspective view, take a look at these characters. You can also actually
take a look at it from the top view to see what
they both look like. And if they look the same, I think for the most part
they actually look the same. Let's go back to the
perspective mode now. What we need to do is
we actually need to fix the hands because
they're not looking good. We can just try to
run an animation. For example, the walk back left. And I'm going to remove all
of the bones so I can see it. You can see they look
fine. Both of them. However, the hands are
a little bit messed up. So we have to fix that.
Let's jump over to the next lesson and fix the hands before we
copy the animations.
23. 3.12 Fixing the Hands: Now let's go ahead
and fix the fingers. Before we copy the animations, let's double click this
mannequin K rig here. I've already added the chains. You can see here, you have to add chains as well
for the fingers. If you want the fingers to work just like the other
parts of the body, just go ahead and
add the same ones. The thumb here, this thumb here. And then you have the index
finger, the middle finger, the ring finger, and
then the pink here. You have to add them,
all of them again, thumb left, thumb
right, index left, index right, middle left,
middle right, ring, left, ring, right and pinky
left and pinky, right. Just go ahead and add
them. I'm just going to show you the first two on
how you can find them again, and then I'm going to
add the rest of them. The first one here, the thumb, you can click on
the first one here. You can see this is
the thumb 01, right? You can click here and
search for the thumb. You can see it starts
with thumb 01. This one is the left one. We have to select the thumb. 01, Left it, right thumb. It ends at thumb 03, left. You can also click
here to view the name, but it's very easy
for these fingers, the same right one, you can search for thumb,
select the right one. It ends at 033, over here in the index
finger, you can click on it. It starts with index 01. You can see for the hands, they are actually straightforward. If you just click here
and search for index, you can see the index
01 for the left, one for the right, 1203 for the right. 101203, left one and right one. Over here in the middle finger, you can click on
the middle finger. It starts with middle 01. I'm just going to go ahead
and add all of them here. Now I have added all of them and we can go ahead
and click on Save. And you can see
all of them here. Just like what we did up here. Okay, so now what I can do, I can close this down. Now instead of adding the
same thing over here, I'm just going to delete it. I'm just going to
delete this one. And clicking on Okay. It's actually going
to give you an era because it's added
to this IK rig. I'm just going to delete
this IK rig as well. Now it says there is something running here and
I'm not sure what it wants. I'm trying to save the project. Clicking the content
folder, fix up redirectors, go back to the player
animations and try to delete. Let's actually delete this one. K players going to give me this. I'm actually going to
close down the project and try to open it up
again to see if it works. Okay, here we are again. I'm going to delete this one. And there it goes.
Sometimes Unreal Engine gives you some random errors. Let's not delete the IK target, let's just make it stay here. I'm going to right
click and duplicate my IK manikin and call it
IK player just like before, go inside of here
and just switching out this manikin with our
own counter terrorist. Just like that, everything
is fine. We con save. Let's go back to the IK target. Right now for the IK retarget, make sure the IK manikin is the source and the
target is player. So everything looks
fine. Let's try again. Let's try to run an animation. If we walk back
left, for example. And I'm just going
to hide all of the bones so I can actually
see what's happening. You can see it's not
looking good either. I suspect that the
chains are not mapped. If you click on
the chain mapping, just like I told you before, they have to be similar, you can see they're actually not the same here, I
have to link them. Instead of doing it manually, try to click up here and
click on Map All Exact. And you can see it
maps them all for you. Now let's see what
it looks like. You can see now
it's a lot better. It's actually holding it,
just like the other player, not just holding the
fingers randomly. Here they are, we fixed
the chain mapping. Now you can see the hand for this player is twisted,
as you can see here. It's twisted over here. However, it's not
really your problem, it's just how the
character is made. You can see it's a bit messed
up on this part of the arm. It's fine. It's not really you that has done
anything wrong. Let's just play a couple
of animations just to make sure that everything is
correct before we continue. And just taking a look at it
and everything looks fine, you can even see
this trigger finger is holding correctly, just like this other
trigger finger as well. Okay, so we can always like, if you want the arms and hands to be 100%
like this player, just like before I told you
before, you can go to edit, slightly move the
fingers around if you wish to remember to click
on the character bones and all hierarchy and
you can try to move them a bit around if there's something you're
not satisfied with. And then you can go ahead
and just play an animation. Take a look at what
it looks like, but I think for now
this looks really good. Before you can imagine, or you can remember, that the
arms were flying upwards. Now they are all fine and the fingers are working as well. Okay, so with that, let's
click on the character. Again, I'm going to hide all the bones because I don't really need to see them anymore. And now let's save the project, and let's move on to the next lesson where
we copy the animations.
24. 3.13 Retargeting the Animations: Now we are ready to copy
over the animations. Let's go over to the IQ Targeta. Inside of here, you can see when I click on the animations, just like in the
previous lesson, everything is working fine. Now we are ready to copy
all of the animations. What you can do,
this is very simple. You can click on the first
one and go down select the last one and
just go ahead and click on selected animations. Now you have to select a folder where you want to
save these new animations. I'm actually going to
create a new folder. To stay more organized, I'm going to make a new
folder and call it Assets. This is what I usually
do for my games. I can write click
here and let's go ahead and call the new
folder animations. And then you can go ahead
and click on Export. And now we are exporting
these animations here, and now it is finished. Now if I minimize and go over
to my assets animations, now you can see
they're all here. If I just click on one of them, you can see it is working
with our character. This is looking really good. No, I don't think it's all of the animations
that I can see here. And this is because they're
not using the same mannequin. If I go back to, let's see here, the player and if I go back to my K targeta, this manikin here, you can see if I hold
the mouse over it, it's using the skeletal mesh from the reference 01 folder. You can see here right now it is just the animations
for the pistol. I can see that over here in
the assets animations folder, we have copied all the
pistol animations. You can see at the end
they are called pistol. However, we do have
more animations. You can see if you go into the other animations
folder that we imported, you have the unarmed
and also the rifle. We can't see them.
And why is that? We can only see the pistol ones. This is because the other
ones are actually using other maniquins
for the rifle one. If you just hold
the mouse over it, you can see it's
using the skeleton from references 02 folder, it's actually using
another Manequin. What we can do is
we can go back to the K maniquin inside of here. We can click on this one. If you just hold your mouse over the other maniquins
that you have, for example, this one, it says this one is from the
references 02 folder. Right now we're using the
maniq from references 01, Clicking on the second manikin. Now go ahead and click on Save. Let's go over to the K target. Now you can see in the animations there
are still the pistol. What we need to do
is just click on this arrow just to reset it. Then I'm going to click again
and select the IK manikin. And go ahead and hit Save. Now you can see it is not
the pistol an anymore, it's all the rifle animations to go ahead and select
all the rifle animations. Export selected animations. And I'm going to export them again in the animations folder. Go ahead and export them when
they have been exported. I'm going to go back
to my IK manikin. I'm going to select
the Manikin from the references 03
folder, you can save. Go back to the Ktageta. I'm going to click on the arrow again up here to reset it. Then I'm going to select
the mannequin again, and just making sure it says UA at the end, which
means unarmed. These are all the
unarmed animations. And you can click on it to
see what it looks like. Go ahead and select
all of them again. And go ahead and click on
Export Selected Animations, and export them again in the animations
folder. Hit Export. Now let's close everything, and let's take a look at
the animations folder. Now you have all the
animations here. So you can see when
you click on them, they look a bit silly. And this is not because we
have done something wrong, it's actually the animation that looks a little bit silly, in my opinion, But it's fine. We don't really have
better animations. And these are for free,
and we can use them. So you can see here all of these animations
really, really nice. And we can use them
to create our game. Okay, So now everything is
working for the character. And you can see everything
is looking great. And sometimes we can adjust
some of these animations. You can see when he looks
down on the ground, it is way too much on the
ground, in my opinion. And we can adjust that later. But you can see everything
is working fine. And this is how you copy animations from one
character to another. So let's go ahead and hit Save, and let's move on
to the next lesson.
25. 3.14 Introduction to Blend Spaces: All right, so let's go ahead
and create a blend space. And a blend space is just used to blend two
animations together. And we can use that in the
animation blueprint. Later on. You can see I just
went ahead and colored my blueprint folder just
to see or spot it quicker. Again, remember you can do this by selecting all
of these folders. Right click Go to Set Color, and then click on New Color
and just select the color. This is how you put
colors on folders. Now, inside of the blueprint
folder in the animations. Let's go ahead and
right click here. Go to Animation and select
this one called a blend space. Again, a blend
space is where you can blend two
animations together. For example, the idle animation
and the run animation. We can use those later on
in the animation blueprint. Let's go ahead and
create it for now. Now it asks you to
pick a skeleton. You have to pick the
skeleton for your character. For this one I'm going to
select the MW style one. This is the counter terrorist
and this is the terrorist. I'm going to select
the counter terrorist because remember in
the animations we actually retargeted
the animations to this counter terrorist. I'm going to select the
counter terrorist skeleton. Call it BS for blend space. Then I'm just going to
call it run after that. I usually call it, for example, this one I'm going to make the unarmed blend
spaces because later on we are going to
make the run with the rifle and the run
with the pistol as well. This one is called run armed. Let's double click on
it when you open it up. This is the blend space. Over here to the left, you have a details panel inside of here. You can do things like
smooth the animation, the movement speed, the
movement direction, and so on, but we are going to work more
with that later on. Down here, very, very
important, you have a graph. And here you add all
of your animations. This is where you blend
the animations together, and we are going to do that in the next lesson
over to the right. Don't worry about it too much. We don't really have much
to do inside of here. But down here you can see
all of the animations. If you just double click on one of them, for
example this one, double click on this one, you can see all
of the animations here inside of this
animation player. If you double click on
it, you can see you are outside of the blend space. Now you can't see this graph
if you just scroll around. You can either just open it up again here by clicking here. But you can now also see
it with the animations. You can see it
down here. This is the color for the blend space. You can double click it and open it up again,
just like that. Very, very simple.
This is how we do it. And we can, for example,
click and drag an animation. Let's actually not
use these ones. These are a offset. Let's use these animations. We are going to work with
the Aim offset later. Let's just work with
one of the animations. You can click and drag,
place them into the graph. And then you can see this guy is now walking automatically. And you can drag
another animation and just place it somewhere. And now you can see
they're actually blending. If you hold control on your keyboard and you just move your mouse
from here to here, you can see they are
now blending together. Okay, really cool. For now, this was just an exercise. Let's click on this one, Click
on Delete on the keyboard. Click on this one, click
on Delete on the keyboard. Let's go ahead and save. And let's start from
the next lesson, where we add unarmed
blend spaces.
26. 3.15 Unarmed Blend Spaces: Now we are ready to create the unarmed lens spaces.
Let's start here. What I usually start with is over here in
the details panel. We have a horizontal axis
and a vertical axis. If you just click on
the small arrows, you can see all of
this information. Usually on the horizontal axis, we have the movement direction. Just go ahead and call
it movement direction. You can also see
it changes name. Down here up here we
have the movement speed. This is the vertical axis. Let's call it movement speed. Now for the movement direction, we are going from a minimum
to a maximum value. The minimum is
minus 180 degrees, the maximum is 180 degrees. This is how we can
turn 360 degrees. Now for the movement speed, usually what I do here, for example, this
is the running. If we go over to the character, if we click on the player and
click on the player base, inside of the player
base, we click on the movement component. You can see here that
the max walk speed, which is also the running speed, it is 600 right now. Usually what I do is I set it to about a half of what
is written down here. Because if you write 600, then you have to
reach the speed of 600 before you can transition
fully into that animation. You want to transition to
the running animation, I usually write 300 because when I reach
the speed of 300, which I do really quick
because my full speed is 600, then I transition to the
running speed a lot faster. I usually just make it
lower of what it is. I'm just going to write
300 for this one, for the movement direction. I am going to increase
the grid divisions here because I have more
animations than four. I'm going to write
eight. We have an eight directional movement. You can see now I
have more lines here. And this is how
we want it to be. Now this is the only thing you
want to do inside of here. Let's click on save for
this detail spanel for now. Now over here in the graph, now what you can do is
right now we want to make the run animation for the unarmed down here at
the speed of zero. This is where you have the idle animation at the speed of zero. We're just standing still. Now, over here, if
we search for idle, this one called idle armed. Let's take this one. Idle,
unarmed, let's drag it. And we have to
drop it down here, where the movement
speed is zero. Now if you hold shift on your
mouse while you drag it, you can see it snaps to the grid. And this
is what I want. I want to snap it down here. If you place it, you can see the character is now idling
with an idle animation. Now let's click and
drag this again. Hold shift to snap it. Just go ahead and click
and drag it into all of these grid points down here. Just take the idle
animation all the way here. It's just the idle animation
because the speed is zero. Now over here, when
the speed is full, take the run animation. If I just search for run right
now we are in the unarmed. If you just go here,
you can see this one is called is forward. B means backwards. B L for example means back left, and B R means back
right, and so on. For this one we want
the run forward, but being unarmed,
run forward here. And you can see this
one called unarmed. You can drag this one again, hold shift, and put it up here. Now if you hold control on the keyboard and you
move your mouse, you can see that
you can transition from the Adle animation. And if you move your mouse while holding control
on your keyboard, you can transition to this one. You can see what it looks like. And this is what
a blend space is. Now over here,
actually I'm going to click on this button to
show you the sample names, so you can see what I have placed and it will be
easier for you as well. So over here, instead
of searching for run, I'm actually going to search
for unarmed just like that. I think it will be
easier for me and I can see all my run
unarmed animations. So over here to the right, we have the front right. This one called front right. I'm going to drop it here. Then we have the
right over here. I'm going to take the
one called right. Drop it here. Then this
one is back, right? I'm going to take the back. Right at the end, at the corner is
the back movement. I'm taking the back
and put it here so you can see if I hold control
and I move to it slowly. You can see my character
is transitioning. Just like that, everything
is looking correct. He walks backwards and
then he walks back. For this one is just
the opposite of this. This is the left side, so running front left. So I'm going to take this one
on front left, hold shift, place it and this one is left. I'm going to find left
and then back left, picking this one called back left and this one
called back again. Just like in the
other corner we have the back movement here and we also have the back
movement here. Because we're turning
360 degrees around. All right, so this
is my animation and everything's
looking correct. So this is what it's
supposed to look like. So we have the front movement, and then we have
the left movements and the right movements. And now we are
actually finished with the running on arm, so
you can hold control. See what it looks like
when you transition. Now you have to do this with
the other ones as well. So I'm just going to share
you one more quick example. I'm just going to go
through it quick. Now, if you just go back
to the player animations, let's right click,
go to animations, make a new blend space. Select the character again, the skeleton that we
created, call it PS. This time I'm going to call it crouch because now
we are crouching. And again, call it un armed. The last one, let's
actually right click again. Let's go to animation. Go to blend space,
select the skeleton. This one S walk because now we are walking
and call it unarmed. This one we have
to make as well. Clicking on the crouch again, over here in the
horizontal axis, we have the movement direction. Then we have the movement speed. As the movement, we are
moving from minus 180 to 180. The grid division is eight, because we have eight
movements that we need to add down here for
the movement speed. Again, this one is
for the crouching. Now, crouching is a lot slower
than the walking speed. Again, you can go back if you want to to the
player player base. Click on the movement component and take a look at
the crouch speed. Right now it's 300. I'm just going to put it to 150, a half of that for now. Like later on we are going to change all of this
movement because we have to test the player
in the game and see how fast he's running. And we can always come in here and change this
value here, okay? Now that we have that
over here to the right, now we need this is the
crouch on, crouch armed. We're just going to
write underscore arm, we have all of these crouch for. The first one is the idle one. I'm going to take this
one, anim crouch idle. I'm going to hold shift,
place it down here. Just click and drag
the same crouch idle on all of these
points down here. Because again the
movement speed is zero. We are just idling. Next we have the front movement. We are going to take the
front here, front unarmed. Then over here are
the right movement. This one is front, right,
dragging front right. The other side is front left, front right, front left. Then we have the right here, the right one and the left
one is on the other side. On this one is back right,
dragging back right. On the other side is back left. And then we have the back
movement on these sides. We can again hold control. See what it looks like.
Everything's looking fine. Go ahead and save.
And I'm just going to make the last one and
I'll get back to you. All right, so here I have
finished the walking and I can enable the labels so you can see what I did just like before. The right movements,
the left movements, and also the idle down here. Nothing new. Let's
go ahead and save, and let's go ahead
and close it down. And here we have all
the blend spaces for the unarmed movement. Now later on, we also
have to create it all over again for the
rifle and for the pistol, but let's not worry
about that for now. Let's jump over to the
animation blueprint.
27. 3.16 Introduction to Animation Blueprints: Now we are ready to work
with animation blueprints. Let's go ahead inside of
the blueprints folder. I'm going to go inside of the player folder.
Animation folder. Here. I'm going to right
click, go to Animation. And then select this one
called an Animation blueprint. Now we have to
select the skeleton for the player we're
making it for. I'm making it for this
Cando Terris right now. I'm going to go ahead
and select the skeleton. Go ahead and click Create. Let's just call
it an MBP player. Now let's double click and open up this
animation blueprint. An animation blueprint
consists of two parts. The first part is
this animation graph. Inside of this animation graph, we plug in the animations and you can see if you
hold the right click here, you can pan around inside
of this animation graph, we plug in the animations here. And the second part
is this event graph. Inside of the event graph, we write the code
for the movement. We have the code part, and then we have
the animation part where we add the animations. Let's start over here
in the animation graph, you can see to the
right you have all of the animations
that you can see here. You can even click
and drag it into the animation graph and you can plug them in and
compile and so on. And you can see when
you plug it in, you can see now the player is idling and you can
see the animation. Now we are working with
animation blend spaces, not just these animations
here. Let's delete this one. Instead of just plugging
an animation here, let's right click and let's
search for state machine. Let's select this
one state machine. Go ahead and rename this one. I'm going to call it
Unarmed movement, because later on we are
going to have movement with the pistol and movement
with the rifle as well. Let's take this and connect
it here, and let's compile. And you can see
you get a warning because this one is
empty right now. Let's double click
this state machine we created inside of here. If you click and drag from this, you don't have many
things you can do here. The only thing we want to do
is just create this state. Click on a state, and let's call
this one idle run. And now we can see
you have this state. Now if you double click
this state inside of here, you can now add the animation. Let's just strike this run
unarmed movement here. This is the one we're
working with right now. Let's plug it in and let
us click on Compile. Now you can see the
era has disappeared now. If you want to go back to the animation graph,
you can click up here. You can see you
don't have a tab. You just have to click up here and you're back to
the animation graph. You can see the era
has disappeared. We have connected the unarmed
movement inside of here. And we have this state, the idle run state. Later on we are going
to create more states. For example, if
you drag at state, we're going to create
the crouch state, and then we're going to
create another state. Maybe we want to create
the walk state and so on. But for now, just
the idle run state. Inside of here, we have this blend space that
we created earlier. Now we can see the blend space
wants to take two input. If I go back to the run space inside of here, you can see we created the movement direction
and movement speed. This is what it wants. It
wants these two values. Now if I just write
a static number here in the movement speed, for example, let's say I'm
moving with a speed of 400. And if I compile, you can see the character is
running correctly. If I just change the
direction as well, for example, writing 90 degrees, we can compile that is working correctly as well.
All right, very cool. Now we don't really want
static numbers here, We want to calculate it through
code in the event graph. Let's go ahead and do
that in the next lesson. Let's just compile for now, writing 00 again here. Let's save everything
and let's move on.
28. 3.17 Movement Speed & Direction: To calculate the movement
speed and movement direction, let's go ahead and go
into the van graph. Now inside of here, instead
of starting from here, let's right click now and
search for initialize. And select this one called Blueprint Initialize Animation. This event is, it's just
like the begin play. If you remember, if I go back
to the player player base, we use this one called
the begin play. What should happen if I
begin playing the game? Now in animation blueprints, this is just called blueprint,
Initialize animation. What happens when you
initialize this blueprint? That's the same thing here. What you want to do,
take this function here, try get pawn owner. Let's direct from here
and say is valid. And go ahead and
select this one with the question mark is valid. Now we're asking if
the player is valid, if the player has
spawned into the world. If the player has spawned, we want to right click this promoted to a variable and call it player pawn and go ahead and connect
to the is valid here. Now what we're simply doing
here is we're just asking this pawn here is this player has this
player spawn to the world. You can imagine counterstrike. When you connect,
you have to select if you want to be a terrorist
or a counter terrorist. Now if the player has not yet selected a terrorist
or counter terrorist, the player has not yet
spawned into the world. It doesn't make
sense to do all of this animation code if the player has not
even spawned yet. We're just checking if
the player has spawned, If the player is valid, if the player is placed
inside of the world. If not, we want to wait. Let's just write delay here
and select this delay. We're going to delay the code
by let's say 0.3 seconds. For example, when this delay is complete, we're going to run. This is valid again because
if the code is not valid, if the player has
not spawned yet, we don't want to get stuck here. If we don't add anything here, the code is just going to stop. And I don't want that,
I want this player pon variable to be set
whenever the player respawn. I'm going to keep checking
if the player has spawned. I'm going to delay
the code if it's not valid and then I'm going
to re run this again. And now we can double click
on this one to create re, route nodes in order to make
it a bit more organized. Something like this.
Here we're keeping delaying the code if the
player has not spawned, until the player spawns and it will create this
player pain variable. Now we can take this player pawn variable, we can place it here. If you take it here,
you can either get the variable or
set the variable. Now in order to
just do it quickly, you can hold control
and drag it in that will get it automatically. If you hold Alt and get it here, it will set the variable. These are just shortcuts, holding control and holding
Alt while you drag them. Okay, so we're getting
this player pawn variable. Now let's right click this variable and convert
it to a validated yet. Now what this does is now
let's connect it here. What this does is again we're checking if the player is valid, if the player has pawned. Just to make sure that
we're running this code only when the
player has spawned. Because you can see
if I compile now, now the code is running. And you can see this
is running infinitely, because we have not spawned yet. This will stop running
whenever we spawn. As for this one, this
will always run, the blueprint update,
animation will always run. And it is always nice to
check if the player has spawned because we don't want to run this code when a val
player has not spawned yet. Okay, now to calculate
the movement speed, let's strike from
this player, paw. Let's search for velocity and let's get this
one called velocity. This is simply the only thing
we have to do, actually. However, if I go back here in the animation blueprint and I go back to my idle run state, You can see the plug in. It wants the input it wants, it is a float type variable. It is not a vector.
You can see if I go back to my vent graph,
this is a vector. We can't really
plug it into here. What we can do in order to
turn a vector into a float, we can drag from this one
and search for length. We can choose this one
called vector length, that will actually turn it
into a float type variable. We can right click this
and promote this to a variable now and call
it movement speed. Now let's connect it
here to the S valid. And now we have the
movement speed. This is actually very easy. That's how you do it. You get
the velocity of the player. We did the vector length
because we want to turn the variable into
a float variable. And then we have the
movement speed here. Now in order to calculate
the movement direction, we can drag from here and
search for calculate. And you can see this one
called calculate direction. Like this one now, it
asks for a rotation. What you can do is you can
direct from the player and search for act rotation. This one get act rotation. Now let's go ahead
and plug it in. Now if you're very
new to blueprint, sometimes you don't know what
these functions are called. If it asks for
rotation, for example, you can just direct from here
and you can write rotation. This is what I did
when I started out. When I was fully, I
just wrote rotation and I tried to read what all
of these functions were. Then after that, I
select from those. Now it will take a of
time if you're new. However, this is
just done over and over again and it will become
muscle memory for you. Don't worry about it,
Just keep practicing. We're getting the
actor rotation, we're plugging it into here. We're calculating the direction. Now we can right click this one, promote this to a variable, and call it movement direction. Now we have calculated the movement speed and the
movement direction as well. Let's go ahead and compile. And now we have this code here. Let's go to the idle
run state here. Again, you can click on
the animation graph. You can also click on the
animation graph over here. Or go to the idle
run state over here, to the left, inside of here. Let's strike our movement speed. Plug it into the movement speed and drag the movement direction, plug it into the
movement direction. Let's go ahead and compile now. Before we can play,
you can see if I play now nothing is going to happen because we haven't used the animation
blueprint in the player. Let's go to the player base. Go to the Viewpo, click on
the player or on the mesh. Over here, up here you
can see animation mode. Use animation blueprint,
that is correct. The animation clause,
we have to select our blueprint and let
us click on Compile. And now you can see the player is animated here in
the Viewpoard as well. Let's click on Play,
and let's try it out. If I click on W to move forward, to move backward, move
to the sides as well. I move to all of
the other sites. You can see it is
working correctly. Awesome. The animations we have plugged in is
working correctly. Now as for the movement speed, we are going to change those later on, so
don't worry about it. I can also see
that the player is actually really small
compared to the environment. So we have to fix that as well. But let's not worry
about that for now. Everything is working correctly. And let's jump over
to the next lesson and create the crouch.
29. 3.18 Multiplayer Crouch Input: Let's now create
the input for the crouching inside of
the player folder. I'm going to go to
the input folder. Again, here let's right click, go to Input and create
this one input action. Again, let's call
this one crouch. Now let's open up our input mapping context inside of here. Let's add this new mapping. Now we have done this before. I'm going to go a
little bit quicker, this time creating
this crouch here. For the crouch, I'm
going to click here and use my left control button. Now you can choose any
button you wish to for the triggers, I'm going
to click on the plus here. And I only want
this crouch action to trigger whenever
I press the button. Because if you don't
add this pressed here, this will actually run very
quickly many times a second. Just like the movement here, if you don't add any triggers, it will just run continuously. However, this will only trigger one time
when you press it. And this is just making
the code more optimized. Not only pressed, I
also want to click here and select Released. Because I want to crouch
when I release my button, either pressed or released. Okay, let's go ahead and save this now. Let's close it down. Now let's go back
to the player now. And inside of the player, let's open up the player base. Down here again, right click, search for IA crouch
or whatever you call the input action.
Select the event here. Now down here in
the action value, you have to drag
from here and write a branch and connect
it to the triggered. The true here is going to play whenever you press the button. If I just drag from
here and write a print string and I
just write pressed. Now, it's always nice to add print strings if you're
debucking the code. If you have an era in your code, very, very good to just
write print strings all over your code, like inserting them here in
the middle of the code, see if they work, and so on. It's always nice to debug
through print strings. Now we can debug the Syria
and see if it works. If I press it, it
should say pressed. If I release it, it
should just say released. If I compile, now,
if I click on Play, if I click on Control, just one time, and if I let go, now it says released. You can see press
release. Press released. Okay. Now it is
working correctly. So we can delete those for now, and we can move on
to the next lesson.
30. 3.19 Multiplayer Crouch Function: All right, so let's go ahead
and do the crouching Now, in order to crouch, you have to click on the character
movement component. First up here, just search for crouch and you have to click
this one called can crouch. If you don't have this ticked, you can't really crouch
and nothing will happen. Remember go to the character
movement component, search for crouch and
select this one, crouch. Okay, Now let's click
on this T it again. Now for the crouch,
we can just go ahead and drag here
and say crouch. This will work just perfectly
for a single player. However, we are working
with multiplayer, so we have to run it
through a server. Now in Honorable engine you have something called a
client and a server. If you click up here and set the amount or number
of players to two, and in the Ith mode, you set it to play
as listen server. If you click on play here, now you can see two Windows will open up and now we are
working with multiplayer. Now in Honorable engine, you have the server and
you have the client. Now the server is the true
game. And what does that mean? The server has the
authority of the game. And that means the server can do whatever
the server wants. For example, let's say here
in the multiplier shooter, I have a gun and I shoot my
bullets on this clients. Now on the client, I can shoot the blots,
I can hit the client. However, the client,
when I shoot the weapon with the
client now on the server. This code for the
firing the weapon. It's going to go through
the server and then the server is going to send this information back to the
client and tell the client, okay, you're allowed to shoot. Why does it do that? And this is actually to prevent cheating. Now the server, again,
is the true game. That means all the clients here are connected
to the server. The server can see the game
as it is, for example, where the players are standing, what they are shooting, what
weapons they are holding. However, for the clients, we actually have to send all
of that information to them, from the server to the client. For example, if someone
loots a weapon, let's say we have
multiple clients. And let's fix that
buck later on. But let's say we have, for example, four players. And we click on Play. And they all open up
on my second monitor. So let me just
drag it into here. Now Let's say here
I am, the server, and I have all of these
clients playing with me. Let's say this client here in front of me is going
to loot a weapon. Now the weapon that this
client is going to loot, I have to send that information. For example, if you
loot an AK or a gun, just Agle for example. I have to send that information from the server to
all of the clients. Because if you don't send the information actually only the server can
see that you have looted a deagle and the other clients cannot see that you're
holding a deagle. If you don't send
this information from the servers to the
clients, it will not work. This is why we say that the
server is the true game, has the authority of the game, and all of the information is contained here in the server. And the server needs to send important information
to the clients. For example, if one of the
clients shoots a bullet, this client is going to say, I am going to shoot a bullet. And it's going to send that
information to the server. Now the server is
going to check, does this client
actually have bullets? Because we're trying
to prevent cheating. It's going to send that
information back to the server. The server is going to check, does this client have bullets? Then the service, maybe
it's going to say, yes, this client
actually have bullets. Then it's going to send
that information back to the client and then it's going to say, okay,
you can shoot. Now you actually have bullets
and the client can shoot. This is how we do it here in the client server relationship, the server has all the
information and the client simply receive and send information in order to prevent cheating. All right, this group
session is finished. You can see they are in a group session discussing,
let's quit here. Now we have this era
here, very, very simple. It's just saying access, non trying to read this, get local player subsystem. And it's actually up here.
If you just click up here, take you to here, it
just says axis none. Trying to read this
property here, the only thing we need
to do is just drag from this one and say is valid. And go ahead and connect this
one with the question mark. We're just making sure that
the player control is valid. And if it is valid, we can
go ahead and run this code. The era you get here is because it's trying
to run the code. When the player control
is not yet valid, you will get an error
saying access none. What axis none means
is it's trying to read the variable you
are trying to run. However, access, this
variable is empty. I don't know what
you're talking about. Let's close it down.
Let's play again. You can see if I just play here and this guy fell
through the ground, because they're all spawning
on top of each other. And you can see the era is gone. All right, let's go ahead here before the video
gets way too long. Let's go here in
the crouch code. Here in the crouch code, first I want to
create a function. Let's create a function up here. If you click on the
plus this function, I'm going to call it crouch. I usually write in front of my function names
so I can search for them later on very quickly. Up here. If I also add them over here, I can
see that it is a. If I go over to the
event graph again, I can drag this function here and just
strike two of them. Connect one to the true and
connect one to the false. What we want to do is we
want to add a bullion. This one is because we want to crouch here and we
want to crouch here. I'm going to click on this
function in the inputs, I'm going to click
on the plus and add this bullion called u. As you can see, you can
add a B in front of bullion variables and they
will not appear here. This is usually done
in C plus plus. You can search for
them easier later on. Writing a B will not be displayed in the name if
you do that for bullins. Now for the crouch, I'm
going to tick this one. So I want to crouch here
when I am trying to crouch with my control button and when I release the button
I want to uncrouch, this is said to false. Now if we go into
this crouch function, now it's going to maybe get
a little bit difficult. And you have to
practice this a little bit inside of this function. We can now right
click this crouch and I'm just going
to promote it to a local variable and call
this one Crouch local. Now what a local variable is, it's just contained
within this function. You see if I go to
the event graph, this function or this
variable is not here. And if I go back
to the function, you can see I have the local
variable, Crouch local. This variable is
actually only used inside of here and
it's not used outside. Now, before we do anything, I want to drag from here and
say, switch has authority. This switch has authority. You can see it has
two execution pins. The first one is the authority and the other one is the remote. Remember I told you the
server has the authority. The authority means just that this is the server
that's running the code. Remote means this is the client
that's running the code. As I told you before,
the client has to run the code through
the server and check if whatever the client is
doing is legal before we can continue the code to the server to prevent cheating. But for now, let's do
it through the server. The server can just go ahead and do the code
without any problem, because the server has the
authority over the game. So what we want to
do is we want to check here if this
is true or false, because we set it here
to either true or false. And this bullion will
set this variable here. So I'm going to take
this local variable and drag from here and write a branch and ask if this is true or false and connect
it to the authority here. Now you can either do it that way or you can do it that way. That is fine. Same thing. I just want to stay a
bit more organized. So I connect it this way. If the crouch is set to true, I want to crouch just like that. If it is not true,
I want to crouch. Search for crouch just
like that. Very easy. I'm also going to
create variables that I will use later on in the
animation blueprint. Create a new variable here, a new bullion called crouch. Then you can take this one, you can drag it from
here and set it to true. And drag it here and
set it to fault. We're going to use this one later on in the
animation blueprint, so we can switch the animation. Now we have the server finished. You can see if I
click on play now, and I play as the server and I run here. I click on control. You can see the movement speed reduces, actually now crouching. However, the animation
is not yet plugged in, so you can't see the
crouch animation. Now it is actually working. Now for the client,
what we need to do, we need to run this code through the server first to check if the player
is cheating or not. Let's go back to
the event graph. Let's right click and
search for custom event. Let's create a custom event. Let's call this one
SRV for server. And I will call it crouch. Because now I want to run
this through the server. Inside of this event,
let's click on it. And now you can see replicates. What you need to do is click up here and run this on the server, and click on Reliable. Now we're running this event
here through the server. Let's take this crouch here again and simply
just connect it. And connect this
bullying to here. And it will automatically create this variable
inside of this event. Now we're actually running
it through the server. What we need to do is
we need to go back to the function here
from the remote. We need to take it
from here and search for server crouch
event we just made. Now for this input, we just connect it here, create a rear route node just
to stay a bit organized. Now it's running
through the server. After it run through the server, it can now run this code
together with the server. Okay, this was it. We can now compile, and
that should work just fine. If I click on play, now I am the server and I
click on control. You can see I'm crouching,
I'm moving slowly. The same thing with the client. I can move and I can
click on control. And I move slowly as well. You can see on the server, I'm actually also moving slowly. This means that it is
working correctly. Both of them are working slowly. Just to go through it
very, very quickly, it might be a little bit
confusing to begin with. We created this crouch function, We added the bullion
to either crouch or crouch when we press the
button or release the button. Inside of this function, we have basically
just the bullion out here setting
this local variable. Then we have the switch, has
authority checking if it is the server right now that we are playing As or the client, if it is the server, you can just go ahead and run the code. Now if you are crouching, we are going to crouch here. If you are not crouching, we are going to crouch depending on the value you
have set out here. Now if you are client playing, you have to go through the
server first and checking with the server what this
value is that you here. So it's going to run
through the server. Depending on this value
that you plugged in, it's going to take
this value and either crouch or crouch as
well on the client.
31. 3.20 Crouching Animation Blueprint: Now that we have the crouching working inside of our
blueprint character, let's go ahead and
do that inside of the animation blueprint. Let's go to the
blueprints folder, the com player animations. And let's go into the
animation blueprint. Now inside of here again, you can go back to the
animation graph over here. You can click on
your state machine. Inside of here, we need
to make a new state. Let's strike from
here and let's right. Or click on this one state here. Let's right crouch Now we're going to make
the crouch now. You don't have to
make it down here. You can also just drag it
here to the side or up here. I just like to
drag it down here. For the crouch. I just imagine that I'm crouching,
going down here. And then we can double click on this crouch state
over to the right. We made this one crouch unarmed. We can drag this lens space into the graph and then
we can connect it. Remember we already made the movement
direction and speed, so we can drag and
plug them into here. Then let's compile.
Now we get an error or a warning here because we
have not made the transition. Let's go back here in
the animation graph, you can go back to
your state machine. And inside of here you
see now this circle. And this circle is
a transition rule. You have to tell your game. When do you want to go from the idle run mode
to the crouch mode? You have to give
it a transition. Now if you double click it here, you can see here
is the transition, the bullion, so we have
to give it a transition. And the way you do this,
first you have to go to the event graph and do some code before you can
give it a transition. You have to know when
the player is crouching. Now if you go back to
our in the player base, you go back here in
our crouch function. If you don't click here. We
made this one called crouch. This bullion here,
Remember it's not the local that we made. It's this one global bull
variable that we made. This one we can use to know
if the player is crouching or not and we can use it here inside of the
animation blueprint. First we have to get the
reference to the player. Right now this is a player pawn, but we need a reference
to the player base because now we need to
use this bullion here. Let's go back here and go back
to the Interfaces folder. Let's right click go to Blueprint and make a new
blueprint interface. Let's call this
one in layer base because we want to reference
to the player base. Let's open it up. And here, inside of this
blueprint interface, just like for the
player controller, if you don't remember, you can go ahead and watch the Player controller interface. When we made it here, it's
actually the same thing. You can click here,
click on two to change the name and say get player, getting the player reference. You can also just call it get
get player base reference. That's the same thing.
Then you can click on this function
here in the output. Go ahead and make
a new variable. Remember here you
have to select what Eva you are trying
to reference to. We're trying to reference
to BP player base. Go ahead and select it. Let
me just call this one player. I can compile now. And going to the player base. Going to the class, actually in class defaults, the class settings in here, in the interfaces, click on Add and search for the
T player base. This one compile and you
will see this interface. Remember, if you don't see this, even though you have added it, you have to compile inside of the interface
before you can see it. Very important clicking on
the Get player reference. And here we can drag again and write self just like before. Because remember we are
in the player base. We're just telling
that this variable here is this player base. Now we can go to the.
Let's compile first. Now we can go to the
animation blueprint. And here we already
have the player pawn. Instead of just
dragging from here, let me just create
a new variable. I'm just going to
drag it over here and place it and click on Get. And I'm just going to use it here instead of
dragging from here. I think it will look a bit messy when the lines are
over all of the code. Let me just take it here as
a new one and say layer ref. Now we have this get player ref. Let's go ahead and connect it. Now we can use the variable. Now if you drag from
here and right crouch. Actually a small trick
I want to show you. If you're right
crouch and you want to use the bullion variable, variables are always
found down here. You can see this is the
crouch variable that we need. However, if you don't see it, you can always make
a space and write variable VAR for variable and you'll be able to
see all the variables. Just a small trick
to find it quickly. Getting this crouch
variable that we have made. Now I can right click
this variable promoted to a variable inside of here
in the animation blueprint. And I'm just going to call it, is crouching just like that. Or you can just call a
crouch the same thing. Go ahead and connect it
and click on Compile. Okay, now we are
taking this crouch. We're taking the value of
it here in the player base. So if it is true or false, we are taking that value and putting it inside
of this variable. Now we can use this variable
for the transition rule. If I go back to the
animation graph, to my state machine and
to this transition rule, you can go ahead
and click on it. Now it's asking
you, when should I go from the idle
run to the crouch? And we can drag from here
and plug it into here. When we are crouching
is crouching is true, then we want to go
ahead and transition. However, let's go back. We have to click on this
and drag from here. And plug it into here as well. Because at some
point we have to go from the crouch back to idle, going and clicking on the
second transition rule. This is going back
from crouch to run. I'm going to drag this
and in here we can write N B and this
one called N bullion. Basically what we're saying
is if is crouching is false, then we want to go back to the running mode because
we're not crouching anymore. It will be false
when evalu are not crouching because we set it here to falls in
the player base. Let's go ahead and
compile. And now you can see all the errors are gone. Now let's see if we're
missing anything. We have made everything here plugged in the movement
direction and speed. Let's actually just try it
out. Let's click on Play. And I'm going to click on, actually I'm stuck
here as the player. Let me click on play
again. Now I'm walking. As the player here, I'm going
to hold control to crouch. And you can see I am
crouching. It is working. But you can see on
my other screens, I am not crouching. This is because we are now
working in multiplier. You can see I'm
crouching as the server, the others cannot
see. I'm crouching. However, if I take this
client here and I crouch, you can see the
server can see I'm crouching just like that if
I'm crouching as the client, but if I'm crouching as the
server, I am crouching. However, the clients cannot
see that I'm crouching. And remember in the
previous lesson I told you we are working
in multiplayer. And the server has to send the information back to the
client and tell the clients, hey, I'm crouching now,
update my animation. The server has to send that information over else they cannot see what I'm doing. And this is what we
will be doing in the next lesson with the
variable replication.
32. 3.21 Variable Replication: Right. Let's go ahead
and fix the crouch. Now before I do
that, I'm going to click up here and
select two players. Because I don't want to load too many players all the time. If I click on Play, you can
see here just like before, if I crouch on the server, the client cannot see. I'm crouching, I, I'm
crouching on the client. The server can see on the, the server itself
that I'm crouching. Remember like before, we
have to send information to the client and tell the client that right now I am crouching. This is very easy to do. So if you go to the
player base is crouching, this is basically what's going wrong right now in the
animation blueprint. If we go back to the
transition rules, we have these transition rules taking from this bullion here. This bullion controls if we
are crouching or not here, The variable, this
information inside of here, needs to be sent to the client. If you click on it, you can see the variables can be
replicated as well, not only the events,
You can see the event. We have replicated it before
to run on the server, but variables can
also be replicated. If you click on this variable, you can see the replication
here is set to none. But we need to send this
information to the client. The client also has the
information if we are crouching or not clicking here and setting this
to replicate it. And it will have the symbol up here because it's replicated. And now I can click on Compile. Now, very important to know, variables can only be
replicated through the server. You can never take
a variable here. For example, if, let's say I'm on the client here
and I paste it like this, you can never do this. It cannot be replicated
through the client, variables can only be
replicated on the server. Very important to remember
that you cannot set a variable and replicated
through the client, never going to happen. Here you can see it
is running through the server because we
have this switch has authority and it's
running through the server and replicating
as well as the remote, it's actually running
on the server because it's running
through the server first, and then we are
replicating this variable. So this was actually the only
thing that we had to do, just clicking on it and
setting it to replicate it. Now, if we could complain, now as you can see, I am the server. Now if I just
maximize this a bit. So you can see if I
crouch as the server, I am now crouching on both
the client and server. And if I am the client
and crouching as well, I'm crouching on the
client and on the server. Sometimes it's also
nice to click up here, go to Net mode, and
play as two clients. So go ahead and play. It's always nice to
test it both ways. So as server and client, but also as client and client to see if they can
actually see each other. If I crouch on the client, the other client
can see me as well. It is working and let's go back and switch it to
play as listen server. For now, let's go ahead and save everything and let's
move on to the next lesson.
33. 3.22 Animation Smoothing: When I go ahead
and play the game, you can see my animation
is not really smooth. So if I walk around, you can see it transitions very quickly as well as like when I crouch
here, it just happens. All of a sudden I
can actually smooth this out a little bit
and make it look good. And it's actually just one
adjustment that we have to do. If you go to the player and
click on the animations. And you click on, for example, this blend space run. You have this one down
here called Weight Speed. If you put it on
something very low, like one, for example. And you can click on play and
you can see what happens. You can see if I begin
walking, running, you can see it transitions
to that running animation. If I stop, it transitions
back by run, it transitions. You can see now it's very
smooth when I run and stop. So we have to put it to a
number that looks good, not too much smoothing. If you increase this number, it is going to be less smooth. Usually something around
56 is really good. Five right now it's a
lot better than before. If you put it to
something like three, this one weight speed,
let's put it to three and let's click on play. Sometimes I don't like to put it way too much down because the character somehow feels
heavy when I walk around. But you can see it is now transitioning a lot
more than before. I think three is way too low. So we can go ahead and try
four and click on play. And then we can run around
and see what happens. Four is still too heavy. I think five was a good number. Or for the smoothing
here, if you just run around like this, it looks good. Maybe even 5.5 I don't like
it to be way too low here, 5.5 I don't like the character
to feel way too heavy. Let's do that with
the other ones. Let's click on the crouch, put the weight speed to
5.5 And click on the walk, put the weight speed
to 5.5 as well. Let's go ahead and
click on File and Save All. Let's click on Play. And you can see now
when I'm running, when I'm crouching, it
is smoothing as well. You can see the
difference actually for the crouching a lot more. I think if I said the
crouching to zero again. And if I click on play, you can see it
transitions really quick. When I'm crouching,
it's almost unnatural. If I put it on 5.5 and I
save and I click on play. Now when I crouch and do this, you can see it's a lot
more smooth than before. It doesn't feel unnatural. Just a very small
adjustment that can make your animations look a lot better when you are
smoothing them out.
34. 3.23 Multiplayer Walk: Now we are ready
to do the walking. Now the walking is the
same as the crouching. If we go back to the player
and go to the player base, it's actually the same process as what we have been doing
here with the crouch. Try to do this alone if you can, and try to see how far
you get without my help. It's a very nice exercise if you want to continue with me, let's go ahead and continue. I'm going to go ahead in the
input and make a new one. Let's go to Input and
click on Input Action. Let's call this one. I walk. And let's go ahead
inside of here. Inside of here, we don't
really need to do anything. Let's go to the input mapping
context inside of here. Let's click on the plus and
add it down here as the walk. For the walking, I am
going to hold Shift, clicking on this one, clicking
shift on my keyboard. As for the triggers, I'm
going to click here, two pluses, and the first one is pressed and the second
one is released. This button will trigger
whenever I press it to walk and whenever I release
it to stop walking. Now let's go ahead
and save here. And let's go back to the
player base in here. I'm going to write,
click and write a walk and select newly
created input action. Now for this one,
just like before, let's drag from this
bullion and write a branch from the true. We will be walking because this is when we
have pressed shift. When we release the shift, we will stop walking
here from the false. Let's make a new function
just like before. I'm going to call this one walk. Let's go back to
the event graph. I'm going to drag this walk here and connect it here.
And drag it again. And connect it down here. Now again, just like before, we need a bullion to either
walk or stop walking, I'm going to compile
and click on the input and call
this one B walk. Now for this bullion,
I am going to set it to true when
I want to walk, and I'm going to set it to
falls when I stop walking. Now just like before,
I want to run it through the server
when I am the client. So I'm going to right click
down here, say server walk. And remember to set the replicates to run
on server and reliable. Now let's go ahead and
take this walk connected, and let's take this input for the bullion and drop it into the event for it to automatically create
this variable here. Okay, the majority is finished. Let's go into the walk
function inside of here. Let's right click this one and promote it into a
local variable. And this one we can
call walk local. Go ahead and drag from here
and say switch has authority. Now, just like before, we want to run the code
through the server first. If we are the client drag from
here and say server walk, the one we just made and now we are running it
through the server first. Remember to take this and
connect it with the walk double click to make a
re round node and just make it a bit
more organized. Now let's take this
local walk variable and drop it into here. From here, right, a branch
and let us connect it. Because we have to ask,
is this true or false? Because if it is true,
we want to walk. If it is falls, we
want to stop walking. We want to maybe start running. Go ahead and connect everything it needs to look like this. Now from here, what we basically want to do
is you can see in the character movement
component we have something called
the max walk speed. This is just the
same as running. I don't know why it's
called walk speed, but it's actually also the
running speed for this one. This is what we want
to adjust when we want to walk and not walk. What we need to do is take this character movement
component and take from here and say set max walk speed. This is what we want to adjust. We want to connect it here. Of course, it doesn't
really need to be high. If you go to the character
movement component right now, the running speed is 600. When we want to walk, we need to reduce it to a lower number. I can actually just
right click this one, Promote this to a variable. I'm just going to call
this one walk speed. I don't like to have
static numbers like that. Let's compile and click on this walk speed variable And
set it to something like, let's just set it to 100 or actually just 200 for
now, random number. We are going to change it later when we are
not walking anymore. Let's just take this
by, paste it here. Let's promote this to a variable
again and call this one, for example, a run speed. Go and put it down here and
connect the falls to it. When we are not walking anymore, we are going to set it
back to our run speed. And click on the run speed. Remember to set
the default value. Go ahead and compile First it asks you to compile
the blueprint. Go ahead and compile and set it to 600, just like default. And now we are running again. Now, just like before,
I need a bullion to use inside of my
animation blueprint. I'm going to make a new
bullion here, bullet walk. Now I can take this pull in and set it to true
when I'm walking. And I copy paste it down here. And set it to false
when I'm not walking. Now remember this has to be replicated so the client
knows if this is true or false for the animation
blueprint to go ahead and set this to
replicate it as well. With that finished,
we are finished and we have to move ahead to
the animation blueprint. But let's just try it
out. Let's click on play. And if I click on Shift, you can see I'm walking now. I'm walking slowly. The animation we need to
fix in the next lesson. But as you can see, if
I release my walking, I can run again. This is very, very cool. Let's go ahead and do
the animation blueprint.
35. 3.24 Walking Animation Blueprint: Now for the animation blueprint, let's go ahead and go to the player animation and open
up our animation blueprint. Now inside of here,
remember inside of the animation graph
state machine, let's drag from here and
create another state. Let's call this one walk. Now for this one, let's double
click it and open it up. Just like before, we created
this walk blend space. Let's go ahead and
connect it here. And let's drag the movement
direction and plug it in and the movement
speed variable. And plug it in as well. Let's go ahead and
click and compile Now. Let's go back here. As you can see,
just like before we have to set the transition rule, we actually have to go to the
event graph first and get that bullion we just made before from the same
interface here. We can drag and
say walk variable. We can get this
bullion from this one. We can write click
and promote this to a variable and call it, for example, is walking. We can call it is walking. Let us go ahead and connect it. Double click this to
make a reroute note, make it organized,
just like that. Let's compile and let's go
back to the movement here. Now for the transition rule, now we are transitioning
from the run to the walk. We can drag, this is walking
into here, just like that. If we are walking, we want to transition
from run to walk. Let's go ahead and compile. Let's go back again. We have to drag this
from here to here, because now we
want to transition from walking to running. If we are not walking anymore, drag this and get it and say bullying if you are
not walking anymore, Meaning this walking
bullying will be false, then we want to
start running again. Go out and click and compile. Now this is going to work. If you click on Play and
you can click on the shift, you can see how I am walking. And everything is working
awesome. Everything is working. You can test out the animation if something is wrong
with the animation. You have probably done
the blend space wrong. But you can see everything is
working in all directions. However, there is a
problem right now. If you click on crouch and you click on the walk button
at the same time, now it is not walking,
it's not transitioning. This is because you have
to drag from this to this as well to create
transition rules. If you are crouching
and you want to go ahead and start walking, I'm just going to
drag this a bit away so there's more space,
more organization. Now go ahead and click
on this transition rule. What should happen? When should I transition from
walk to crouch? You can take this is walking
and get it here again, just like before bullying. If I am not walking, right now we are transitioning
from walk to crouch. So we're not walking anymore. I'm not walking anymore, but I am crouching. If crouching is true, but running is false, and we have to drag
from here and say, select this bullion, go
ahead and connect those. If you are not walking anymore
and you are crouching, go ahead and run this
transition rule. Let's go back here and
let's strike from here, from the crouch to the walk like that and
double click on it. Now, when should you transition from
crouching to walking? This is if I'm not crouching
anymore, Taking this one. If I am not crouching anymore, just like that, I am walking. I want to transition
to the walk. If I'm not crouching
anymore but I am walking, I want to transition. If I go ahead and
click on play now, you can see if I crouch. If I hold the shift to walk
and I let go of the crouch, you can see I am walking. We can transition from
walk and crouch as well. However, you can see there
is still a small error. You can see if I crouch, hold, shift to walk, and
see I'm walking. But if I hold control to crouch, you can see my movement speed is slightly higher because I'm
actually crouching right now. It's taking the crouching speed. This is something to do
inside of our player, in the player base in here, we said this run
speed and walk speed. We're automatically
running this walk speed here whenever we are walking, even though we are crouching. This is a small
era and I want to introduce you later
on to enumerations. And we can make this
system a lot more clever, but for now,
everything is working. And let's move ahead
to the next lesson.
36. 3.25 Multiplayer Jump: Do the jumping. Let's go ahead
in the blueprints folder, go to player input. Let's go ahead and
make an input action. Just like before. You can right click here, go to Input and create
an input action. Let's call this one
jump inside of here. We don't really need
to do anything, let's close down
the input action. And let's go into the input
mapping context instead, let's minimize all of those so we can see what we're doing. Let's click on the plus
up here and add the jump. If you search for jump and you select the input
action you just made. As for the triggers,
just like before, I am going to click
on the plus here and I'm going to
select the press. Whenever I press, let's
choose the space bar. So I can click here and
click on the Space Bar. So whenever I click
the space bar, this input action
will be triggered. Now that this has been added, you can go ahead
and click on Save. Let's close it down, and let's go over to the player base. Inside of the player
base where we have all of our movement
here in the event graph, you can right click
and search for a jump, and then you can select
this jump event. Now for this jump event, what we want to
do is simply drag from here and right jump. And then you can select
this function called jump. Now in order to make this work, actually this is already
working as you can see here. We did all of this
with the walking and with the crouching, but the jump in Unreal engine is already replicated
and in multiplayer. So you don't really need
to do more than this. You can see if I compile now and if I click on play and you
can click on the space bar, you can see I'm
jumping right now. The animation is not
correct because we haven't set anything inside
of the animation blueprint. But as you can see
here, if I jump as the client it works and if I jump as the
server, it works as well. Jump inside of Wheel Engine
is already multiplayer. You actually don't need
to do more than this. However, before we do this, I just want to make sure
that the player can't spam the jump button when they
are already in the jump. Because you can see
here, if I drag from here and write print string. Always nice to use
a print string to debug so we can compile
and click on Play. You can see if I just
spam my Space button. I can spam the jump even
though I'm in the air. To fix this, just to
make it more optimized, we can take this character
movement component we can drag from here
and say is falling. What that basically is basically telling if the player
is in the air or not. We can take this here
and now I'm going to say not for not bullion. What we're saying is
we just want to jump whenever my character
is not falling. This means that the
character is not in the air and therefore
I want to jump. If the character is in the
air, I don't want to jump. We can drag from here and
take this and make a branch. We can drag this a
bit away so we have more space to work with
and connect it here. What we're saying is if my
character is not falling, meaning my character
is not in a jump, we want to go ahead and jump. If you compile and click on Play and spam the jump button, actually, let's
write a print string here so you can see
what's going on. Let's compile, save, and play. If I spa my Space button, you can see I can only spam it whenever I land
on the ground. It only triggers once. This just makes the game more optimized just to make it
a bit more clean here. What you can do, this
is optional of course, but what you can do
is you can over over these nodes and you can write click and say collapse
to a function. Now this function you
can call, for example, is not jumping. Instead of making it with the inputs here,
execution pins. This one is basically
just getting information if you double
click on this function here, if you double click on it
and you go inside of it. And I'm just going to
organize this a little bit. You can see we're just
getting some information. We're not setting
any new information, we're just getting if the
player is falling or not. Instead of having
these execution pins, This doesn't really
make sense for functions that just
get information. We can click on the
function and select pure. Pure just means this is a
function that gets information. We don't need to run it
through the code because we're not really setting
anything new here. We can just drag them together. And now you're saying if
the player is not jumping, you can go ahead and jump. And you can see you can
make things a bit more clean if you collapse
them to functions. So you can go ahead and
click on Compile and Play, and just test it out. And everything is working on both the client
and the server. And let's go ahead and do
the animation blueprint.
37. 3.26 Jumping Animation Blueprint: Do the animation. Let's
go to the animations. And inside of the player
animation blueprint. Now inside of here I'm actually going to click here
and right click and close the tabs to the right
just so it's more clean. Again, I'm going to open
up the animation graph. Open up the state machine
that we made inside of here. For the jumping, we
need three states. For the first one
you can drag from here and you can
create a new state. This one I'm going
to call jump start. Then you can drag
from here and make a new state called
jump loop or jump air. And you can drag from
this one and make a third state called jump end. Now for the jump end,
you can take this and connect it back
to the idle running. Now we have three states and we need to add the
animations to them. How this is going to
work is when I jump, I have a jumping
start animation. If I click on it and I just search for jump here
in my animations, you have this one called
Jump Start Unarmed. Just make sure it's
the unarmed one. Click and drag this into
here and connect it. If you want to see what
the animation looks like, you can always
double click on it. And this is what it looks like. We have an initial jumping
animation that we are going to go through before we go to the animation where
we are in the air. Let's go back here. Now that we have connected this,
let's go back, click on the jump air and take this one called
Jump A unarmed. And put it here
for the last one. Let's go back the jump end. Let's take the jump unarmed. If I can find it, this one
actually jump land unarmed. We can take this and connect it and go ahead
and compile, Okay. Now, just like before, we have to set these transition rules, let's click on the first one. The first one, basically
when we are in the air, as we did here in
the player base, if you go back as we
did here for the jump, if the player is falling, it means we are in the air. This means we actually
want to jump. We have to go first in
the event graph and code that in here as the player, just like what you did
in the player base, you can drag from this and get the character
movement component. And then from the character
movement component you can drag and say is falling. If we are falling, you can right click this
and promote this to a variable and you can
call this one is in air. This means we are in the jump. You can also call it
is jumping if you want to ahead and compile Now
inside of the animation graph. Let's go back to the jump
here. This transition rule. Let's take this is in
air and connected. Now we are transf,
I go back here. We're transitioning to the jump start whenever we
are in the air. Whenever we click this
space button over here. From the jump start to the
jump, we can utlick this. The function we want to use here is called time remaining. If you're right click and
search for time remaining, this one called time
remaining ratio. Just make sure it's ratio. You can drag from
this and say less, less than here and then
you can connect it. What we're saying here
is we want to transition from a jump start
animation to the jump, a animation whenever
the time remaining of the jump start animation is less than whatever number
you plug in here. For example, if I plug
in 0.5 and I compile, let's actually
continue this and I can show you later
what this is doing. So let's go back here
for the jump here. If I click for the
transition rule between the jump
air and jump end, but this one, we are going to land whenever we are
not in the air anymore. Because you can
imagine the player is jumping and then the player is landing again on the ground. When the player
lands on the ground, we want to play this jump end animation when the player
is not in the air anymore. So we can get this say not bullion, and we
can connect this. When the player is not
in the air anymore, we want to go ahead and play
the jump end animation. Now for this one down
here, just like before, we want to write
click and search for time remaining ratio for the jump land when it is less than some
number we input here. Then we want to
go ahead and stop the jump end animation and
go back to the add run. For this one I'm going to
write 0.5 again and going to compile now we can go ahead
and try it out and see what happens if you click on
play and maximize this here. When I run and I jump, you can see I have a
jump start animation. I also have a jump
land animation. You can see it more
clear if I put this number to
something very low. If I go back to this one as well and put it to
something very low, you can see it transitions. If I click on play jump, it has a jump start animation. And it has a jump
land animation. And see that jump land
animation is more visible. Now it looks like the player is sliding on the ground when
the player lands. This is how you control
it over here for the time remaining ratio,
if you click on it, the higher you put this, the quicker the animation
is going to cut off. If you put it very low, you can see the animation
is not cutting off quickly. And it looks like the
player is sliding. However, if you put it
to something very high, for example 0.9 you jump, you can see the player
is not sliding anymore. The jump animation will
cut off a lot quicker. When this is a higher number, you just have to
sit here and adjust this number as well
as this number. For the jump start,
you just have to click on Play multiple times, try to jump, see
what works for you, see what looks good, and try
to adjust these numbers. I try to play around with this, and the number that
fit best for me for the jump start is 0.8 If I
go back for the jump end, it is 0.9 That is correct. So let's click on Play and
see what it looks like. Now if we jump, you can see
this is what it looks like. You can always adjust them
a bit more if you wish to. But I think this is a good
starting round for the jump. Now what you can do as well. You can see here if I
click on play and I walk around holding shift to walk
around and I click on jump. The animation is not playing. This is because, remember you have to transition
from the walk. You don't have a transition
yet to drag from the walk and transition to
the jump start from here, you can see this transition
rule just like before. Just like what you did
here for the idle run, you use the Is in air bullion. You have to click here
and use the same thing. If you are in the air,
you can transition from the walk to the jump. Now, I'm not sure if I want to transition from the
crouch to the jump, but you can add that
mechanic to your game, but I don't want
to add it for now. I don't think I will
have it like this. So you can click on play now, and you can walk pressing Shift, you can click on space. And you can now see
it transitions to the jump animation when
you are walking as well.
38. 3.27 Introduction to Enumerations: Right now, I want to switch something with the
movement here. You can see if I click on shift and I walk and if
I hold control, you can see I can't really crouch while I'm
holding the shift. If I hold shift to walk and I hold control at the same time, I'm not really crouching. I have to press shift and
then I have to let go of shift and then press C. I
don't really like that. I like, for example,
if you click on Crow, you press on shift
at the same time, it's going to walk
here like this. But it's not doing
this right now. I have to let go of the
button and then I can walk. And I have to let go
of the walk button. And then click on, on the
crouch before I can crouch. And I don't really
want to do that. Let's go ahead and fix
this and make the system a bit more advanced so it
can take inputs like that. What we're going to use
for this is enumerations. In those lessons, I just want to introduce you to enumerations. You can go back to
the blueprints folder and you can right
click here and make a new folder and call this
one enoms or enumerations. That's up to you. You can right click this folder,
set a new color, and just use the same color as before inside of this
folder. Let's right click, Go to Blueprint and select this one called an enumeration. Go ahead and make it,
and I will call it as a prefix and I'm going to
call it movement states. And you can open it
up and you can see an enumeration is basically
just a list of items. You can click up
here to add an item. If I just click here
a couple of times, you can see it is an enumeration is just a list
of items that you can make. It can be a list of
anything, for example, a list of groceries, a list of weapons, a list of movement states. As we're making here just a list of anything you wish for. It can also be a list
of items you can loot or a list of which portions
you have in your game. Anything you can make a list of, you can create them here. Clicking on these icons, you can remove the list items. For the first one,
we're just going to make a list of
movement states. The first movement state
that we have is running. Then you can click
up here again. Then we have walking. Now, it doesn't really need
to be in a specific order. You can do, for example,
running first and or the walking first and so on. But right now we have
the running and walking, and we also have the crouching and you can
go ahead and save. So very, very simple and enumeration is just
a list of items. In this case, we're creating a list of the movement states, and we will be using those in the next lesson to make the system a bit more
advanced for the movement.
39. 3.28 Switching Movement Variables to Enums: Now that we have created
the enumeration, let's click on the Player. Let's go inside of
the player base. Now let's go back to
the event graph here. And I'm going to drag this
tab over to the side. So it has a bit
more structure like that for the first one. For example, for the crouch, let's go into the
crouch function. Inside of here, You can see we are crouching and we're setting this bullion to C
and not crouching. We're going to make
this system a bit more advanced so it can
take multiple input. Let's go ahead and delete
these bullions for now. I'm going to drag this down
so I have more space to, Let's create a new variable. This variable, we're
going to call it movement state for
the variable type. Instead of just making
these default variables, you can also make variables of anything inside of the game. For example, you can make a variable out of the
enumeration we just made. If you just search
for movement states, you can see here, this is
the enumeration I made. Just make sure you search for the name as you have written it, for the file. Movement states. You can see here, if I go
back to the enumeration, it's called movement states. Now I have this as a variable and I can
click and compile. You see if I take a look
here at the default value, you can set the list item
here for the enumeration. You can set it to one of these
states if you're running, if you're walking, if
you're crouching and so on. You can click and drag it
into here and write set. You can also see the
enumeration here. You can set it to one
of these list items. You can see this is very
good and we're also going to use it later
on for the widgets. When we're creating the UI, we can make a list of UI. For example, main menu, pause menu, escape menu. We can make the game Main UI. And so one you can
make a list of anything it's really
useful to use here. Instead of just having it like this as a
standard variable, I want to give it
multiple values. You can see if I
connected, I want to walk, instead of just crouching, you will set this variable
to walking instead. However, this will
just be like before, There isn't really a change. You're just setting it
to walk and not walk. And you're setting it to
crouch and not crouch. Now I want it to have multiple input. What
you want to do. Instead, I want
to click on this, on the type here of which
variable type it should be. And I'm going to select an array instead of
a single variable. Now what an array is compared to a single variable or
the single variable, you're only able to
set it to one value. For example, if I set it to
walking over in the walking, this will override this
value that I have set here. For the crouching for the array, you can imagine it as a box and you have multiple
input inside of here. You can see if I compile. And when you switch it into an array and you click
on this plus here, you can see you can
have multiple inputs. You can have the
running, the walking, the crouching at the
same time an array, you can imagine it as a box. And you're putting all of these
values inside of the box. However, if you have just a
single standard variable, it's just one item you can set to either walking,
crouching, and so on. But for the arrays, again, you can imagine it as a box. You're basically putting all these items
inside of your box, and you have all of these
values stored for you. Another use for an array is, for example, which items do
you have in your inventory? For example, you can have a sad, you can have a shield and so on. So you can have multiple items
inside of your inventory. You can see arrays
are very nice, or if you have
multiple items that you want to store for now, let's delete everything here. And let's compile
for the crouching. Let's drag this
crouching into here. What we want to use
is if you drag, you can say set array
element for the arrays. If you don't know all
of these functions, you can basically just drag
from here and write array. I do that sometimes if
there's something I forget or don't know about,
you can write array. And you can see, you can see all of the functions
for the array. It can clear, it can find an item you're asking
if it contains an item. You can find an item. You
can get a specific item. You can ask if this array is empty and you can
do something with it. You can get the
length of the array. You can see we have a lot of functions that you can
use for the array. The one we're going to use
is called set array element. We are going to set an item. Now you can also use this
one if you drag and write a, for example, write add here. And you can write the crouching. When we are crouching,
we're going to add the crouching
to it, the item. However, this one is working
great in single player, but I have a lot of issues
with it in multiplayer. Sometimes it will not add and I try to debug my code for hours, and it's actually just
this one bugging out. Nothing wrong with your code. This one is really bad
to use in multiplayer, it has a lot of bugs, so I'm going to delete
it and use this one. If you want to add items, use this sit array element instead to go ahead
and connect it. What I want to set is
when I'm going to crouch, I want to set the
item to crouching. I'm going basically what I'm
doing here through code. When I click on crouch, I'm adding this
crouch to my array. Okay, go ahead and make sure you have deleted all the
default values for now. So now we are setting
the crouching. Now for the index, it just asks you where you
want to set the crouching. If you click on the array
and you click on the plus, you can see you have
an index number. And if I click on
the plus again, you can see you have
another index number. Arrays start at index zero, and the more items you
add, it will increment. It will be index one, index two, index 345, and so on. So it starts at index zero. It doesn't start at index one. Very important to know now for the index instead of
just having it as this will be a
problem. Because if we take this and copy paste
it into the walking, and we also set the
walk to index zero. You can see here that it
will overlap if I'm walking, let's say, let's say
I'm crouching here. I press the crouch and I'm going to delete all
of the other ones. This one I'm going to
delete as well as this one. Right now I'm
crouching. It added the crouching to my index zero. Now if I click on the
walking at the same time, it's going to overlap
my crouch here, The crouching value, because it's going to set it to index zero instead of
overlapping my values. What you can do is you can
take from this and say, last index. It's going to take a look at what is
your last index number. Right now, my last
index number is zero. If I added these items, for example like this, my
last index would be three. It's going to find the last
index you can take from this and save loss and add
one to it like this. And then you can add
it into the index. What you're basically
saying is find the last index number three for example, incremented by one. Here is where you want
to add this new value. You're never overlapping
your old movements. I'm going to delete all of this. Compile now click
on Size to Fit, because this will basically make room for the new
state you're going to add. Okay, now we have this here. Now for the crouch, if we don't want
to crouch anymore, you can take this crouch state and you can drag from
here and say remove. And you can choose
this one called remove item and you
can connect it here. When we're not
crouching anymore, we basically want to remove the crouching from this item
or from this array here. When we are crouching, we're adding the item to the array, to the last index plus one, which means we're
not overlapping the last item that we added, which maybe could be walking
or running and so on. And then when we're
not crouching anymore, we want to remove it from this array because we're
not crouching anymore. Okay, let's compile. Let's just copy paste all of this here. Copy and paste it
to the walking. I'm going to delete the
movement speed and the walk. We're going to add the
movement speed later on. Make it more lever as well. We'll delete all of
this. Let's paste this code, connect it, and for this one, go ahead and select the walking instead. If we're not walking anymore, we can take this and say remove item just like
before and connected. And you can remove the walking. And go ahead and organize
it a little bit more. Right, so we have the walking, now we're adding the walking. Just make sure you have the correct values
for the walking and for the crouching as
well. Crouching, crouching. When we're crouching.
We're going to add the item when we're walking. We're going to add
the item as well. However, now for the running, we don't really have
a place where we can add it for the running. What I want to do is I just
want to add it by default. If I click on the
movement state, I want to click
on the plus here. And I'm just going to add
the running as the default. Because when I'm walking or when I'm not crouching
here and I'm not walking, I'm basically running around. I just want to have this
movement state as default. When I'm not crouching
and walking, it will run automatically. So you can see here, when
I'm starting to walk, it will add this walk to
the last index plus one, which means zero plus one. It will add the walking
down here and it will never overlap my
running movement state. Now that we have this finished, we're actually finished
with this system. You can see it's a little
bit more advanced, but it is going to work a
lot better than before. And you can see when we
make an enumeration, we can reduce the amount
of variables that we make. Because now for the crouch, you can go ahead and
click on Delete. You can just delete this. And for the walking as well. Now you can see we only have one variable for the crouching and for the walking later on. If you want to create a sprint
variable for your game, you can go ahead inside
of the enumeration, add the sprint variable, and for the sprint again, just like before, go ahead and make it a function
for the sprint. Like the crouch and the walking, you can add the sprint
just like that.
40. 3.29 Switching the Animation Transition Rules: Now that we are finished
with this system, let's compile, save everything. Let's close this down,
and let's go over to the player animation
blueprint instead. Now inside of here,
we get a couple of errors because we have deleted the crouch and the walk in the event graph of
the animation blueprint. You can just go ahead
and delete these ones, the crouch and the walking, because we don't
need it anymore. You can compile and you can
see the errors are gone. What we want to
use here instead, we can direct from here and say movement states that we want to use this array
that we created. Go ahead and get this array. You can write lick it promoted to a variable and just call it movement state here inside
of the animation blueprint. Go ahead and connect
it. And connect the is in Er together with it. And go ahead and just make
it a bit more organized. Now when we compile,
it gives you an error. I'm not sure what it
really wants here. If I just compile again,
you can see it disappeared. I don't know, that was
just a random error. Let's go over to the
animation graph. Inside of the animation graph,
let's go inside of here. Now we want to switch all of the movement states
for the first one from the idle to
walk, for example. You can click this here using this bullion
that we used before. Let's go ahead and delete it. Let's take this movement state. Now for this array,
what you can do is you can take it from
here and say get. We basically just want
to get the walking. Remember, if I go back to the player just to
explain it a bit better. Instead of the when
we are walking, we're basically adding the
walking item to this array. Now, for the blueprint here, the animation blueprint, we
want to get this walking. We don't really know
what index it is at, because it might
be at index zero. It might be at index one. Remember, it can never
be at index zero, because at index zero
we're always running. So it can be at index one or two in order to
know what this is. Instead of just getting, you can drag from this one
here and get the last index. Remember, we used this one
in the previous lesson, and then go ahead
and connect it here. Now we're getting
the last index. Remember whatever the last index is is the current
button you're pressing. If I'm pressing on the walking, my last index would
be walking here. If you get this
and you're asking get the last index
for this array, this last index is equal. So you can write an equal sign and select this
equal enumeration. If this last index
that you got from this array is equal to
walking, this is true. It means I am walking. Because the last index,
if it is walking, it means I'm currently pressing the walking button
and I want to walk. I want to transition
from idle to walk past this here and go
back and go to this one. We're going from the walk to the idle instead of using
this one is not walking. You can copy paste
the code you wrote before and you can just
switch it to running. If the last index is equal to running means that we're
not pressing the walking, because we removed
it from the array. And we're not pressing
the crouching as well. Because we removed
it from the array, we only have the
running state left. If it is running, then we can go ahead and run
and this will be correct. Okay, just go ahead and copy
paste this to all of them. This was for the walking. Now for the idle to crouch, you can click on this. Instead of this
one is crouching, you can paste it again. Select crouching, connect it. Go back and from the
crouch to run, again, delete this past, select
the running and connect it. You can see it's a lot
easier to use actually, but this one from
the crouch to walk, we can delete all of this. We don't need it from
the crouch to walk. This means we're walking.
We can select the walking. And connected the same thing
from the walk to crouch. This means we're crouching. We can select this and select
crouching and connect it. Now we have switched all of those. We have switched these. And this one is
just for the jump. We don't really need to
switch anything here. Let's compile and
let's click on play. Let's test it out. You
can see as the player, I can click on the
control, I can crouch. If you hold shift
at the same time, you can see I can now walk while I'm holding control and
shift at the same time. If I let go of the shift to crouch again, you can
see it's working. And if I let go of the control, I am walking here now, the movement speed
is not correct, and we need to fix that later. But you can see I can now
press multiple buttons. If I let go of the shift
now, I can walk normally. I can hold shift again, hold control at the same time. You can see we can now hold
buttons at the same time. And it will do this action instead of before we had
to let go of the button, before it can do this action. All right, so let's test it
out on the client as well, just to make sure it
works in multiplayer. For the client, I can crouch, for the server, I can crouch and it's not
working just like before. If you remember what I said, we have to replicate the
variable before it can work. So if we go back to the player and I click on the
movement state, and I click on Replicate. And replicated and compile and click on play as the survey. Again, if I crouch,
you can see it works. And if I walk, it works again. We can also test it for two
clients just to make sure. Play as client and play. Now we have two clients. If you do the movement,
it works correctly. Now again, to fix the
movement speed later on. But now you can see everything
is working correctly.
41. 3.30 Fixing the Player Size: Before we continue fixing
the movement speed, we have to fix the
character size. Because right now you can see as the character, if I walk around, I'm a very small character and
we have to make it larger. I'm not sure if it's
my map that is very small or if it's
these characters that I imported from the marketplace.
They are very small. Either way, it doesn't
really matter. What we have to do is we have to increase the player size. That will be the
easiest solution. Let's go ahead and click on
the player base on the mesh. Remember, you have to do
it in the player base. It will automatically apply it to the terrorist encounter, terrorist clicking
on the player base. Clicking on this character, I tried to test a
bit with the sizes. I tried just to scale this up a couple of times to
see what is best here. But if you click on the mesh
and you click on this lock, you can see if you just
write a number here, the y and the z is not
scaling together with the x. It's not really
scaled uniformly. You can click on this lock. This means if you
change a number, it will change it
for all of them. Far right, 1.7
here, for example. And you can go ahead
and click on Compile, and you can click on Play. You can see if I
walk around now, I am very large compared
to the environment. You can try to test
out different sizes. Try to run around
your environment and see what it looks like. I think this is maybe
a bit too large. I'm going to decrease it to 1.6 Go ahead and compile
and click on Play. And try to walk around
now in the environment to see like your height is
compared to the boxes. You can even go around
here and maybe walk on this ramp to see the
size and go up here. I think this is a lot
better than before. I'm going to use this 11.6
if we have issues later on, we can always change
it and fix it later. We can just change
the number here. However, I think
this is good now. We also have to fix
this collision capsule. Because if I run around now, maybe I go over to this
part and I walk into here. You can see I overlap
with everything. And I can jump into the wall. And this is because you
have to increase the size of this collision capsule again. If I click up here and
go to the right view, for example, I can increase
the capsule half height, I can click on the character. Move the character down so
the foot is at the bottom. Here you can see I have to
increase it a little bit more. So if I click on the
collision capsule again, increase it, maybe
something like 150. And I can click on the character again, Move the character down. It fits a lot
better than before. Now, it doesn't really
have to be precise. We're going to make a
better system later on. But just clicking
here, make sure the foot is at the bottom. Here, you can click on
this collision capsule. Now you probably have
to make it wider. You can click, click
on the front view, Now we have to make the
radius a bit wider. And I'm just going to
make it a bit wider than these arms so they don't
collide into the objects. Something like this,
maybe 60 precisely. We can go ahead
and click on play. Now we can walk around. It is a lot more
precise than before. You can try to walk
into here and you can see it will not allow
you to. We have small box. If you click on control,
you can walk here, but I can also leave the control and you can see I'm
overlapping now, we have to fix these
small issues later on. But you can see generally
everything is working fine, the character size is a
lot better than before. So let's go ahead and continue.
42. 3.31 Setting the Movement Speed: Now that we have improved
our movement system, let's go ahead and set
the movement speed. Let's close this down. And I'm going to go back to the player in the player base. Inside of here, what I want
to do is make a new function. Let's click on the plus up here. Let's write F, set movement
speed for this function. Simply what I want to
do is I want to take this character
movement component and set the max walk speed. This is simply what
I want to do now. I want to set this max
walk speed depending on if the player is running
or if the player is walking, or if the player is crouching. Now the way we can do
this is we can direct from this one and say select. And you can see this
one called select. This is the first time
we're using this one. And this one is really, really useful in games or here basically in every game
you make in real engine with blueprints lets you select an option depending on
what you plug in down here. Let's say for example, you're
plugging in a weapon here. And depending on which
weapon you're plugging in, you will have like the
shooting speed or you will have how many bullets you have in that gun and so on. So very useful note
to use in this case. We're going to set
the movement speed depending on if we are running, crouching, or walking, we actually need this
movement speed again. Let's get the last
index just like before. Remember the last index is
the latest button we have pressed and let's
drag from out here again and say get
and get a copy, and let's connect this one. Okay, so now we're getting
the latest movement. We are pressing on the keyboard and let's drag from this
now instead of before, we dragged from this and wrote equal and did it like this. Now for the select, now we're going
simply just to get the last index and see what the player is
currently pushing. And we can drag from this
and plug it into here. And now you can see the
running, walking and crouching. And the reason you see
this is because it's simply taking it from this enumeration that
we have written. If you add more stuff to this enumeration will also
add more options to here. Whatever you add into
this enumeration, we can see very useful now, whenever you are running, you can have this
run speed variable. You can drag it in and plug it into here whenever
you are walking, you can plug it into here
whenever you are crouching. We don't really have one yet. Let's just right click this one, promoted to a variable
and call it crouch speed. Let's go ahead and compile now. For now, I don't really have
specific movement numbers, we're going to
adjust those later. For example, for the running, you can write 1,000
for the walking, you can write 500
for the crouching, you can write 150. This is just to see if it works and you can go ahead
and make it more organized. All right, for this one
set movement speed, what I want to do is let's
go back to the event graph. And let's start with the crouch. For the crouch, we're
doing the crouch here. And then we need to take this set movement speed
and set it over here. Also down here, we need to set the movement speed as
well, dragging it here, set the movement
speed because when we're not crouching
anymore, again, we need to get the
last index and see if it is run,
walk or crouch. We need to do this as
well for the walking. Let's again drag the
set movement speed. Plug it in. And the same thing down here, Set movement speed. Now for the running, it
doesn't matter because if we remove the
walk and the crouch, it will be running here as the last index and it will go
and take the running speed. Okay, let's click on Play and test it out and see
if everything works. So here I am as the server. I'm running actually
here for the run. You also need to
change it first. Here in the default in the catal movement component
for the max walk speed. Since I wrote here that the max walk speed would
be 1,000 by default, let's write 1,000
here as well for now. So they are the same here for
the walk speed, 500, fine. Let's click on play
again, tested out. Now I'm walking and
it's really fast. We're going to
adjust this later. Crolick, shift to walk. You can see everything is working crouch and
shift at the same time. You see there is a mistake, a fight crouch or a press
crouch and then press the walk. You can see the movement
is still the crouch. The reason why this is is
because when you are crouching, you write this, you
have this one crouch. You never crouch unless you actually remove your finger
from the crouch button. We actually, when we crouch
and we walk at the same time, we are still in
this crouch state. We actually need to crouch in order for the movement
speed to be correct. Let's go back to the
set movement speed. Let's actually crouch if we are crouching to
make it look correct, what we're going to do is we're just going to copy this here. And I'm going to extend
this here, copy paste it. What you need to do is you
need to drag from this and say equal and we need to see if
it is equal to crouching. We need to ask, is the player
currently crouching or not? If the player is
currently crouching, we need to just write
this crouch again here. If the player is crouching, meaning if the last index
is actually walking. Even though the player also
presses crouch button, but the last index is walking, the player is currently walking. We need to actually, let's connect it later on. We can crouch. When we
remove the walking, let's connect them here.
This is the crouch. And here we crouch. And we can just go ahead
and plug it into here. Again, I'm just going
to do click and make a rear out node here and I'm
going to plug this one here. Yeah, that looks correct. Now if I crouch, it's going to set the
crouch again here. If I'm not crouching, let's say I'm pressing the walk button the same time as I'm
pressing the crouch, it's actually going to crouch. And then I'm going to
apply this walk speed. However, when I stop walking and I'm still pressing
the crouch button, it's simply just
going to crouch here. Let's click on Play and see. Let's click on Shift to Walk. Now you can see if I click crouch and I click
Shift at the same time, you can see the movement
speed adjust correctly. If I leave the shift
again and I crouch, you can see the
movement speeds are correcting here and they
are walking correctly. If I shift, crouch
and then shift, or then first shift
and then crouch, you can see it's also working. Our movement speed is
working correctly. Now what we basically did is we made this function
set movement speed. Now we're asking if the
player is crouching or not. And the reason we do
this is if we're not doing it and we're pressing
first the crouch button, we're going to apply
this crouch function. However, if you're
still pressing the crouch button and then
press the walk button, it is still having this crouch applied
because you never crouch, never let this button
go for the crouch. Basically it would apply the
wrong movement even though have set the movement for
the walk speed as well. We're just asking here, are we crouching or not? If we are crouching,
just continue crouching. If we're not crouching, make sure to on crouch
before you do all of this. Because if you don't on crouch, you're still up here. We're just making sure that we're applying the
correct movement. Now that the movement
speed is finished, we can save everything and we can move on to
the next lesson.
43. 4.01 Aim Offset Blend Space: Now we are ready to
create the Aim Offset. For the player to
create the Aim offset, let's go back to
the player folder. Inside of here, let's
go back to Animations. And let's right click
here, Go to Animation. Now we have something
called an Aim offset, but we also have a
more simple one called an Aim offset one D. This is the same thing
as the blend space. You actually have something
called a blend space. One D for this one, I'm
just showing it to you quickly For
the blend space. For example, you can see before we had the
eight way movement, but one D is just going from walking to running a
very simple blend space. Now for the Am offset, let me delete this one
right click again. Instead of doing
the eight movement, let's go to legacy and
use the Aim offset. One D. I'm going to
select my skeleton again and calling it a
O stand unarmed. Let's double click on this one. This is the Aim offset. The Aim offset,
very, very basic. We just have our aim here is the center where
we're looking forward. And the player is
looking down over here. And the player is
looking up over here. What we need to do, just
like the blend space, we have a horizontal axis. This is our direction. We can write direction. The minimum value
for the direction is -90 This is when we
are looking down, the maximum is 90, this is when we are looking
up for the weight speed. I'm just going to apply
just like before what we did with the blend spaces. I'm going to apply a bit of smoothness so it looks better. And now we are ready to apply the animation. Let's
save everything. Now you can see I have imported for you the Aim offsets as well. If you take one of them for example, let's just do this one. You can see when I
try to drag it in, it says invalid additive
animation type. So we need to fix that. And let's move on
to the next lesson to fix this additive type.
44. 4.02 Preparing the Aim Offset Animations: Before we can use
our Aim offsets, we have to prepare them. So let's go to the
assets animations. And this is where all
of your animations are. Remember, it's not inside of the animations the
one I gave you. It's inside of these ones, the assets, animations that
we re targeted earlier. For example, let's search
for an animation offset. If you just write AO up here, you will see all of
the animation offsets. Now you can click on one of them and here you can see
this one, for example. This is the pistol looking
forward, crouch center pistol. For this one, you can
see the additive type, this is what it
was talking about. This one, you have
to click here and set it to mesh space. Then you have to click here and say selected animation frame. Now you have to select the
idol for this animation. The idol for this animation is the pistol crouch idol,
we can search for here. If you just search for idol, this one here,
animation crouch idol. Make sure to choose this for
your retargeted skeleton and not the default manqin
animation crouch idol pistol. This would be the
correct for this one. Let's go ahead and
save now for this one. You can see if I
close it down and I go back to my
player animations. Open it up here,
you can see if I go back to the sensor pistol, if I can find it here. This one here. Crouch
sensor pistol. Now if I drag it into here, you can now see it's working. We have to do this
with all of them. You can see that
the other ones are also invalid for
the additive type. Let me just delete
this one for now. And we have to do
it for all of them. Now, there is an
easier way to do this. If you click on
the Assets again, animations, you search
for the AO again. Now you can click the
first one, Hold Shift. Click on the last one, you can write click
Go to Asset Actions, and then click on Bulk
Edit via Property matrix. Inside of here, you can edit the settings for all
of them all at once. A very handy trick to do it. Here you can see
you can also edit other settings such as the
compression, the animation. You can edit stuff like this, but for now we're
just interested in the additive
settings in here. Let's see here, the
additive animation type. You can click here and set it to mesh space for all of them. For all of them, you
can click here and set them to selected
animation frame. Now for the base pose animation, it can't be the same
for all of them because some of them have a
pistol, a rifle, and so on. So let's close everything down. Now that we have the
basic settings set, we can go ahead and
save them first. Now what we can do, for example, let's start with
the crouch pistol. Clicking on this one. I'm
also clicking on this crouch pistol down
and crouch pistol up. We only have three for each
pistol center down and up. We can now click on them here, right click Acid actions Bulk
edited via property matrix. Again, we can go to
the additive settings. Click this button here,
these squares here. We need to find
the idle animation for this grouch pistol. We can see it is
the crouch pistol. We need to find the idle. For the crouch idle pistol. Now it is correct.
Let's close it down. We have to do it as well
for the rifle here. Click on the rifle crouch, rifle crouch, and
rifle crouch as well. Right click at Actions Bulk
Edd via Property matrix. Go to the additive settings. Click on the squares. Now we need to find the crouch. For the rifle idle crouch, rifle here. Close it down again. You can see it's just
the same method, but we have to do
it multiple times. Now it's for the
unarmed. This one. This one and this
one. Right click, bulk edited via property matrix additive settings. Click here
and then search for idle. Now we need to find the
crouch for the idle, unarmed, just like this. So I'm just going to do the same thing for
the stand as well. And I can see this
one has a wrong name. So I'm just going to rename
it before I continue. This one is called AO,
stand down unarmed. Instead of this,
now I'm going to apply it for the stand,
just like the crouch. And I'm going to skip ahead. Right now, I have prepared
all of them so you can see if you just
search for one of them, for example the AO stand
rifle, you can click on it and now you can see
you have applied it Animation Idol rifle. Just make sure you're applying the correct idle animation,
else it will be wrong. So I did it for all of the stand here as
well as the crouch. Now let's save everything and let's move on
to the next lesson.
45. 4.03 Adding Animation to the Aim Offset: Let us now create the Am offset for the
unarmed movements. Let's go over to the blueprints. And I'm again going back
to the animations folder. I actually, let's do it
for the stand first. Before we do the others, let's click on this stand
unarmed inside of here. Remember we did the
direction and we did the smoothness
in the weight here. Now what we can do is we can
search for AO for this one. Now it is the stand unarmed. I need the unarmed movement. So the stand starts
from here to here. I need the center First, let's take the center unarmed. This one click and
drag and hold shift, and then it will snap into here. Now for the -90 in the
direction this is looking down, we need this one
called stand means unarmed click and drag and hold shift to snap
it into this corner. Then for the up movement stand, unarmed, hold shift,
and plug it into here. Now when you click on
control and move your mouse, you can see this
animation offset is taking action. This
is looking great. We can always adjust
how far he's looking down and how far he's looking
up later on if we wish to, if we think this is
looking a bit ridiculous. So we can always make it
like this instead of this. We can always
adjust it later on. But for now, let's
save everything. This is working now let's
do it for the other ones. I'm actually just going to right click this one and duplicate it. And let's call it grouch arm. Now for the walking, it's actually the
same as the standing. We don't really need
one for the walking. Now that we have
this duplicated, let's double click on it. Let me just delete
this one for now. Now this is the crouch. Let's search for
the crouch here, crouch center arm, and
the crouch down arm, and the crouch up arm. Now you can see this
is working as well. Okay, let's go ahead and
save everything now. We are going to do
it later on for the crouch pistol
and rifle and so on, but for now we don't
really need them. Let's colosso down now. Before we can apply
these animation offsets, we have to calculate
the aim direction. We need to know in what
direction the player is aiming, if it's up or if it's down. And let's do that
in the next lesson.
46. 4.04 Calculating the Aim Direction: All right, now it's time to
calculate the aim direction. And we can do it very simply
by going to the player. Now going to the player
base inside of here, let's actually make
a new function. Let's make a new function
called calculate aim direction. For this function,
let me just compile it and let me go back
to the event graph. The place I want to place this, it makes most sense
for this look event. This is where we control the mouse movement
when we are in game. This would make more
sense to put it here, actually, after this one, let me just drag this, calculate a direction, and
just plug it into here. Now basically what we want to do is set a float called
aim direction. Let's make a new float
called aim direction. And let's change it
into a float variable. Whoops, integer. Float, compile and save. Now inside of this here, let's take this aim direction. We simply want to set it. Now remember what I said
before, in multiplayer, you can never set a
variable for a client. You need to be on
the server to set a variable and then set
it to replicate it. You have to set this
one to replicate it, because the clients
need to know at which direction the other
players are aiming at. The animations update correctly for all of the
connected clients. The server needs to replicate that information
back to the clients. Else the clients will
not be able to see at which direction all of
the players are aiming. And they will just
be looking forward. And it's like nothing
is happening when you set variables and put
them to replicate it. You can never set and replicate variables
through the client, has to run through the server. Now you can see if I write
a print string from this. Now I will give you
a trick to know when you are on the server and
when you are on the client. Right now, it should print a string automatically
when I move my mouse, because I have connected
it here and it will be connected here
if I compile now, and I click on play
and I move my mouse. When I move my mouse,
I'm on the client. You can also see I'm
playing as the client up here so the client can
actually run this code. When the client is
able to print code, it means this code that you are writing is also
running on the client. You can see when I
play as the server, actually it's the second client. Now let me change it up here
to play as listen server. Instead, let me click on Play. Now I'm playing as the server and you can
see now it's the server printing the string on the screen when I am
playing as the client. Let me just play again
and take this client. Now you can see the code is
now printing as the client. When you can print a string
through the client as well, this means this code is run by both the server and the client
and not the server alone. When we need to
set this variable, we have to make sure that we
are running on the server. What we can do, again,
just like before, take this and say
switch has authority. We're making sure that
we're only running this on the server client. You still need to run the code. If you are the client, you have to run through
the server first. Let's go back to
the event graph. I'm just go back down here. We're going to
organize this later. Down here we can write
a custom events, then run this
through the server. And I'm going to call it
Calculate a Direction. And let us run this on the
server and being reliable. And I'm going to
take this calculate a direction and
connect it to here. Go ahead and compile
now let's go back to the calculate
a direction. And let's run this server, calculate aim
direction down here. And then we can
continue the code. When you are the client, you are going to go through
the server and run this. And this will make sure that as the client you can never
run this one alone. It has to go through the server. Okay, So now for
the aim direction, how we can calculate
this is first list, right click and say
control rotation. Now we're getting the rotation
for the player controller. Then we can say
get Acta rotation. We have the rotation for
the player controller and we have the
rotation for the actor. Now what we can do to
find a middle point, We need to find
this middle point in order to know where
the player is aiming. We can take this and say delta and choose this one
called delta rotator. You can plug this in, it's through the player
controller rotation and the actor rotation. It's going to find
a middle point through this delta rotator. Now let's break it
here, rotators. When you break a rotator, you can see the X, Y, and Z. You can also just do it. If you write, click here
and say split struct pin, that's actually the same thing. I'd just like to split here. So I'm going to write
break, Break rotator. And I can see the XY and
Z for the aim direction, we need the y, the Y You can take it and
plug it into here. Now you're actually calculating the aim direction correctly. You can go ahead and compile
and save everything. Now we are ready
to apply this to the animation blueprint and make our player having
the Am offset work.
47. 4.05 Adding the Aim Offset: Let us now go ahead and add the aim offset to the
animation blueprint. Go back to the
animations folder and open up the player
animation blueprint. Here I'm going to go back
to the animation graph. And from here let's
actually disconnect this. I'm going to show you
a trick with this one. For this state machine, you can actually
drag and say Cache, and then click on this
one. Save Cached. Let me call this one
Unarmed Movement Cached. What this is, it's just
taking the locomotion, this whole state machine, and it's saving it
through this cache. It's saving it inside of here. Instead of taking this one, we can actually just use the
cache. Let's put it up here. Instead of using it again, let's right click and
say unarmed movement. You can see you
can use this one. Used cache unarmed
movement here. You can now use this instead
of this one up here. Let's right click
and search for AO. Let me actually remember
what I called it. Let's use this 10 stand unarmed. Let's search for
O, Stand unarmed, and make sure it's this.
01:00 A.M. offset player. A offset player, stand armed. Just like what we
called it here. We called it the AO stand arm. Let's go ahead and connect
this as the base post, the unarmed movement with the
unarmed animation offset. Let's go ahead and
connect it here. As for the aim direction. Remember, we already
calculated this. We need to go to the event graph and we need to drag
from the player and we need to search for the aim direction.
This one here. Let's again promote it to
a variable here inside of the blueprint and
call it a direction. Let's connect it
here at the end of, of the graph. And let me just double click and
make it a bit nicer. All right, let's compile. And now I can go back
to the animation graph. And inside of here,
the direction I'm taking this aim direction, plugging it into here. And now let us compile. Now when we click on play, let's see if it works.
And you can see it works. Now if I look down
and if I look up, it is actually working.
48. 4.06 Adding Player Camera to Head: Now when we go ahead
and play the game, you can see the camera is
just floating around and it's not really following the head when we
look up and down. In order to do this,
let's go back here. Let's add the camera to
the head of the character. To do that, we need to find the skeleton for our
character right now. It is inside of the marketplace, inside of military
character Silva, and this is the skeleton that
we have been using so far. Let me just double
click on it here. Inside of this skeleton, let's find the head bone. You can just go over here and try to search for the head bone, and you can see it's down here. You can also just
search for it up here. A third method is to click
on the character up here. Go to Bones and go
to All Hierarchy. This will show you all the
bones for the character. You can just go ahead and
click on the head bone. And you can see it will
also be selected here. I want to click on the character
again and go to Bones. And select it only so I can
remove those bones again. Now that you have
selected the head bone, let's go ahead and right click
here and create a socket. Add a socket for a socket. Is it's just an
empty holder that you can use to
attach items to it. In this case, we're going to use this holder to attach
our camera to the head. You can also imagine you can use this for weapons as well. For example, if let's
say you want to attach an AK 47 to the
side of the character, you can always add a
socket to the side of the character here,
maybe to the hip. And then you can attach the weapon as well
through a socket. But for now we're just
going to add a camera. Let's right this head bone, go to Add socket. And let me click on it and click on two on my keyboard
to rename it. And let me call it for
socket and camera. Okay, this socket camera, we have it now, let's go
ahead and lose everything. Now let's go back
to the blueprint. Go to the player and
go to the player base. Okay, Inside of here. Let's go back to the viewport. And now we want to
attach this spring to the head or to the socket camera that we just created here
in the sockets, you can see in the
details panel, when you select the spring, you can see the socket
section and you can also see that it is
attached to nothing right. Now, if we click on this folder, you can now see the socket. Now if you don't see this
is because you don't have this spring inside of
this mesh component. If I drag this outside
here like this, you can see if I click on this folder, now
nothing happens. You can see you have to put the spring arm into
the character. It's a child of this mesh. Before you can actually click
here and see all of this, you can also click on the
condo terrorist, for example. When you click on the
counterterrorist, you can't really click here on the spring for the
counterterrorist, you have to do it
through the parent. So in the player base,
this is possible. You will have the spring
arm inside of the mesh. And then for the spring arm, we can click here and then
we can select the camera. Remember, if you don't
have anything in the mesh, for example here you have none, you have cleared
it and you don't have a character standing here, then you will not find
the socket here as well. This is why in the
player base we need a character to
be inside of here, because we need to click here and then add it to a socket. Click on this camera. Now the camera is attached
to the character. You can see it's actually
moving with the head movement. It's actually attached. Now
it's more realistic now. Now it is floating.
Let's click on the spring for the
target arm length. I'm going to write zero, since it's a first person game. Then for the location
and the rotation, just click on these arrows to reset the location and
the rotation as well. You can go ahead and compile
and save everything. Let's go ahead and click on Play and see what it looks like. You can see we're inside of the head of the
character right now, but when I look
down and I look up, you can see it's
following the head. Now when I stand still and take a look like
in front of me, you can see it's following
the head as well. The camera is moving slightly
the same thing when I run. It's actually moving with the
same movement as the head. Okay, now it's attached
to our player. Let's go back and let us now
try to adjust the socket. If you open up the
skeleton again, I go back to the military
character Silva, open up the skeleton. And inside of here, let's
click on the socket camera. And I'm going to just go in front here and try to
adjust the socket. You can see for the socket, when you have
selected it, you have the relative location as well. You can click and drag here. And I'm just trying to
adjust it close to the eyes because the camera
is realistically close to the eyes
of the character. Maybe ten in the X and
in the Y and the Z. It is fine right now. Let me, let's go ahead and play again to see
what it looks like. Now we're inside of the
head of the character. If we look down, if we
look up, it looks fine. However, the characters
head is in the way. I can also see the sides of the character is in the way.
Let me actually go back. Let me just push the
camera slightly forward. If you click and
drag this, you can see you're sliding
the camera forward. However, I don't want to
slide it forward too much. I'm just going to write
five instead of zero. Let me just try to play again. It looks better. Now, however, we can still see
parts of the head. Thing is, we can't see the body inside of our character here. Everything is looking good. However, the head is in the way. Let's actually go
in the next lesson and remove the head
for this character. Only the enemy can
see your head, but you as the player
cannot see the head, it is like this
inside of the camera. Let's go ahead in the
next lesson and do this.
49. 4.07 Hiding the Player Model Head: To hide the characters
head for the player, you can go to the player again. And let's open up
the player base. What we want to do is remove this head for me as the player. When I play my
character, however, the enemies can still see
my head on top of here. The reason why I
remove the head for me because when I'm the first person character
here, I have the camera. It's actually inside
my head, right this, and I don't want to see all
of this, it's not necessary. Now let's remove the head for the player that's
playing the character. Let's go to the van
graph inside of here. Let's just do it up
here in the begin Play. When we start begin playing
the game over here, you can right click and
you have a function called hide or by name. Hide bone by name.
And select that. And it's going to create this mesh variable for
you automatically. This variable is simply
from this mesh variable. You can just click and drag
this in. It is the same one. Okay, so let's go
ahead and connect it. Now it asks you, which bone do you try to hide? Now if you go back
to your skeleton, you're trying to
hide the head bone. If you just click on it, you
can see it's called head. You have to write it exactly
as it is written here. It is upper case sensitive. You have to write it
exactly as it is here. If I just write head like
this and I click on Compile, and if I click on Plate
to play the game, you can see the head
is gone for me. And I can also see
it on my shadow. You can see the head is gone. And it's actually
looking better. Now as the first person
character I can run around, everything is looking nice, nothing is bugging out.
Yeah, it is amazing. However, the side of the
character, I can see this, I think it's the radio
of the character that's actually appearing
for us to fix this. You can always go back
to the player here if you have something for your character that's still showing. And click on the
socket for the camera. And then you can click on the Y again and just increase it slightly until it's
not bugging anymore. If you just increase
this to something like ten and you click on play. And if I look down
and I walk as a side, you can see I cannot
see the radio anymore. However, don't increase this way too much because if you
increase it too much forward, the camera is actually going through walls. If I
click on play now see it's clipping through walls because I've increased
it way too much. Don't increase
this one too much. Maybe instead of five, I want to try six and see
if that fixes my problem. If I walk around and I still
see the radio slightly, I can increase it
to seven Instead, try to click on play again. Try to play with the minimal
value to see if it fixes it. I can see that seven is the
number to go with for me, and everything is looking good. However, you can see my
shadow, I'm missing the head. So we also need to fix this. Let's go ahead in the next
lesson and fix all of that.
50. 4.08 Adding a Third Person Mesh: Okay, now let's fix the
missing head on the shadow. So let's go ahead and
go to the player base. Let me inside of here, how we can fix this is we can actually add another
third person mesh. If you click on the
mesh and you go to Add and you search
for skeletal mesh. Now if you don't know
what a skeletal mesh is, if you're new here, it is simply a three D model
that is animated right now. For example, the mesh for your, your character is animated. This mesh, if you hold
the mouse over it, it says skeletal mesh component is simply just a three D
model that is animated. This is a skeletal mesh. Go ahead and create it again. Let's call this one
third person character, or third person mesh,
inside of here. What we want to do, again, we want to select the character and we have to select
this one style, one male like this one. Then we have to select the
Animation blueprint up here. Animation blueprint player. Now you can see it's animating exactly like our mesh over here. What we actually want to
do is this character. We don't want our own
player to see this one. If you click on play, now you
can see the head is back. The reason why the head
is back is because now we have this mesh that
we're seeing in game, but we also have this mesh. Now this third person mesh, we don't actually want people to see it because I'm only adding this to see my
shadow on the ground and correct it from
the other one. To hide this for
all of the players, we can click on this
third person mesh. And then we can go down and try to go to the
rendering settings. You can see in the
rendering settings, you can click on Hidden in Game. Now it is hidden in game. If you click on play, you can see now
the head is gone. However, my shadow is also gone. I need to fix that as well. If you click on the third person mesh again and
search for shadow, you have this one
called Hidden shadow. I can see the shadow
of my hidden item, my hidden third person mesh. If you click on hidden
shadow, you compile. You can click on Play. My character is hidden. However, I can also see the
shadow on the ground now. Now it is working correctly.
Now this is fixed. And let's go back just to make sure that we don't
have any collision on this character
because we don't want this character model to
collide with the mesh up here. Clicking on this
third person mesh, I'm just going down to
the collision settings and I'm making sure that
it says can character up on, I'll say no here. And make sure that you don't have generated
overlap events on. And make sure that you have no collision as the
collision preset. Let's compile everything. Let's save everything and let's move on to
the next lesson.
51. 4.09 Camera & FPS Smoothing: When we are playing the game, there is a slight leg, maybe I'm not sure if you
can notice right now, but if you just run around and try to move the
mouse up and down, sometimes it's actually
feeling a bit laggy. In order to fix this rotation, you can try to close
this game right now. Go to the player and inside of here you can
click on the spring. If you click on the spring, you can enable this
one here under this one called enable
camera rotation Le. This will smoothen out
your camera rotation. If you play around and you
can feel that is actually, it feels a bit laggy. You can actually feels laggy when I try to
rotate my camera. To fix this, you can enable
the rotation camera leg, and this will smoothen out
rotation for the camera. You can hear for the
camera rotation leg, you can try to set a number. If you set it very, very high, you can see
what it looks like. Not much is happening here. If you maybe put it to one
and try to play again, you can see now it's
very smooth like this. This is way too much. You can see it's
trying to smooth out the camera. This
is way too much. I have to increase it
to maybe something like ten and you can try
to see what it looks like. However, if you put it too
low, you can see it is smooth, however it feels a bit laggy and it will probably give
motion sickness to some people. Let me put it on
something like 30. Instead, I compile and
I try to rotate around. I just want to have
it feel natural. It's still a first person
shooter and we don't want to put it too high
or too low here, maybe putting it on 40 instead. Just try to keep playing again. Try to increase the number. Try to look around and
see what it feels like. It still feels a bit y, maybe something like 60. And I'll try to look around. It feels a lot more natural, just like a first
person shooter. Let's try to adjust
this number here. You don't want it to be too low, else the camera will
feel very slow and y okay, this is fixed. Now let's go to the
window or edit actually, and go to Project
Settings inside of here. If you search for smooth, you have something called
smooth frame rate. You have to have
this enabled for your game if you want to
release it somewhere else, for example on Steam
or to a friend. The reason this is a mistake I made when I released
Fm tail on Steam. If you don't have this limited, if you don't have this enabled, then the player who's
playing your game is going to run your game at
maximum frames per second. It depends on which
graphics card they have. If they have a very,
very good one, maybe your game will run
at 800 frames per second, and it will actually use a lot of resources for their computer. You can probably
hear the computer making a lot of
sound from the fans because the graphics card
is running way too much. You have to enable this
to prevent from the game running and using all of the
resources from the player. Go ahead and use this
smooth frame rate. The minimum, I'm just
going to put it at 30 frames per second
as the maximum. Usually I put it to
60 frames per second. For other games, however, this is a first person shooter, you need more frames per second. Maybe I'll put it to 200 as
the maximum frame per second. I think 200 is fine. I don't think you
need more than that. Let's close this down
and save everything. Let's move on to
the next lesson.
52. 5.01 Adjusting Movement Speed: Now we are ready to adjust
the movement speed. You can see when
you click on play, it's running way too fast. So if running game, you can try to have a feel of how fast you want to
run in your game. Now for me, this
is way too fast. It really depends on which
game you're creating. Now if you're creating
a fast paced game, this run might even
be too slow for you. For me, I'm just creating something close
to counterstrike. Not really 100% but something. I'm going to reduce this
movement speed slightly. I think it's way too fast. I can go here in my player
base, the character component. And then I can decrease
my maximum walk speed. Now I'm going to decrease
it to something like 700. I try to play a couple of times and trying to
adjust this number. And then you have to
click on Play again. And just to run here and try
to see what it feels like. Now just keep playing the game. Try to increase and decrease the speed number
and see what it looks like. I think for me this is fine. Maybe I can actually
increase it to 750 and try to play again. I think 750 is the
number to go with. Okay, So when you're
heavy with this one, you can also remember you have these float variables
as well for the speed. Let me actually
just click and drag this up here, so
they are together. You can click on this
run speed and set it to 750 as well. Go on and compile now
For the walk speed, I'm going to set it to
something like 400. And for the crouch speed,
something like 200. Again, I tried playing my games a couple of times.
I know these numbers. You have to, again, set the walk speed to something. Then you have to click on Play. Then you have to click
on Shift to Walk and try to see if this walk
speed is good for you. Or if you want to have
it slightly faster. Just try to playing
your game again and again and try to
adjust these numbers. Now if I play my
game and if I run around and try to have a
feel of how fast it is, if I click on Shift
to walk around, I think this is
looking good as well. And if I click on control and try to see what
it looks like, I think this speed is
looking good for me as well. Okay, so let's go ahead
and close all of this down now that the movement
speed has been adjusted. And let's also adjust the animation speed
in the next lesson.
53. 5.02 Adjusting Animation Speed: When we adjust the
movement speed, we have to adjust the
animation speed as well, else it will look incorrect. If we click on the player again and click on
the player base. For here, I want to add
some length to the Spring. Um, again, just like before. The reason is I want to see my running animation and see
how fast they're running. You can see we are running now. It actually looks good. You can see it's
following the ground. Sometimes your animations for the character when
you are running, they are too fast and too slow. You have to adjust the
running speed as well. You can actually see there's
some collision here. For some reason I
think it's my sky. If I click on this sky over here and I actually
move it away, for some reason this one
has collision set on. But this is just the sky up here and it doesn't
really matter where it is, we're just going to
put it over here. Okay, for the animation speed, what you need to do is you
need to go to the animations. And then you can set
the animations inside of the blend spaces that
we created earlier. Let me start with
the run blend space. And inside of here,
if you just go down and you can see
all of these blends. Now all of these animations that you added here as points, you can also see them over here. Now first what I want to do, I actually want to
increase my weight speed. Because the weight speed, remember, is the smoothing
of the animations. I think sometimes it is sliding around a
little bit too much. Maybe if I increase it to
6.5 instead of 9.5 again. Remember just like before,
when you increase it, it applies less smoothness
to the animation. I just wanted to
look more natural. I'm going to open
the rest of them. For the rest of them,
I'm going to set the weight speed to 6.5 as well. 6.5 for the walk as well. I'm going to set the
weight speed to 6.5 Okay, that's fixed. Let's
save everything. All right, before
we do anything, you can also go up here and remember to change
your vertical axis. Maximum value here. Remember this was the
movement speed for the run. Movement speed right
now for my game is 750. I usually put it to
somewhere around the half. I'll just put this
one to 350 instead. You can see when you put
it to something higher, now it is applied here, 350. However, my animations are still running at 300, I
have to click here, drag and hold shift, and just put it up here again, click hold shift to again
snap it and put it over here. Nothing new. We have
done this before. Just drag all of these
animations up to 350, and now they are
running at that speed. Okay, so let's do that
with the rest of them. Let's open up the crouch. My crouch was a speed of 200. If you open up the
player and inside of here in the player
base the crouch speed, I set it to 200, so I can go to the
crouch and I can put this one to something
maybe like 100. However, you can see if I
put it to something lower, it's going to give me a lot of errors and all of my
animations are gone. This is because it's deleting
all of those animations. Up here, I'm going to
click on control Z to bring all of those
back. Here they are. Remember to decrease all of
those before you actually begin to play around with these numbers so
they don't get deleted. I put them down here. Let me decrease this
number to 100 now. And now you can take all of those and add them up here
to the maximum speed. I wish there was a
functionality where you could actually take all of
them and move them up at the same time. I
don't think there are. Actually now for the walk speed, it is set to 400. I'm going to put it to 200, going back to the
animation speed, and I'm going to put
it to 200 instead, for the speed, I'm going
to move them up again. All right, now that this is
fixed, let's save everything. Let's go back to the running
now for the animation speed. Let's start with
the run forward. I'm going to start
with the run forward. And the reason I do this
because when this is correct, I am going to apply
to the rest of them. The running forward
is my first one here. Run forward unarmed. And you can click on
the small arrow to see those settings for
the rate scale. If I increase it to
something like three and all of them maximized
for some reason, this is the run forward. If I set it to three
and I click on play, you can see my animation
speed is really, really fast. Now you have to adjust
the animation speed to fit your movement
if I right now, one is the default. If I said to 1.1 just
slightly faster. And if I click on play, and you can see what
it looks like, now, the running on the
sides is not working because this is only the run forward that we have adjusted. This is what it
looks like. For me. I think 1.1 in the
rate scale looks good. I actually want to apply
it to the rest of them. What you can do is you can
hold shift and right click. This will copy this. Or you can simply just right
click and copy. But you can see Shift
and right mouse button will copy this as well. Then I don't want to do it
for the idle animation. The idle animations, I just want them to be one just like usual. More problem for the
running animation. The front right running here. I'm going to hold shift and
left click to paste it. Again, you can simply right
click and paste it as well. But you can see the shortcut
is shift and left click. I'm going to paste it on all of the other animations as well, so they are applied
just like that. Let's go ahead and click on
Save. Let's click on Play. Now you can see what
it looks like for all of the other sides as well. It looks a bit better. And the reason why
we increase it is so it doesn't look
slightly like before. All right, now that this is
done, let me close it down. You also have to do
it for the crouch. You have to play here. Try to crouch and try to crouch
around, See what it looks like. Maybe again, we need to increase the animation speed
slightly because you can see it looks like it's sliding because the animation
speed is way too low. So you have to go in here again, go to the animation,
crouch forward. I'm going to put
it to 1.1 again, just like my running, just
to see what it looks like. And if I crouch and try
to walk to the side, maybe we need
slightly more here, 1.3 Instead, click on play. Try to crouch around and
see what it looks like. Put it to something like 1.1 and then you can click on Play. Then you can remember, this is only for the crouch forward. It doesn't work if
you run to the sites or crouch to the
sites crouch forward, and I can see what
it looks like. Maybe it is still
sliding slightly. If I put it to 1.2 instead, I click on play and
I crouch forward. I think this is
looking a lot better. Let's try, actually 1.2 What I'm going to do is I'm
going again to copy this and paste it on all of my other animations
that are not idle. The idle animations
I don't care about. I have them at the rate
of one. That is fine. And for the other animations, I'm going to put it to 1.2
just like this going to save. And then let's play and
see what it looks like. If I walk to the sides as well, it is sliding still. I actually need to
increase it to 1.3 maybe. Let me actually go again. In here you can see it takes some time. You
have to test it. If I put it to 1.3
I copy this and I paste it on all of
the other animations. Just like before. I go ahead
and click on play again. Let me see what it
looks like now. Now it's a lot less, you can see it looks a
lot better than before. We can go ahead
and keep adjusting those movement speeds and those animations and see
what they look like. When you are satisfied, you can now go over to the walk, do the same thing, go
ahead and click on Play, Hold shift, Try to walk around. You're sliding way
too much right now. Go to the movement forward. Let me see if I
can find it here. If I go up the forward, this one here,
Animation. Walk forward. If I put it to 1.3 click on play and I hold
shift and try to walk around. And it is still
sliding slightly. If I put it to 1.5 instead, hold shift and try
to walk around, you can see the walking
is looking a lot better. I'm not sliding around. You can either adjust
the movement speed for the walking or you can adjust the animations to fit
the movement speed. I think 1.5 is fine for me. I'm going to copy this on all of the other animations
that are not idle, like this and the back as well. And now you can
see this is idle, so I'm not going to
copy it down here. Okay, Click on play, and
now you can hold shift and walk around and try
to walk to the side. Looks a lot better. If you
think this is too fast, you can always reduce the movement speed or
reduce the animation speed. That is fine. Again, it really depends on which
game you're creating. I think for me this is fine. And I can always come here and adjust it later if
I'm not satisfied. Sometimes when I
close my game and I get online the next day, sometimes I think
something looks stupid and I change it around, try to change the movement speed and the animation
speed and so on. But for now, it
looks good for me. So I have to close it down now and let us save everything. And let's move on
to the next lesson.
54. 5.03 Fixing the Camera Wall Clipping: Now we need to fix
the camera issue. If I go back to the
player and I set the spring to the
arm length of zero, just to go back to first person
mode and I play the game, you can see if I go near
something and I look down it, sometimes clips through the wall like this, as you can see here. And I can look through the wall, and people will probably
misuse this and cheat in the game to see what's behind the wall in order to fix this. There are two ways. The
first way is if you go to the market place and go to the player and find the skeleton
for the player. Now it depends here
on your socket. First, the socket
you have added, you can see that I have
put my Y value to seven, if you put it to
zero, for example. And you click on Play, you can see you push
back the camera. And you can see more of
your body, just like that. You can try to push
back your camera, maybe instead of zero, you can make it minus five. You can see how
much can you push your camera back without
making it look bad. So you can see minus five. I start to, you can see my
character neck or head, almost where the head has disappeared and it
doesn't really look good. Minus five is way too much. I would set it back to zero, for example, and
try to play again. The problem with this
character is he has a radio. You can see the radio
on the player here. It's actually getting in
front of the character or the camera like that
and a bit annoying. Now if this was a custom character that
you have designed, you could stabilize
this a bit more so it actually doesn't go
through the camera. And if that was the case, then this position for the socket would actually
be a lot better. Because you can see the body
and it looks nice like that. However, the radio is a bit
annoying for this character, so I'm going to push
it forward again. This is the reason we
actually pushed it to seven, because at seven we can't see the radio and everything
is looking great. Okay, How can we fix this now? We can't really play around
with the socket anymore because it is placed
as best as we can. The other thing is you can go
to the player base and you can go to the viewport
here in the player base, you can click on the
Capsule Component. Capsule Component. You can
see if you increase it, the capsule radius to something extreme,
for example, 150. And you click on Play,
you can see you have collision a lot faster
against the walls. And you can't go towards
the walls easily. You can see here. Now it's impossible to walk and
see through the walls. However, it's a bit
unrealistic if you put it too high because
you can't really come close to the walls
and you get blocked. You will also get
blocked up here. If you go to this ramp, I think can see you can't
go through the ramp because your capsule component is way too high and you
can't go through it. Okay, increase this
capsule component. A size that actually makes sense for you and removes
the wall clipping, but it's still small. 70, for example.
Let's try it out. Let's go through the wall here. Look down, look to the size. Maybe it's nice. This is working actually,
let's go to this one. Sometimes I can see
through the walls. Sometimes if I walk into it, I have to increase it
slightly because actually still going through the
walls can increase it to 75. And then test again and
see what it looks like. Yeah, maybe 75 is
working actually. It's bucking a little
bit sometimes. Okay, So I'll put a 280. That is my final decision here. So let's compile and
now it is at 80. Yeah, if I look down, I look up, I look to the sides. I can't see through the wall. And I can still go near
the wall like that. And let's see if we can
go up the ramps here. If I go up the
ramp and it works, even though I'm close
to the ramp wall here, I can still go up the ramp. Okay. This was an easy
fix if you go here. Now here, it's a
bit of a problem because the space
is really narrow. What you can do
to fix this right now is you can always come in here and you can put on the snapping up here to
maybe something like ten. And put it on. Then actually my camera speed is way too high. I'm going to
decrease it. You can click on this object here and
just move it to the side. Maybe just change the map design a little bit so
this doesn't buck out. Now if you need a very, very complex collision system, this actually requires way too advanced work
for this course. Here, you could do
it with blueprints. However, it does require a
lot of code for it to work, and it will be really advanced
compared to this course. You can try again to go up
here and see if it works. See if everything is good. And you can see everything
is working good as well. All right, so this is
how we fix the camera. Clipping through
the walls again. If it does clip sometime, you can always go in here. Maybe take back the position here for the socket,
that will help. Or if you can come
in here and increase this capsule component slightly
so it doesn't book out. But be careful you don't
increase it way too much.
55. 5.04 Fixing the Jumping Crouch: Right. Now if I play the game, you can see when I jump, actually when I jump and press my crouch button
at the same time, you can see I can spam it here. When I jump and I
keep crouching, the camera is
clipping like that. You can have it as a mechanic
if you want for your game. Some people like stuff
like this, for example. You can jump, you can try
to do some crouch and you can look over the wall that
maybe it could be a mechanic. However, I think it's a bit
too much and I don't really want this mechanic here
when it clips like that. If I keep crouching, let's go back to the player, go to the player player
base inside of here. Let's go down to
the crouch logic. This one here. In the crouch logic, I want to make sure that
the player is not jumping. You can't crouch when
you are jumping. If we take this one, remember we already made this
function is not jumping. The only thing we did
here is just take the character movement
component and ask if the character
is falling or not. If the player is not falling, it means they are
not in the air, which means they
are not jumping. Okay, we can take this,
we can make a branch. If the player is not jumping, then we are able to crouch. There is a slight
problem right now if we jump and I
press on crouch. Because see, I can only
crouch on the ground. However, if I jump and crouch, when I land, I don't crouch. I need to actually crouch whenever I jump and
click on crouch, it should auto
crouch when I land. And we need to fix this here. I'm going to drag
from this and delay the code by something
really, really small. So maybe 0.05 after the delay, we can go back and
play this code again. What this is doing is simply
if you are in the jump, you can't crouch, then
it will be false. It will go ahead and
delay the code and it will go back and ask again
if you're jumping or not. It keeps checking if
you're jumping or not. And when you land
on the ground and you still have the
crouch button pressed, it will actually go
ahead and crouch. You can try it out, see
if it works or something. Bugs, You can jump here, crouch, auto, crouch,
one eye, land. That actually works. Now
if you put this too high, it will seem a bit laggy
because when you jump, it takes a bit of time. Before you crouch, you can make it a lot better
to crouch here. If you make it a lot lower, the response time
will be a lot higher. If you jump and
click and crouch, you can see it
crouch immediately. I don't like to put
it way too much down, because remember the
further down you put this, the more times this
code is going to run. It's going to run
this many times per second trying to check if
you're jumping or not. For this one, I'm just going
to put it to 0.05 instead. To check how many
times this runs, you can always take this
browser and say 1/0 0.05 Then you can see
this code right now, runs 20 times a second. And you can see it does
run a lot of time times. If you put it to 0.01 then
it runs 100 times a second. I don't like to put
it way too low. 0.05 is a good number.
Let's close this. Okay, now this is working. Now the problem is
here. For the crouch. It's actually going to run the crouch code even though
I'm not crouching anymore. You can see if I
drag here and say print string and I just print a simple message to
the screen to see if this code is running or not
compile. Let's click on Play. You can see if I jump and
hold, crouch, and I'll let go. So when I land, it's
actually going to crouch. I jump, I crouch and let go. It's going to run
the crouch code even though I don't
really need to, because I haven't crouched
yet to do this or to fix it. We can take the movement
state and we can drag from it and we
can say contains item. If it does contain
the item crouching, then we want to go
ahead and crouch. When we let go of the
button, let's strike here. Actually, just
drag it down here. And let us make a branch and let us connect
it, just like that. Okay, I organize this
a little bit, okay? So what we're doing
here is we're asking if we are in
the jump or not. And if we are not in the jump, we can go ahead and crouch
if we're on the ground. However, if we are in
the jump in the air, it's going to keep
rechecking whenever we land. And when we land
it's going to go through this code and
then it's going to ask, did you let go of the button
or did you press the button? If you press the button, you are going to crouch
automatically. If you're still pressing
the crouch button, if you have let
go of the button, it's first going to check if
you're actually crouching, If this movement state array does contain the
crouching element, and if it doesn't, then don't do anything because
we're not crouching. Make any sense to run this code. However, if it does
contain the crouching, and you'll let go of the button, it's going to crouch. Let's try to play it now. And let us jump
and click crouch. That helps. If I jump and
click crouch and let go, You can see the
code is not running anymore and it is
fully optimized. Let's compile now. Everything is working here. When I jump and spam my crouch button, it's
not going to work. Only when I land
here in the air, I can't spam my crouch button.
56. 5.05 Fixing the Remaining Crouch Bugs: Okay, the final thing I want to fix for the
crouching is you can see if I go over
to an edge or a ledge. And I crouch here and I go to this edge here and
just walk off the edge. You can see the character
is blocked here in mid air. You can see every edge
that actually does this. If I go up here, that
is way too high. I go up here and I go and
crouch and want to fall off. You can see I'm actually
here on the edge. And yeah, it looks weird.
Let's close it down. Let's go to the player base. And if you click on the
character movement component and search for crouch, you have this one called,
Can walk off ledges. When crouching, click on that and go ahead and
compile and click on play. Now you can see
when it does that, if you crouch here
and if you jump off, it will fall down
from this edge here. That was the only
thing we had to do, a very, very simple fix. Let's move on to
the next lesson.
57. 5.06 Preparing the Footsteps SFX: Now it is time to add some
footsteps sound effects for the character to make it sound better in the game so
it's not too silent. Let's go ahead and
make a new folder. Let's go ahead here in
the content folder. Let's right click, go to a
new folder, call it audio. Inside of this folder,
I'm going to write click and make a
new folder as well. I'm going to call it sound
effects inside of this folder. Let's go ahead and import
the sound effects now. Again, in the cost
materials that I have uploaded for
you on this website, you will see a lot more items. For example, in the
UI or in the audio, you will see a lot more items than what you see here
because I keep adding stuff. While I develop this course. You might see even more stuff than what you're
seeing here right now. Don't worry about it,
Don't get too confused, I just keep adding stuff
while I develop this course. Right now, what we need
to use is the footsteps, the footstep sound effect
1-6 So all of these, you can click and drag
those into the panel here, the content browser, and let go, and they will be added. What you need to do is
you need to right click go and here in the
audio, make a sound que. When you make a sound que, you can call it, let's
call it footsteps. Now another way to create a
sound que is you can also just right click one of them and go ahead and
click on Create Que. The third option is
selecting all of them and creating a single que that will actually also upload all
of them into a single que, which is actually
what we want to do. But you can also just
right click and go to audio and create
the sound que. You have different options. Let's go inside of
this sound queue. Let me just make it a bit
larger so we can see. Can do now is we can
take all of these. Click on the first
one, whole shift, click on the last one and click and drag them
into the sound cue that will add all of the footstep sound effects
into the sound cue. Now inside of here,
what you can do is we want to play these
footsteps randomly. It should choose at
random which one to play, just so we have some variety. What you need to do is write
click and search for random. Then you find this random note. By the way, for the sound
cues, you can write click. And you can see you
have these nodes just like in blueprint. However, not like in blueprint. You can see you don't
have many nodes, but you can do cool
stuff with them as well, even though you don't
have many nodes. Now for this one, we are
going to use the random, and it's going to play one of these sound
effects at random. Let's connect it. Let's drag
and connect these into here. And let's click on
this. Plus a couple of times we have those inputs, we can plug them into just like that. Plug
all of them in. The output we plug
into the output. Let's just organize
it a little bit. What you could do
now is you can click on Pl Q to see what it does. And you can see it plays
one sound at random. It just chooses one of them. Now I think it is way too quiet. We can go to the volume
multiplier and increase the footstep sound effect to
put it to 1.2 for example. Or you can put it to three. You can see that
increases the sound, maybe 1.2 I don't want
to make it too high for this course because I'm also talking to you and you
can hear my voice. If this is too loud, it will probably
be too annoying. Maybe one for me, you can
increase it a bit higher. One is still maybe too quiet. But for this course, I'm
going to stay with one. I think you can hear me as
well when I recall the course. Okay, we have this footstep
and it is prepared. And you can also play it here
to see what it sounds like. Now if you want more
variety as well, you can use something
called a modulator. If you right click and
search for modulator here, I'm actually just going to use one sound to
demonstrate it to you. If I take this sound and
connect it to the output, you can see if you play now, it sounds a bit different. If you click on the modulator and maybe decrease the pitch to 0.9 and increase
the maximum pitch to 1.1 there is a
big difference. It's going to make a variety of the sound with
different pitches. If you click on play
now you can hear that it sounds a bit
different every time you can use a modulator to increase and decrease the
pitch by random. You can also connect it here. If I just connect this back, you can connect it here to
make a bit of a variety. Now instead of 0.9
I'm going to stay with 0.95 But for the pitch max, I can stay with one. Something like that. You get a different sound every
time you play this. Okay, let's save everything. Let's close it down and let's
move on to the next lesson.
58. 5.07 Timer by Event: Now to add the
footstep sound effect. If you have done this before, you know that you can go to
the assets and animations. And inside of an animation, for example, this one here,
any random animation. Actually the crouch is probably the running that we need to
find. For example, this one. You know that you can go
in here, right click, add in the notifiers, then lay a sound effect. When you do this and you select a sound effect
here in the sound queue, and you just click on play. You can see that it's
actually working. And you can copy this
sound effect, paste it, try to put it together with the
footsteps, just like that. Something like
this, for example. Just like that. It
will work in game as well when you play the game. However, I did this and I
wanted to record it for you. However, it does buck a little
bit because when you run, sometimes it places
the sound two times. Because on the other
animation you also have this, you have to put this on all
of the run animations when you switch animation from back to front or back
right to back left. Sometimes it actually place
the sound two times at once. It sounds a bit buggy. I don't really like this method, so I tried another one. So let's close this down and let's try something
called a timer by event. In this lesson, I
just want to explain to you what this
timer by event is, because we are actually going
to use it more than once. And it is a very
important concept and function inside
of blueprint. Let's go to the player,
let's go to the player base. Now for the running, I just want to put
it maybe here in the movement event that
will make the most sense. Let's take all of this, and I'm actually going to
push it down slightly so I can work here
without any restrictions. Let's go here at the end
of the movement code, and let's drag from here
and write timer by event. And we can go ahead and select this one called timer by event. You can also write, and you
can see what you can do. You have timer by event, timer by function name. This is almost the
same as the event, but you can see what this is. After you have understood
what set timer by event is, let's select set timer by event. Now for this event, we have
to add a custom event here. You can see this input
you have to direct from here and you have to
write custom events. Then you have to call your
custom event something. For example, I'm just going
to call it play footsteps, sound effects, play
footstep sound effect. Now it asks you here, what is the time you
want to loop this? For example, let's rise 0.5 Now I'm going to select here that this
timer is looping. And I'm just going to
click on this arrow again. Okay, Now it is a looping timer. And it's going to loop
every 0.5 seconds. If I direct from here
and print a string, and I can click on play here, you should see we run here. And I stop my code, you can see that it
runs every 0.5 seconds. You can see it actually prints
hello every 0.5 seconds. You can see this better if
I just change the color. For example, in the duration, instead of just 2 seconds, I put it to 50 seconds. I click on play, and
I move, and I stop. It's going to run the code. See every 0.5 seconds, it's going to say hello. If you put it down,
you can see every 0.2 seconds it's going to say
hello, as you can see here. So we can use this
timer to run some code. In this case, we're
going to use it to loop the footstep sound effects
when you're running, it's going to play
the sound effects. Okay, for this timer, at some point we need
to stop the timer. Else it's going to loop forever and your code will crash at some point because you have spawned too many
instances of this. So let's right click and
promote this to a variable. Let's call this 1 Ft steps. This effects time or handle.
It's called a handle. If you hold the mouse over it, it's called a time
handle structure. I usually just call it
time or handle at the end. Footsteps, sound,
effects, time or handle. Now we have this later on, what we can do is we
can take this and say clear and invalidate timer. This is when we want
to stop this timer. At some point, we
can go ahead and use this clear and
invalidate timer. But far now let's
just delete it. Yeah, that was actually
for this lesson. Let me just change this one to something like 0.5
to begin with. Because remember, a timer
runs this amount of seconds. So for example, if you re 0.1 it's going to run
ten times a second. You can imagine you don't want to put this to
something like that, because imagine how many
times this will run. If I say hello and I click on
play and I run and I stop, you can see it's going to spam. This code, you can see
my game is actually crashing and it's lagging a lot. Don't do this, this
is really bad. I like to stay at the
minimum, minimum value. If I really have to go very low, it is 0.3 or maybe
0.2 in rare cases. But usually I try to
stay at 0.50 0.40 0.6 That is if I
really need to run it. A lot of times, again,
what I said before, you can always go to your Internet browser
and you can say, for example, 1/0 0.01 Then you can see how
many times it runs. Usually I don't like to go
over 60 times a second. I write, for example, if you write 0.03 it
runs 33 times a second. And sometimes this is
okay, don't worry. Sometimes this is necessary and you will know
when you need it. When you can stay up like
this, that is a lot better. This runs the code 16 times. You can see 0.03 You run the code almost or actually
double the amount of time as 0.06 Try to
stay as high as you can here because
that will be really optimized for me right
now for the footsteps. Let's just run it as 0.5
seconds, two times a second. And we can always adjust
it later when we need to. Let's delete this
one. Let's compile everything and let's move
on to the next lesson.
59. 5.08 Multicast Replication: Okay, so here we are again. Now, very important we
are in multi player. We can't just go in here and drag from here and say
play Sound for example. You just say play Sound. You can play the sound two D, which is used usually for UI elements when you
click on a button. And you can play
sound at a location, for example, for footsteps. And you can just go ahead
and select the sound. And you can see if
I click on Play, I run, it's going
to play the sound as you can see here. Now this doesn't really work
in multiplayer. The client will not hear
the sound, because again, remember we have to replicate the items to the clients
from the server list. Now this would work in single player, but
non multiplayer. Now for multiplayer, we
need to use a multicast. What a multicast is, let's actually just create it here and I will
explain it to you. Let's right click and
make a custom event. This custom event, I'm
going to call server first. Let's run it through the server. Server footsteps, sound effects. Okay, let's click here
in the replicates, run the server and reliable. Now let's right click down here and make a
new custom event. Let's call it MC for multicast. And again, play footsteps, sound effects for this one, let's click on the Replicate. And now we're going to choose multicast and reliable as well. What a multicast is,
you can imagine it, it replicates this, whatever you write in here to
all of the clients. It costs all of these items that you write here to
all of the clients. For multicast, it can only
run through the server. You can't come in here and say multicast footstep sound effects because this one you can see, it says if server this only
runs through the server, you can't multicast
through the client. We can't do that. This is why we have to drag from here and run it through the server
first, footstep sound effects. Then from the server
we can drag and say multicast footstep
sound effects. And that will work perfectly, so you have to run it
through the server first, from the server, you
can then multicast. Okay, another
explanation as well for multicast that you
have to understand is multicast are usually used for effects that are temporary. For example, if you play a sound effect because
remember multicast, if a player connects to your game and you have
written a code in multicast, the connected player will not
be able to see this code. This is where rep notify comes in. And that
will come later. Don't worry about it for now. But you can see here if
I click on a variable, if I actually have a
variable, if I go to you crouch for example, and I
click on my movement state. You can see in the replicated, I also have something called a rep notify that
will come later. But if we go back and we go
back here for the multicast, whatever code you write
here will not be seen by the connected player
unless it plays again. If I just connect
to the game and it just played the
running sound effect, I can't hear it unless the player stops and
then runs again. And place this code while I
am connected to the server, then it will play correctly
for the multicast. Very important is you do
something that the connected player doesn't really
need to hear or see unless it is played
again, for example. Now for this footstep sound
effect we can play here, as well as some visual effects, for example, some fireworks. And if you open a
chest and there are some gold visual effects
that come out of this chest, then that needs to run
on a multicast as well. The rep here, if I click on
one of my variables. This needs to be used whenever you need the connected player
to see that change. Let's say for example, if
the player is holding, for example, an AK or
a pistol, a deagle. Then this is very important
that the connected player needs to see the correct
weapon on the player's hands. The weapon you don't
really do in a multicast because the connected
player will see the wrong weapon on the player. Some games have a lot of bucks because they use
multicast for everything. Again, usually what I
use it for is mostly sound effects and visual effects that don't need to be
there all the time. For example, you can see if
you have a traffic light that goes from red,
yellow, and green. This traffic light
like that color, I would probably do
inside of a rep, notify because that color needs to be visible correctly
for the connected player. The connected player needs
to see if it's yellow or red and not keep seeing it
green until it changes again. For temporary visual
effects, for example, fireworks that disappear
after 3 seconds that relate doesn't need
to be in a notify that needs to be in a multicast. Whatever is temporary
that the connected player doesn't need to see immediately,
you have to do it here. Remember, this code has to run again before the connected
player can see it. Okay, let's go ahead and
play the sound here. Let's drag from here and
say play sound at location. This is how you play a sound. You have to specify where do
you want to play the sound. Remember, we are coding
inside of the player. I can just drag from here
and say get actor location. I'm getting this
player's location. Now this sound is going to
play wherever this player is. Now we have to
select which sound. We're going to select
the footsteps. Now if I click on play
and I run around, now I stop. You can hear that
the footsteps are playing. You can also hear it here
on the other player. If I open the other player, I can actually hear
the sound as well. This is from the client.
Now this is working, okay? You can hear it
runs all the time, even though I'm not running. And we also need to fix
this in the next lesson. But for now, we know that this sound effect is
actually playing. Again, multicast can only
be run through the server. You can't run a multicast through the client, run
it through the server, and from the server
you can multicast to temporary sound effects or visual effects that
don't need to appear connected player. For example, some fireworks or a bullet that you just shot and
it will disappear. But for example, which
gun the player is holding is really important
for the connected player. So that will go inside
of a rep, notify. Don't worry, we will
do this later on. For now we don't have much. We only have the sound effect. But we will have a lot of
examples through this course. Okay, to stop the sound effect whenever we stop over
here in the completed. This is whenever we let
go of the movement keys. What we can do is we can take
the footsteps here again. We can clear and invalidate
timer by handle. This will stop this timer
from running anymore. We can go ahead and connect it, just like that we can compile and let's
try to play it now. If we run and I stop here, you can hear nothing
when you run. The reason why you can't
hear all of this is because this keeps running
like this really quick. It never reaches this timer before the second
movement is running. It keeps running like this. It gives it a break to actually go over
and set this timer. We are going to fix this, but you can see here
when you add this, the timer actually don't play the sound effect anymore
because we are stopping. It clears the timer just to make sure that
it doesn't buck out. We can always take
this footstep handle, we can drag and say
valid and we can use, this one is valid timer. If it is valid we can
make a branch and we can clear this timer like that. Okay? Making sure
that this timer is valid and then clearing
it to make it more clean. You can always just take another instance of this
variable and plug it into here. And you can go ahead and
organize this pit more. And now we have this code. Okay, let's compile and
in the next lesson, let's actually make this less boggy and actually run this
code whenever we are running.
60. 5.09 Footsteps SFX Conditions: Okay, first of what I need to
do is let's make a bullion, let's drag this away. And let's make a new bullion called Playing
Footsteps Effects. Playing the footsteps
sound effect. And I just misspelled that. Just like that, playing
footsteps sound effect, let's drag this and set it to true whenever we are
playing the sound effects. Before we do this, let's
take this and make a branch. First, we're going to ask if we are playing the sound
effects or not. Just to make it more readable, I'm going to drag
from this and write not bullion, just like that. When we are not playing
the sound effects, I want to go ahead and
play the sound effects. We don't need to run
the foot sound effects when we're already running them. If we are not playing the
footstep sound effects, then we can go ahead and play the sound effects
just like that. Remember, you have
to set it to faults. At some point here, when we stop the timer and
we stop the sound effects, I'm going to set this to false. Let's compound,
see if this works, or if we need to do more. Now you can actually see it
works when you are running, It works when you are
stopping, it stops as well. Okay, awesome. Now it
runs way too slow. So maybe you need to reduce
this number to 0.5 or four. And you can go ahead
and play again. Maybe that is way too fast. Actually, I'm going to write 0.42 I think you have to
play it a couple of times. Try to test your game.
I think this is fine. You can always adjust this later if you have
a buck with it. But I think this number
is fine for me right now. Now this is working correctly. However, you will
have some bugs. You'll see if you click
on Play and I run around, you can see if you
run into something. Also place the sound effect. This is a small bug
that you need to fix. For this one, you can use
the velocity of the player, because if I just
strike this away, let's move all of
this away here. So you can actually have
some room to work with. If you right click
and say get velocity, this is the speed of the player and you take this and
break, break this vector. So you can see the
X, Y, and Z again. You can also just
right click and split the struct pin.
That is the same thing. However, I do like to break the vector just
to have it out here. Now, just to see it,
let's print a string. You can just print
the x velocity, for example, and you
can see what it says. I usually do this sometimes
when I do a new mechanic. I use the print string a
lot to see what it does. You can click on
W to move around, and you can see the
velocity increases. The speed of your character
increases whenever I move. Okay. Just like that. And the same thing
with the X and Y. So you can see it increases
whenever you move. What we can do to play the sound effects when
you walk into things, I don't want to play the sound. Let us strike from
this and say if this velocity is larger than, for example, 100 or if
it is lower than 100. Because remember,
if you walk back, it will be a minus number if it is lower than 100 as well. Or let's do this
for the y as well. Let's copy paste this and
just connect it here. If it's lower or higher, or lower than 100 here.
Let's drag from this. We don't need to
use bullion because n means all of this
needs to be true. We can drag from this and use an Or bullion if one
of them is true, we don't want to play the
sound because we are too slow. Let's click on the plus
here and add all of them. What we're saying is if the velocity for
the x is over 100, or if it is lower than 100, or if it's this,
or if it's that, then we want to
play the sound we can drag from here
and write a branch. Then from this branch we can
go ahead and connect it. Just like that, we
can connect the code. Now the code is
only going to play whenever we are moving
at this velocity. Let's click on play.
And I move around. I stop and I move
into something here. See it's still playing. And I think it's because this
here is not high enough. If we write, for example, actually this is
because this one is, the lower is also wrong. Let's actually make it
higher first, Let's do 250. And here I have to write lower -250 That was
a mistake from me. Let me just write 250 and
it is lower than -250 It's actually still playing
the sound if I walk into things and it is because I haven't put it
here on the false. When it is false, you
can see if it is true, it's going to play the
sound effect. But if I Keep pressing the button
and it will be false. We don't really do anything. This will only stop
the sound effect whenever I let go of the button. What we need to do is we
need to drag this down here. And we need to plug this
false into here as well. So it stops the timer
whenever it is false. Let's click on play now
and walk into things. And you can see now it
doesn't play the sound. When I walk a bit, you can see it begins
to play the sound. You can always
adjust this number. If you make it lower,
it's going to play the sound a lot faster
when you walk into things. But for now, this
is fine for me. And you can always go ahead and organize this a bit more, okay? So something like that. I
just put the read route notes just so it is
a bit more readable. Just like that, Okay. Now what we need to do,
there are other factors. Now the next factor is, you can see if I go up here, let me actually jump
from up here and I jump, it's also playing the
sound in the air. What we need to do
is we have to take, this one is not jumping, so we're making sure that
the player is not jumping. Else we don't want to
play the sound effects. Let's strike it from the
oar and right bullion. If true, if you're not jumping, then we can go ahead and
play the sound effects. This needs to be a
condition as well. Actually, let's strike them. Yeah, a little bit back here. Let me drag all of
this further away. Now the jumping is working. The second thing is we also
want to make sure that we are actually running
and not walking. And you can see here, if I
play the run first and I walk, it's actually going to
play as well, running. I don't know if I have
that, I don't, actually. We can take this movement state and we can drag from here and say get a copy again. We can try to check
what the last index is. If it is running, it
means we are pressing the running button right now and not walking or crouching. If this is equal to running, then we can go ahead and do this code just like that.
We can do it like that. Now to make it more clean, I'm going to select all of this right click
and collapse this to a function I'm going to call this, function is running. This is just checking if the
player is running or not. I'm making it into
a pure function. Let's go into here
and just organize this a bit more inside of the
function, just like that. Here we're simply checking if the player is running or not. So this one is running, so we're making sure
the player is running, else we don't want to play
the footstep sound effects. Okay, let's go ahead
and play here. And try again. I'm playing now. I stop. If I run, if I hold shift to walk,
not going to play. If I let go, awesome. Now it works, okay. There is a small
issue right now. You can see if I run a bit, it's not really going to play the sound effect unless
I run a bit more. What you need to know
here for the timer by event is the time
you right here needs to to run by before it actually plays this
code fit five for example. And I click on Play. It's not going to play
this code instantly. It's going to wait 5
seconds before it runs. The first instance
of this code there goes 5 seconds
before it actually begins playing the
footstep sound effects. As you can see here
it just played, the footstep sound
effect is 0.42 We need to play the sound effect right before it plays
this, just one time. We can do this here.
Whenever we are going to start playing
the sound effects. I can go ahead and remember, you can't run the multi cast
directly from the client. You have to run it through
the server as well. This is why I can drive
from here and write the play footstep
sound effects first. And then it's going to
play the multicast. After that I'm going to play the footstep sound
effect right away when I run after 0.42 seconds, it's going to begin
looping this code. Because if I don't do this, it's going to wait to 0.42 seconds before it begins
running all of that. This is why we have
a small delay. If you click, can play now
you can see it plays right away, so it's a lot better. Now also what you can do if you don't want
to play it right away, If you want to have
a slight delay in your sound effect,
what you can do, you can also click here and take this elapsed seconds
or trigger seconds. Both of them work.
Let me actually just use the one called
trigger seconds. What you can do is you
can drag from here, let's actually just
print a string. I like printing strings so you
can see what we are doing. Let us connect this print string to the code and just connect this trigger seconds to
print string. Let's play. You can see when I hold my key, just counts seconds of how long I have been holding my key. For example, not only my key, actually all of my
movement can say I'm moving, it counts. If I let go of my movement, it starts from the beginning. It just counts seconds of how long you have been pressing
the movement buttons. But what you can do is you can
track from this and say if the trigger seconds
is higher than, for example, 0.3 then we
want to go ahead and run. Let me just add another
condition here. We have a lot of
condition one here. The end we have a
lot of conditions. Let us plug it in, and
let's click on Play. It works, but now after 0.3 seconds it's going
to play the code. Now if you make it higher, it's going to play
it a lot later. After 2 seconds, if you click on Play and
run after 2 seconds, it's going to play the code. This is if you want to
delay it a little bit. If you don't want to play the running sound
effect instantly, you can have a small delay, maybe 0.4 instead
of 0.5 like that, and it will play a lot faster. You can see it doesn't play the sound effect whenever
you just do this. If you just click the key fast, but if you click
it slightly more, it's going to play
the sound effect. I think I'll put it to 0.3 I think it's playing
it way too late. If you do this, it's
not going to play. However, if you
press it a bit more, it's going to play
the sound effect. Okay. Now it works perfectly. Go ahead and organize the code. If you want to remove one
of the pins from the Or, for example, you can write
click and remove the pin. Go ahead and organize the code. Now everything is organized and you can see the code here, just in case you have
missed anything. I've also uploaded
this final project for you as well,
so you can follow. Let's go ahead and compile. Let's save everything, and let us move on
to the next lesson.
61. 6.01 Placing the Spawn Points: Okay, so now that we have
the movement finished, we of course still
need the movement for the pistol and the
movement for the rifle, but we will focus
on that later on. For now, let's continue to the player's spawning
for the player spawning, let's start placing
some spawn points for the player here in
the blueprints folder. Let's right click
make a new folder. Let's call this one
Span Points Again, let's right click this folder. I'm going to set the
color to this one. Again, inside of this folder. Let's right click now to
make the spawn points, we need the players start so the player can actually
start into the level. However, instead of having
it created from here, because this one right now is just created from
this, players start. However, we need
the spawn points that are actually blueprints. Instead of doing this
one, let's delete this. Players start from the
level if you want to make sure that you don't have more player starts
in your level, you can always just
come up here in the outliner and search
for players start. And you can see nothing is here. I'm going to click on the X
up here to make a new one. Let's right click go to Blueprint class now instead of selecting one of those here, you can click on
this small arrow, can actually see, you can make blueprints of almost anything. A camera, foliage, and even
the player starts and so on. So you can see you have 682
items you can search for, for example, a save game, when you are going to create a game where you save,
unload and so on. So you have a lot of
things inside of here. For now, we just need
the players start. If you search for a player
start, you can see it here. This one called Players Start. Select this one. Go ahead
and click on Select. Let us call it BP spawns. Going to auto save
for some reason. Let's call it BP
spawn point base. We have, we have a base
blueprint just like the player. If you go back to the player
we have a player base. And from that player
we created these two. Now I haven't really explained what these
are used for because we haven't really
anything inside of the terrorist and
counterterrorist blueprints. And this one we need
to correct later on. But now you can see
here they are empty, the children of the player base. Remember, these are the child blueprints of the player base. You can also see that if you
hold the mouse over them, you can see the parent
class is the player base. We are going to explain it in this section how
they are used for. Now let's go back
to the sum points. And now that we have
a base spawn point, let's right click it. Create a child blueprint class. Let's call this one BP
terrorist spawn point. Let's right click
this saw point base again and create another
child blueprint clause. Let's call this one BP
terrorist spawn point. Okay, we have a counter
terrorist spawn point and we have a
terrorist spawn point. Now let's go ahead and place
them inside of the level. Let's take the counter
terrorist first and place it into the level
somewhere, for example, here. And you can again click on E to rotate and you can rotate
it around. Just like that. You can see you have
this blue arrow and this is where the
player is looking. Because you can see
if I click on play, now the player is looking
in that direction. If I rotate it this
way and I play, the player is rotating
this direction. So to make sure that they are looking the correct direction, let's go ahead and
make it point toward that direction like this. Okay? Now you can always adjust
the bond points later on, but for now I'm
just going to place them where I think they
would be the most optimal. So for example, the
counter terrace here, you can always hold Alt
and drag to copy it. And you can place this
one here for example. And I usually put them
behind the defense here, because if you put
them here out here, they can just kill
each other right away. I usually put them
behind the wall so they don't get
killed right away. You can just place
a couple of them. This is a third one and
this is the fourth one. Okay? Just like that. You can even place one up here, but I don't want to spawn
anyone up here, actually. I just want to spawn
them down here. Again, for your game,
it's all up to you. You can choose where you want to spawn your players up to you. Okay, I have them spawned here. Let me do the same thing now
over here for the terrorist. Let me take this on point
and place it somewhere here. Again, I'm trying to place them as best as I
can behind the wall. Hold alton, drag to copy and I'm going to
place one over here. Now it says, oh, I
have the color picker. For some reason I have actually no idea what I just pressed. Clicking here and
dragging it here again. Hold place somewhere
here and hold Alt. Drag and place the
last one over here. I'm just going to take
a look at the side, see how they look. I can select all of them by holding control and
clicking on them. I can just move them
slightly closer to the wall. This is because I actually
want to place weapons behind those players or
behind those spawns. Okay. Something like that. I think it looks good. You can adjust those
spawn points as you wish, but I think this
is looking great. So now we have the terrorist
spawn points placed, and we also have the counter terrorist spawn points placed. So let's go ahead and save
everything and let us move on.
62. 6.02 Storing Spawn Point Information: Now that we have placed
all of these son points, let's go over and store
all of the information. Now I usually do this
inside of the game mode because the game mode chooses
the rules for the game. Now very important now that you're working
in multiplayer, it is very important
to know that the code you write here
inside of the game mode, is only running on the server if you are the player and let's
say inside of the player, you try here from the movement because remember when
you start the movement here you are firing the code as the player or as the client. And as the server,
you can always see which one you're firing as. If you just drag from here
and write a print string. Now remember a print string
is really powerful to use. And if you compile
and click on Play. And now when I move, you can
see it is now saying server. And when I move as my client, it's the client is saying hello. This means this code
here is running through the server and the client
and not the server alone. Now let me connect it. Let me take another example. Something that only runs
through the server. For example, if I go to
the crouch and I play it here from the authority for
example, I can compile. Click on play, and when
I walk as the server, nothing is printing out. And this is actually, now
when I click on play, I walk as the server. I'll actually crouch.
This is the crouch key. If I crouch, you can
say it says hello. However, if I play as
the client and I crouch, you can see the server
is saying hello. It is not the client
that is saying hello because this code
only runs on the server. Now, for the game mode, you can't access the
code here from a client. It has no access
to the game mode. If you want to write some code here which you need to
access from the client, this is not possible,
then you should not write it inside
of the game mode. Spawn points. Very
important to know, it is always the server that spawns things into the world. This is because we are
trying to avoid cheating. We always let the server
handle the spawning. For example, spawning the
players spawning a weapon into the level when the player drops it from the inventory
and things like that. Spawning is always handled
through the game mode. For the spawn points, we can
write them inside of here. Let's delete all
of this for now. Let's write click
inside of events. If you click on a
event, for example, and you click on game, you can see something called post login. You can also just write click and
write post login. And this event in
multiplayer plays. Whenever the player
connects to your map, connects to your server. Unpost login is just
like a begin play. Whenever the player connects to your server, something happens. Okay? So what we
want to do usually here is we want to
make a new variable. Make a new variable, you can
see the new player input. Here is a player controller, so you can actually store the player's controller when they connect and you
can use it later on. This is very useful information. Let us write connected players and the type is
player controller, then select this one,
Player controller object reference.
And let's compile. Since we want to store all of the player controls
when they connect, we have to make
this into an array. Remember this one is
a single variable, you can only store one
piece of information. However, in an array,
it's like a box. You can put all of
the player controls inside of this box and
you can use it later on. Let's take this one, let's
track from here and say Ad. We can add this
player controller to this box here with all of the player control with the
connected players here. Instead of using this ad, just avoid box I
usually just strike from here and use this
one called add unique. You can only have one instance of that player controller
inside of here, just in case the player
reconnects or things like that. We don't have two of this guy's player controller
inside of the array. Add Unique. Just adds one instance of that player
controller inside of here. And then to store the
information for the bond points. Now to get anything, this is very, very important. When you usually program
through my courses, I want you to pay attention to the tools I'm using. Sometimes important that we
are programming a first person shooter
or a two D game. Sometimes it is more
important to actually pay attention to the
nodes I am using. And imagine how
else you can use it in an RPG game when you
loot coins and so on. To store or to get anything
that is inside of your level, that is existing
inside of your level, we have to use a node
called Get Actor of class. If you're right click here
and say Get Actor of class, you can see now you can get anything here that is
inside of your level. For example, the players
start that we are using. If you search for players
start, you can see that. You can see it here
also, since it's not called players start,
this is not wrong. However, you can also get, if you go to the spawn points, you can get the
spawn point base, now that we have
it in blueprint, if you just search
for point point base, you can see it here. Get actor of class. Gets just one of them
here from the level. We also have another node
called get all actors of class. We're not only getting
onepoint point, we're actually getting
all of the spawn points. Actually, I just want
to separate them. You can just search
for span point base and you can add it and
call it Spain points. However, I'm actually going to separate them already from here. I'm going to search for the Cada terrorist spawn points. Spawn point. Make sure it is the spawn
point that you select here. I'm going to right click here, promote it to a
variable and call it Cada terrorist spawn points. Now I have them inside
of this array variable. Okay, next we can again say
get all actors of class, We can get the
terrorist spawn points. Now if you can find
terrorist spa point, let us connect it here again. Let me right click this one, promote this to a variable, and call it terrorist spawn points. It is getting all the actors of class
of terraced spawn points, which is all of those here. It's getting all four and we're now storing it inside
of this array. All right, now that we
have this stored, again, you can always try to print
a string if you want to, right click print a
string just like this. You can try to get
this one for example, right get and get
a copy of this. Again, if you don't remember
the functions for an array, you can just search
for array and you can see all of the functions
that you can use here. For example, you can say get, if I can find it
here, this one here and you can connect
it. Now you're getting the Spain
point at index zero. And if you play you can see it's called terrorist spin
point like that. If you get the spin point
at index one in this array, it's called spin 0.2 If you
get the one in the index two, it's called Spin 0.3 You can see this array actually contains
all of the Spain points. Very useful, again to use Pin strings when you
want to debug your game, are just interested in
seeing what this variable, for example, is
actually storing. Let's go ahead and compile, save everything,
and let's move on.
63. 6.03 Importing the UI Assets: Now that we have the Spain
point information stored, we're actually ready to create some UI before we
finish the spawning. So let's go ahead
and import the UI in the cost materials
that I have given you inside of the this website, you can go at and
download it again. If you don't have it
downloaded already, you can go inside
of the UI folder. In here I have buttons for you and I have the icons
and I also have images. Now if you click on the buttons, let me go inside of the
engine actually first. And let me create a UI folder. Let's right click on
the content folder. I'll make a new folder
called I inside of here. Let's right click and
make a new folder. And I'm going to call it,
for example, buttons. I'll make a new
one called icons. I'm going to make a
new one called Images. Let's start with
the buttons folder. Let me go inside of
my course materials. Take all of the buttons here and click and drag them
into your punt browser. Just like that, you can see
all of them imported Awesome. Now for these here, if you just open one of them, you can see they are important
and everything is correct. To make them a bit better and to not make them blurry or any
errors inside of the game, you have to change the
texture group to UI. You also have to change
the compression settings to user interface two
D. Then it actually knows that it is a UI element and we don't have anything that is blurry or some white line
behind this UI and so on. And you actually have to
do this for all of them. Now I will show you a trick. We have used this before. And if you just
select all of them, you can write Click
Go to Asset Actions and Bulk Edit via
Property Matrix. Now we have done this
with the animations. If you remember, you can also do this with the UI
elements inside of here. Let's click on compression here. Make sure in the
compression settings make them into a user interface. Two D, let me actually
see what the other one, I think it's in the
level of detail here. A group select this one
and make it into UI. Now you actually have
changed it for all of them and we don't need to
do it for every single one. Now you can see if you click
on one of them, for example, you can see it is UI and
user interface two, awesome. Everything is looking
good. Let's go ahead and click
on File and Save. Let's go back to the
course materials. Let's go back to the icons Now, you might see more icons that what you can see
here on my screen. Again, this is because I usually put icons as I
develop this course. Later on I will add more icons, but in your example or in your
content course materials, you'll probably see more icons. Don't get confused, we are
going to use them later. But for now I just
have these two. And I'm going to go to my icons and I'm going to
drag them into here. And again, just like
before, click on it, make it into a UI and into a user interface two D. I'm also going to do
it for the other one, user interface two D.
Okay, so these are ready. Let's go over again
to the images now. And let me open up
my cost materials. Let's go back to images. Let me import all
of them into here. And sometimes it's
actually going to make them into a normal map
as you can see here. These ones were imported as normal maps and I
don't want that. And click on Revert, Reverse and revert it will not make
them into a normal map, so go ahead and click
on the first one again, select the last
one, right click. Go to Asset Actions and Bulk
Edit via property matrix. Open up the compression select here in the
compression settings. Select user interface,
two D in the level of detail in the texture
group, select the UI. Let's close everything down
and let's save everything. Now that everything is ready, let's move on to
the next lesson.
64. 6.04 Importing a Custom Font: All right, so now that
we have the UI added, we actually also need some
fund that we can use. Some text, customized text, And you can find it if
you write Google funds, this is really nice
to use because they are free and they have
a lot of cool funds. If you go into the Google funds and click on it,
this is out of here, one of the funds that you
want to use in your game. What I usually do is
here in categories, I usually remove the display,
handwrite and monospace. Again, it depends on what
style you want for your game. As for the number of styles, I usually like funds that
have a lot of styles because I know they are looking
good inside of the game. For example, we can use
Roboto or Open Sense. Or you can also use, for
example, something like Rubic. I think I'm going
to use Rubic again. Choose whatever you
like, doesn't matter. I'm going to choose Rubic and then click on
Download Family. It's going to
download it for you. I can click it and open it up. And here you can see all
of the static funds, clicking on the static ones, and here are all of
the funds, okay? What I'm going to do is
I'm going to minimize all of those here on my desktop. I'm going to put them
in here first because this is a folder and you
need to extract it first. Because if you try to import
things from a Sip folder, it's not going to let you, it's going to give
you this error here. Again, I'm going
to minimize this. Usually you don't really need very light
funds like this one. Rubic light, because it is
really hard to see in game, I usually just take
the very bold ones. Rubric, bold, extra
bold. Let's choose the semi bold as well, there's a regular medium. I'll take the medium one
and just click and drag them into your desktop
to extract them. Now I'm going to
close this down. So now that we have those funds, we can go back to Unreal
Engine and let me just make a new folder actually
here in the UI folder. Let me right click and make a new folder called
funds Go in out of here. And I'm going to drag those
into my funds folder. And I'm going to ask you, would you like to
create a new fund asset using these imported funds? I'm going to click and
apply to all D. Yes, I want you to do this. It's going to create
a fund for you. Go ahead and save everything. And now you can actually
use this fund if you go into any UI we are
creating in the future. You can change the fund to one of these so
you can see a very, very easy way to add this. Okay? So now that we have
added funds into the engine, let's go ahead and I'll introduce you to
Widgit blueprints.
65. 6.05 Introduction to Widget Blueprints: Let's now go ahead and
make a widget blueprint. The widget blueprints
are basically the UI here inside
of Unreal Engine. So if you right click, go to User Interface and
create a widget blueprint. But then create
it and select it. Here, up here, the user widget. And let's just call it WB. And I'm going to call
it team selection, because we are creating the
team selection where you can select to be either
the terrorist or the counterterrorist. Let's open up this
widget, blueprint. Inside of this
widget. Blueprint. It almost looks like the blueprint viewer that
we have been working with. You can write, click
inside of here and pan around to the left. You can see all of the elements inside of the palette
that you can add. For example, we can add images, buttons, borders,
sliders, text, and so on. We will be working a
lot with all of this. There is also a hierarchy. For example, if you click and drag this button
into this hierarchy, here you can see we
have this button added. It looks very weird right now, But we have a button added to our steam selection,
Widgit Blueprint. Now again, you can
compile to make sure you don't have any errors,
just like in Blueprint. And you can play the game
at test and see your game. However, we haven't really displayed this UI
into the level, so you can't see
anything in game, okay. And to the right you
have a details panel. If you click on the
button for example, you can see you can change
things about this button. You can change the style, you can change the color, and you can also
change other settings. We will be working
with those now. The Wiga blueprint is
divided into two sections. You have the designer right now, you're designing the UI. And then you have
the graph where you code the buttons and so on. Here is all the code,
the blueprint or the UI. For example, here in
the graph you can code, for example, if you click on this button, what should happen? This is done here in the
code here you design, here you code the
functionality of the UI. Okay, let's go ahead
and delete this. And the reason why it looks
so weird is because you actually need to add something
called a canvas first. If you search for canvas, you can click and drag this
into the hierarchy first. And now you can see
you have a canvas. When you have a canvas now, you can add elements to it. Now usually I don't
click on these lists, but if you're very new here, you can click on all of them. Try to read what you can
actually do inside of here. That is actually really good. If you're new here however, I usually just
search for elements. You will get very
used to it because we are actually going to
work a lot with this, The same elements that we
keep using again and again, you'll get very
familiar with it. For example, you can
search for a button and you can click and
drag it into the canvas. And you can see when you
add it into the canvas, it is also added
in the hierarchy. Whatever you see inside
of this hierarchy, it is also inside
of your designer. Here in the canvas, for example, you can click on this button
and you can resize it. Or here in the details panel, you can also resize it here in the size x and the
size Y as well. For example, you can
search for an image, you can drag an image into here as well. You can resize it. Click on the image,
click on the brush, and you can change this image. For example, you
can change it into, let's actually
import some icons. If I search for ICO and
select one of the icons, and you can see here
we have the icon imported and you can
play around with it. You can also click
on Size To Content. This will actually size it to whatever size you have
here in the image size. You can increase and
decrease this as well. Usually when you click
on these small arrows, it defaults them to whatever resolution
you have imported. For some reason, it's not
working for me right now. I don't know if it's a bug in real engine or whatever it is, but it usually works
however it should actually resize it to whatever
size you have imported as. And as you can see, the
dimensions for this icon is to 256 by 256. So it should make it
256 like this one. I press here, but for some
reason doesn't do it. But this is actually
the original size of this image here, and if you click on
Size to Consent, it actually resizes
it to this one here. Okay, So you can
just play around. We have the button,
we have an image, and you can also just
click on all of those. Actually, it doesn't
matter if you just strike everything
in out of here. Just click on it, try to see
if you add a value to it. See that you can actually
move this slider. And you can click on, for example, Editor Input. For example, Editable text. You can place it here
and see what happens. You can write something inside of this text and just
play around here. It's actually really fun to just take a look at what's
inside of here. And I'm going to
click and click on my Delete button and
delete everything for now. And I'm also going to
delete the canvas panel. Go ahead and compile,
save everything. And let us move on
to the next lesson.
66. 6.06 Displaying the Team Selection UI: Let us now go ahead
and display the UI before we actually design
it to display the UI. Usually when we work with UI, we do it inside of the
player controller. This is where we control the UI going inside of
the player controller. Let's go to the
event graph in here. What we usually do
in single player, we take this and say create
widgets, just like that. Create widget, and then
you select the widget, for example, WB team selection. And then we usually add this to the viewport, just like that. And then we can click on play, and we're happy we should
be able to see the UI. And when I click on Escape, you see I get an era. And this is because we
are in multiplayer now in order to display the UI and we can actually
see something. Let's first go
into the UI again. Let me just add a canvas again, let me add a random
image because I actually want to see if it is added
to the viewport or not. So I'm just going to add this
weird image here to my UI. And I click on Play,
And you can see it's actually displaying
on my screen, both on the client
and on the server. I am actually displaying
the UI right now. However, if I click here, if I click on Escape, you can see only local
player controllers can be assigned to widgets. Remember, when we
are working with UI, we don't really need to
run it through the server. This is because every single
player has their own UI. It's not like a
weapon you have in game where you have
to run it through the server and then the server needs to replicate
that information to the clients and tell them that you have a weapon here
laying on the ground. It's different for UI, every single player
has their own UI. It's not like it's
running through the server and then the
server is updating their UI. It's not how it's happening. It's happening by just
every single player as their own UI. It's not running
through the server. When you work with UI, you have to run it
through the client. Remember, every
time you have UI, you have to run it
through the client. Let's delete all
of this for now. What I'm going to do is I'm
going to right click and make a new custom event here inside
of the player controller. Let's call this one
show hide widget. Basically, what this widget or this event is going to do is going to either show
or hide the widget, depending on what
you tell it to do. Now we have to give
it two parameters. What widget is it
going to show or hide? And is it going to show or
hide it? Here, let me just this bull in name to show this will either
be true or false. If it is false, it's
going to hide the UI. If it's true, it's
going to show the UI. We can use this bull in here. However, for the second one, we have to tell it which
widget are we talking about. We have to make an enumeration. Let's minimize this. Go to the blueprints to
enumerations folder. Remember, we made this one called movement states earlier. Now let's right click
and make a new one. Go to blueprint and enumeration. Let's call this
one game widgets. We can make a list of all of the game Widgets that we have. For this one, let me add a
new enumerator, a list item. Let me call it team selection, because right now
we want to make the team selection widget. You can also make one later on. For example, the Mau I, which is actually the main one with your health and so on. You can also make a new one called Escape menu when
you have one and so on, but for now I'm going
to delete those. I only have the team selection. Let's save now inside of
our player control law. Let's click again on our Event. Let's change this type to E.
We called it game widgets. And it's this one,
this enumeration. Go ahead and call it Widgets. And here we have it.
So let us compile now. As you can see, if
I write, begin, play, and make the
begin play event. If I drag from here and call this event, show hide widget. Show hide widget,
you can see now I can select which widget or
what widget I'm talking about. And then I can select
if I want to hide it, meaning the show is false. Or if I want to show the UI. And we can run the
code through here. Okay, so very, very cool. Now let's continue the code. I told you that this needs
to run on the client, so all of the UI that you create needs to run
through the client. So let's right click and
make a new custom event. Let's call it CL for
client, show hide widgets. And let us run this through
the client and reliable, just like the one up here, we need the two inputs. Let's create the two inputs. The first one is called widgets and it has already
selected this one. The second one is called show
the bullion. Show or hide. And let us select the
bullion as the type. We have to run it through here. Choose the CL, show, hide widgets here as well. So we are connecting the
client event up here. And go ahead and
connect it together. Okay, So what is happening right now
is in the Begin Play, when you start beginning
playing the game, I'm going to show the team
selection UI instantly. So I'm going to
tick this and I'm going to show the
team selection UI. When I do this here
in the begin play, the code is going to
run through here. So it's going to put this information into the client one. And now this
information comes out here and we can
use it as we like. Now I'm going to
drag this bull in and write a branch
because I want to know, am I going to show the UI or
am I going to hide the UI? Is this false or is this true? This is what I'm asking
right now. Now if it is, let's make a new function. Let's make this function
called show widgets. Let's make another one
called Hyde widgets. Again, click on them and add a new input of the
type A widgit. The enumeration that we made
before and call it widget, again compile because
we need to know what Widgit are we talking
about in the Hyde widget. Make a new input
and call it widget. Again, make sure that type
is game widget as well. Okay, let's go
back to the graph. Let's drag those functions we just made. They
are still empty. There's nothing inside of them. But for now, let's just
add them here. Okay, show hide widget. If it is true, we need to show the widget. This one, I can connect it. If it is false, we need
to hide the widget, and we can select it here. Now, what widgit are
we talking about? This information we have here, because we have set it up here, we can connect those into the inputs we just
made for those here. Now this information goes
inside of the function. Now we have this here, and
we can do whatever we want. What is our goal here?
To show a widget, we need to use the
node called create widgit. We need to
use this one here. Then we have to select which
widgit are we talking about. This one for example, here, as you can see for
the enumeration, we could have a lot of items. We need to know what is the
value of this enumeration. We do that by just dragging from here and
search for Switch. And we have this
one called Switch on enumeration. Go
ahead and select it. And now it's going to give
you an execution pin, depending on what
list items you have. For example, if I go back to my enumeration and
let's say I have a menuI and I have
an escape menu, just like that, for example. Go ahead and save it. And let's go back to the
player controller. Now you can see I
get execution pins, depending on my list items, whatever you set up here. So if I go back,
whatever you select here is going to go
through this event, put it inside of the client one and it's going to
continue the code, put it inside of the function. Now it knows you
are talking about the team selection because
you have selected it here. So it's going to run the code inside of
the player selection. It's not going to run the
code that is written here. And it's not going to run the
code that is written here. Only going to run the
code that is written here because you have set the
value to team selection. It's only going to run it through that execution
pin right now. That's how we do it.
Let's actually just delete those for now. We don't really need them, we only need the team selection. Go ahead and save and
compile this as well. Okay, to create
or show a widget, go ahead and create the widget. Select which one
you want to show. Then let's right click it and
promote it into a variable. Because it's really
useful with the variable, we can use it later
on to run events. This one I'm going to call WB selection. Now that you
have created the UI, now if you click on Play, it's not really going
to show anything. This is because it's not sufficient to just
create the UI. You also have to drag from
here and say Add to Viewport. Now it is added to the Viewport. Now if you click on Play, you
can see now it is added to the viewport and you don't have any errors when you click
on the Escape button. Okay, this is looking good. Now to make sure you don't keep adding this to your viewport
without any reason, let me actually just disconnect
here and move this away. Let me take this variable,
drag it into here, right click and convert it into a validated get, go
ahead and connect it Now if this variable
is not valid, meaning we haven't created
this variable yet, the program or unreal engine doesn't really know what
you're talking about with this variable because you haven't put any
information inside of it. This means we haven't
run this code yet. If it is not valid, go
ahead and create the UI. However, if it is valid, if this variable already
contains the widget. So we have run this code before. We don't really want
to run it again, We just want to go
ahead and add it to the viewport, just
like this, okay? So this avoids that we create
the UI again and again. If it is not valid,
go ahead and create the UI and then add
it to the viewpoort is valid. However, go ahead and just add it to the viewport. Let's go ahead and compile
and save everything. Now for the hide widget
here, same thing. Let's strike from here and
say switch on enumeration. Let's take this variable, now that we have created it, let's right click convert into a validated get. Go
ahead and connect it. Now if it is valid, meaning
we actually want to hide it. Now let's strike from here
and say remove from Parent. That's how you remove
UI from your Viewport. Remove from parent,
if it is valid, go ahead and remove it, because we want to hide it. Now, if you compile
and click on Play, you can see the viewport. In the viewport, you
have added the UI. If you go ahead in the
player control event graph, if you just remove the show, because now it's actually,
when it's false, it's going to run through here and it's going to
run through here. And it's going to show false because you
have set it to false. Meaning it will go ahead and
hide the UI, the widget. And it knows what widget
you are talking about, because it is feeding that
information into here. And it's going to hide
the team selection UI. As you can see here when I play, I don't see the
team selection UI. But for now, we
actually want to show the UI ahead for
the team selection, go ahead and click on Show. Now it should work perfectly. Now if you want to make this more organized,
you can always click and make execution pins, or you can go ahead and
select all of them. Click on C on your
keyboard and call it, for example, Show
Hide UI and so on. So just go ahead
and stay organized. But for now, let's go
ahead and compile, save everything,
and let's move on.
67. 6.07 Dynamic UI Size for All Screen Sizes: Now, before you start
designing the UI, it is really important to know what the UI looks like
on other screens, not only your screen,
but my screen. If you design your game, you have to know what it
looks like on my screen, which is a four K
resolution monitor. And also on a laptop
screen and so on. So you have to
resize it correctly. Let's actually learn this
before we actually design, because it will be a later on if you design
it in a wrong way. For example, let's go into
the widget blueprint. Let's go ahead and
add some text. This will be the
easiest way to see it. Adding some text
screen and let us say I am resizing something
like that, whatever. Now that you have that inside of the UI, let's
go ahead and compile. And go ahead and click on Plate. Now this is what it
looks like on my screen. And usually I just take up my widget blueprint and
I take up my game here. And I usually just
try to compare it. Go ahead and open
up your game here. I'm going to minimize
it slightly, and I try to see what it
looks like in the game. This is what it
really looks like. If I compare it to here, it looks a bit larger here, it actually looks like this. When I zoom in and out, you can actually see
the zoom up here. Right now I have
zoomed plus three, and now it looks correct. At zoom plus three,
it looks correct. Now, this might look a
bit weird to fix this. Now go up here in
the screen size. Usually what you want
to do is you want to, in the UI to the smallest
screen possible. If you to design it
for mobile games, you have to click
on the screen size, Go to phones and then
select the phone. You want to design it
for the smallest screen. Right now, I just want
to make a computer game. I'm going to click up here. Usually I design it for laptops. These generic 14,
15 inch notebooks. I'm not going to right now. I have a four K monitor. I can select this and
just design it here. However, it will
maybe look like this on your screen if you have
a one K monitor and so on. Very important to
design it correctly. First, let's click
on the screen size. And I'm going to select
the generic laptop size. Right now, if I zoom in
and it is one to one like this here at
the laptop size, right now, I'm actually looking at it and seeing
what it looks like. If I open this game
right now on my laptop, this is the size of the text, For example, on laptop,
let's click on this fund. Click on the fund, and I make
the size, for example, 30. This is now what it
looks on the laptop. But if I play, now this
is what it looks like. On my four K monitor, you can see there
is a difference. This is the laptop. This is me. I see it a lot larger on
mine than the laptop. If you don't like that,
if sometimes the UI gets too big on the
larger monitors, you can click on this
button down here. Here you can see the
scaling of the UI. The generic laptops
are down here. As you can see, this
is the resolution one. I'm designing it
for these laptops. Right now I have
a four K monitor, and it's actually over here. You can see at a four K monitor, I'm scaling it up by 3.8 It is 3.8 larger than
what a laptop is. Now, if you don't want to
scale it up this much, you can select on this
one, this resolution. Instead of scaling to eight, I'm going to scale it
to four, for example. Now you can see
it's not going to scale up this much
compared to before. Now if I click on Play, it's actually smaller
than what it was before. If I go back,
actually click here, let me just increase it
to something like 18, so you can actually
see something extreme. If I click on Play, you can
see it now it is very large. Usually what I like, if I'm satisfied with the size for the laptop, I try to scale it. So I'm also satisfied
with my four K monitor. Usually it is around
2.5 in the scaling. I don't like to go too much. You can click on these buttons. It, it to your screen like that. I'm just going to
zoom out slightly. Maybe just click on, I'm going to zoom out slightly,
so it looks better. Let me just click on play Now, I think this looks nice. If I need to size it more, I will resize it. But I think this looks nice. You can compare it now, and it almost looks the same. I will try to design it with
the scale of 2.5 but again, just go ahead and
play around with it. Just scale this up and down, depending on what it looks on your monitor compared
to the laptop monitor. Okay, when you're satisfied, let's close everything and
let's save everything. Let's move on to
the next lesson.
68. 6.08 Designing the Team Selection UI: Now that we are
displaying the UI to the screen and we
have the correct size, let's go ahead and
design the UI. Let's close down the game. Let's go over to the UI folder. And here, inside of the team
selection widget, blueprint. Now let's delete this here. The only thing we have right
now is the canvas panel. Again, if you haven't
added it yet, go ahead in the palette
and search for canvas. And go ahead and add it to
your widget, blueprint. The canvas is very important. You have to add this
before you do anything. The thing we want to design
is the team selection. This is from my other project. I'd like to display the UI to you so you know
what you're designing. This is what we want to design. Whenever you start designing UI, you have to imagine
what you want to design because it will
be a lot easier for you. This is what we are
going to design. Let's go over here. The first thing we want to do, we want to break down the UI. If I take this
again here for you, you have to break it down. As you can see here, we have a background and we have
some text on top of it. When you have two things
on top of each other, you have to use this
one called an overlay. When overlay overlays items
on top of each other, when you have something
on top of something, think of an overlay
dragging it into here, and let's search for an
image, for the background, and place it here as well, inside of the overlay.
Just like that. Let's just drag this into the middle of the canvas
so we can see what we're doing just resizing this overlay to fill this image. You can see it's very small. To fill this image
to the whole screen, you have to here in the horizontal and
vertical alignment, click here to fill,
horizontally and vertically, it fills the whole overlay. It doesn't matter how
large your overlay is, your image is going to
fill the whole thing. We want to fill it
with the background. Now the background, you can
click here for the image, and in the brush here, click the image and
you can search for, I think I called it panel. And this one panel blue. Again, it's up to you
what you want to use. You can use another color, but I'm just going with the
blue one. And here it is. Okay. Neral engine, to make things not blurry like this and to make them
stretch correctly, you have to change this
instead of an image, you have to change
it into a box. Now, before I do this, let me actually show you how it works. If I go to the UI images
and I search for the panel, you can see if I hold
the mouse over it, it's actually a
very small image. It's 68 pixels by 68 pixels. If you open it up,
this is actually how large it is when I
designed it in Photoshop. This one you can make very large and still look
good in Unreal Engine. If you just add the image, paint the draws into a box
and then change the margin to 0.5 as if you click on this one. Here you remove
these dashed lines. I'd like to do that to see my UI without
anything distracting. And this is what it
looks like you can see, even though it's a small image now you can just
click on the overlay and stretch it and
make something else out of it without
it being blurry. Really cool feature
in Unreal Engine. You don't have to design
every single button, You can just design the base, and then you can design the buttons themselves
inside of here. This is our background
for the team selection. Now for the team selection, we also, if I drag
this into here, again, we have some
text under it. We have these buttons. We have something
called a vertical box. If you go over here and
search for vertical, you see this one vertical box. I'm going to add
it to the overlay. Now in the vertical box, we have some text at the top as the title. As
you can see here, we also have these buttons. Before I add these buttons, you also have to
break this down. You actually have
a horizontal box. These are aligned
horizontally to each other. If I search for a
horizontal box, this horizontal box, you have to place into the vertical box. We have the title, we
have the title here. And then we have
the horizontal box where we add the two buttons. Okay, this one over here. The title actually needs
to go in the middle. I'm going to click on the text, align it here horizontally
to the middle. And you can see nothing happens when I align it to the middle. Sometimes when you do
this inside of a UI, don't get confused, you have to look at the parent as well. It doesn't matter if the text is aligned like this or if the vertical box is
not aligned either. You can see the vertical box when you click on one of them. Here you can see that the vertical box is
actually only this section. It doesn't, if you
align this text here, here, and here, you
only have the space. It's not filling
the whole thing. Clicking on the vertical box, I have to fill it
here on this overlay by clicking on the
horizontal alignment and vertical alignment. Now you can see it is. Filling horizontally
and vertically. Okay, Now when I align
the text, it should work. Always pay attention to the parent up here,
how it is aligned. Because if it's
aligned like this, this text is never
going to go here. Go ahead and horizontally
align them like this. Now to give more
space to the edges, we can click on the
vertical box and we can push it down here in the
padding or the left. Actually, you can also
write a number up here, for example, 50 or 102030. You can see you can push
it from the edges 50, 60, and so on. And if you want to push it
specifically in directions, for example, the left
I will put to 55, and the top I'll put to 45. Not as much as the
left and right. The right is 55 and
the bottom is also 45. Something like that. Remember,
I am in zoom plus two. The real size is
looking like this. Just pay attention
to what zoom you are in because you might
be too much zoomed in. This is what it actually
looks like right now. I think the spacing to the
edges is fine right now. What you can do
is let's go ahead and continue our design. And then we can go ahead
and stylize everything. Let's click on the
horizontal box. Now for the horizontal box, we have these two buttons. Now again, we are
overlaying a button. On top of it is an image
and we also have some text. Again, you have to
use an overlay, else you can't overlay
things on top of each other. Inside of the horizontal
box, we have an overlay. Inside of that overlay, we have a button, and then we have an image, which is the icon of the button. We also have some text. If I search for text
and add it here, we have the button, the
image, and some text. Clicking on this overlay, actually, this horizontal box, again, we have to fill
it here. So you can see, even though I am aligning it
horizontally and vertically, it's not aligning vertically. And this is because you
have to click Fill, and it's going to
fill the whole thing. Clicking on this
button, let's go ahead and add something
to this button. Click on the button,
go to the Style, click on Normal up here, and select the button. I'm going to select
the red button. And usually I call buttons BTN. You can try to search for
what button you want to use. Again, it is optional,
it's up to you. However, what I want to use is this one called Button Red, I believe, or Button
Square red, like this. And I'm going to choose it here. What you can do is, again, let's tint. I'm going to
click on the tint, and I'm going to
put it to white, because I don't want any
gray tint on my button. This is actually the real color. If you put it to white here, the rounded box,
I'm going to change it to a box, a normal box. Again, the margin, what
I told you before, set it to 0.5 and it
will look normal. Now let's see if we have other things to
change and we don't, if you want to copy this
setting over to the hovert, you don't have to
do all of this. Again, hold shift
and right click. Or again you can just
right click and copy. But you can hold shift and
right mouse button to copy it, and shift and left mouse button to paste it
for these two as well. Remember to click on the hoverd. And remember as well to change the hoverd
one to the hoard. And click on the pressed one
to the, pressed this one. Okay. We also need maybe
to adjust the image size, but let's do that later. For now, at this one you can
see it's very stretched. So what I'm going to do, I'm going to click on the overlay, and I'm going to click on Fill. So it fills the whole thing. Then let me actually
copy it again. Clicking on this overlay, I'm going to click on Control D, and that will copy
the other button. So I can actually see what it looks like if I
have two buttons. So now I have these
two overlays, and let us put a
spacer between them, Search for spacer and add them between
these two overlays. And then let's add some space
between these two overlays. This is the x axis, and this is the Y axis. And we need space in the x axis. Let me write something like 50. And now you can see
there is some space. Now for this text. I want it to be at the bottom of
this button here. Clicking on the text,
I'm going to align it to the button here and
also in the middle. And the same thing with
this one bottom alignment and in the middle horizontally. Okay, now for the buttons. I don't want them to be
stretched like this. Clicking on one of the buttons, instead of aligning
it vertically, I'm going to click
on the bottom here. The same thing here.
Click on the bottom. Align vertically, like that. Instead of aligning
it vertically, let's actually
control it ourselves. Click on the button, you can
click on the Image Size. Here, this is the Y
increasing up and down. You can increase the
Y for the button, and you can choose
how large it should be for this one and this
one, something like 160. For now, 160. Let's actually add
the icons before we can decide what
size it should be. I'm going to do
again for the image, is aligning it in the middle. Let's actually do it
for both of them. Let's click on both of them. Click on one old control,
click on the next one. Let's align them in the middle
and at the bottom again. To push them upwards again, we can use the padding, pushing them from the bottom up. So you can push
them, for example, 40, something like that, 50, 60. You can see you can push
them up something like 40. Let me actually just
change the icon first. Click on the image, and
let's change the icon. If you search for ICO for this one I'm going to
select the counter or the terrorist
for this one I'm going to choose the
counter terrorist. Here we can see they are
very small for some reason. Again, these buttons don't work, so I have to add
the size manually. If you just go down
here actually, and click if I go down
to the UI to the icons, if you hold the mouse
over these icons, you can see the dimensions. The true size is 256
pixels by 256 pixels. If you can click on it,
if you write 256 by 256, this is actually the
true size of the icon. However, this is way too large. But just be aware
that if you increase it more than the maximum
size that it has, it will actually be blurry.
Don't go over that. What I'm going to do
is maybe I'm going to make it like 150 by 150. And the same thing for
the counter terrorist, the size 150 by 150. Okay. Something like
that. Now, to control how far up and down
these buttons are, you can click on
the vertical box, actually the overlay itself. And then you can just
resize the vertical box. And then choose how far up and down these buttons should be compared to the title. Clicking on this text as well. I want to stylize these texts. Remember we added some funds from Google funds,
The Rubic one. We can always click on the text, click on the font family, and then choose one
of the rubic styles. For this one, I'm just going
to choose the rubic bold. And then I'm going to set
the size to a bit smaller, maybe something like 22. Instead, I'm going to add
some outline to the text. If you just select
both of them again, go to Outline Settings. I'm going to set the
size to something like, you can try 1234, I think something like
three is fine here. And then also change the color. I'm going to change the
color by clicking on the Outline color and then
taking the color picker. Then I'm going to
pick dark color, maybe this one here. Go ahead and click on it and
it will pick that color. You just have selected. Okay, for the text, if
you want to push it down, you can always try this
bottom here, for example. Minus two, minus five. You can see you can
drag them down. If you write a plus number, you actually push them
up. Something like that. You can also use
this one down here, the translate, if I can find
it down here, the transform. And then translation, you
can translate it in the y. If you write two
here, for example 56, you can also push
it up and down in the translation for this one may be something, two is fine. We just pushed it down slightly. Okay. I'm going to stylize
this text as well. Click on it. Go ahead and
select the Ruby bold. This one I made 22. This one I'm making 24
because it's a title. And then go ahead and select
the outline settings. I'm going to put it to three,
just like the other ones. For the outline color, I'm going to maybe this
dark color or this one, I'm going to pick this dark color and go ahead and click on. Okay. Now you can just go
ahead and change the text. For example, select
a team for this one. I'm going to write Terri
for the other one, I'm going to write terrorist. Okay, for the daterrist. Actually I want to
change the button. You can click on it,
change this button. I'm going to change to square, I think square green. And go ahead and
select square green. Just like that. Again,
just like before. You can copy this on
top of the other ones, you can click on the text, click on the Outline Color. Take the color picker and
select this one instead. Okay, I think this looks
a lot better than before. Okay, now let's
see what is wrong. Now if you click on Play, it's always nice to compile. Click on Play and see
what is happening. Right now you can see the, the UI or the steam
selection widget is actually on the top of the image and not in the middle. You can see if you
click on the canvas, it's actually over here. If you just drag this overlay
down here, for example, at the bottom right, and you click on Play, you can actually see
it's in the middle. That really doesn't make sense. It should be down here,
because I just placed it here. This is a very important
concept that you have to understand these anchor points. They are very
important right now. What is happening is you have
the anchor point up here. If I click on play, I try to
maximize the screen here, you can see this UI is getting. Towards that end of
the screen up here, it's going to be pushed up here. This is because your
anchor point is up there. It's not going to stick
down here as you wish. You have to change
the anchor point. Remember to always
do that for your UI. Clicking on the overlay, you have to change the anchor
point by clicking up here. As you can see here, only the parent has
an anchor point. All the other ones don't
have anchor points, only the parent one. Clicking on that one, go
ahead and click on Anchors and then select where you want
to align it. For this UI. I want to align
it in the middle, selecting the
middle anchor point to the middle of the
screen like this. Then for the position, I'm going to write 00 to
align it in the center. But as you can see, it's
not aligning to the center. It's actually an to
that point over here. This is where you have to
play with the alignment. If you just increase this one, you can see now you are
increasing it correctly. It is in the middle,
at the position 00. Now for this one, you have to write the exact
number instead. 0.50 0.5 You can see here, if you write zero
in the alignment, this is the x alignment. It is going to align this way. If you write 0.5
it's in the middle. If you write one, it goes to the other side the alignment. You can either write 00 point
5.1 You have these options. I'm going to write 0.5
by 0.5 because it will align this in the middle
and at the position 00. Now you can see it is
directly in the middle. And if I compile and play, it should be in the middle. It doesn't matter what
size of screen I have, it's going to stick to
the middle of the screen. Okay. The next issue
that we have right now is the mouse
doesn't really appear, and we're going to do that later on. We're
going to fix that. However, if I try to hover
my mouse over the buttons, they're actually bugging out. And I have to fix that. This is because if you click on the button and you
click on the normal, you have set the image
size to 32 by 160. However, for the
hovert, the image size is still very low. You have to copy the image
size from the normal one, based it on the hovert as well as the pressed all of them. And do the same thing
for the green one. Copy this, based it on the hovert image size and on the pressed image size as well. Let's go ahead and compile, okay. Click on play. Now, again, if I hover
my mouse over it, you can actually see I can hover my mouse
over the button. However, when I put my
mouse over the image, I can't really over the button, and the image and the text are actually
blocking the button. Let's fix that. Click on the
images, all of them here. And the text as well. You have to find this
one called visibility. And you have to set it
to non hit testable. And what that means is the images and texts
are just decoration. I don't want my mouse
to interact with them. I choose this one non testable, and that will make
sure that these are not interacting
with my mouse. Now when I click on play and
I try to hover the button, you can see it also hovers even though I'm hovering
the icon and the text. Okay, so that was it for the CI. The final thing I want
to do is I also want to make the background blurry because as you can see,
everything looks fine. However, I also like my
background to be blurry. Now it is optional. Maybe
I'll remove it later. But for now, let us search for blur and let us put it
here in the background, so over the overlay
outside of everything. Now for this one, again, remember to change
the anchor point. I want this blur to
fill the whole screen. As you can see, for this blur, you can change the
blur strength. So something like 50
as you can see here. But I want it to fill
the whole screen. What you need to do is
click on the anchor point again and go ahead and fill the whole screen.
Just like that. And change the offset to
0000, just like that. Now it's going to fill
this whole screen. And if you click on Play,
the screen is blurred. Now for the blur amount, I'm actually going to reduce it to something maybe like ten. This is because you can
also see the background, really cool effect while
you are selecting the team. When you join the
game, you can see the other players are playing
while you select the team. Okay, so now that
we are finished, go ahead and save everything and let's move on
to the next lesson.
69. 6.09 Button Sound Effects: Now let's go ahead and add some sound effects
to the buttons. And to do this, let's go
over to the cost materials. And inside of here,
let's go to the audio. And I have those sound
effects for you. The button hover
and button pressed. Let's go over to the
audio folder as well, and the engine and
sound effects. And let's just drag them
into the content browser. Now let's right click on
the button, hover, Create. And I'm going to call
it, so button hover. For the other one, the pressed, let's right click
Create Q and call it Sound Button press. Let's go inside of both of them. The hover and the pressed. Let me put down
the sound to maybe 0.25 That sounds
fine for the press. Let me put it to 0.4 maybe. Yeah, that sounds fine. Okay, let's save
everything again. As I told you before, we can
see if you play the sound. If you want this
to be different. Every time you can add a modulator and connect
it here, you can. I'd like to change
the pitch from 0.9 to 1.1 It sounds different every time you can do
the same thing here. I'm going to copy the modulator. I'm going to paste it in here and connect it here as well. Now this sounds different
every time as well, when you hover the buttons. Okay, awesome. Go ahead and save everything Now to add
the sound effects, let's go back to the UI. Open up the widget, blueprint,
click on the button. Then down here you
see options pressed. Sound You can go
ahead and change it to the button
press for the hoverd. Sound You can change it
to the button, hover. Same thing for the other one. You can change the pressed
one to the button press and the hovered
one to the button hover. Go ahead and compile. And now when you click on Play, and you hover the
mouse over them, if you press okay, now
you can see it works. However you can see I
actually have a buck here, so I need to change
the green one. Green hovered and green pressed. I actually want to use the
other one, the tal one. I think I have a tal one. This one is a lot better for me. I'm actually going
to copy this over. Choose the hovered and
pressed version of this. I'm going to click on the text and select the color picker. And select this one instead. I think it looks a lot better. Okay, for the sound, I actually need to reduce the
sound effect for the hover, I think it's a bit annoying. Let me change it
to 0.15 instead. Play. And now let's test it out. It works here. Okay,
now they work. And you have some sounds
on the buttons as well.
70. 6.10 How to Spawn Actors: Now let's go ahead
and spawn the player. And before we do this, let's go over to the extent
world settings. Let's actually go
to the blueprints. Click on the game mode
for the game mode. Remember in the class defaults, we set the default on class to spawn as the
counter terrorist. Let's go ahead and
clear this for now. And let's, before I do
anything else as well, let's go to the blueprints and let's open up the
counter terrorist to make sure it is correct. If I open up the viewport here, just making sure that
the third person mesh is the same as the mesh and I think there's
a bug in the terrorist. So if I open him up and you
can see there is a bug, the mesh is the terrorist.
That is correct. And the third person mesh, we have to change it over to the male terrorist as well
as this mesh over here. Okay. Just making
sure also the camera is wrong for some reason and that's actually because we need the socket for the camera as well here and
the parent socket. Because remember the terrorist
is using another skeleton. If I go to the
marketplace, this one, the silver character is
using this skeleton, the military do, The terrorist
is using this skeleton. I'm going to open up this
skeleton for the terrorist. Go to the head. I'm going to right click and add a socket for
this one as well. I'm going to change
the name to camera, just like the other
one I'm going to save. And now we need to position it the same way
as the other one. I'm going to open up the
character silver skeleton. I'm going to click
on that socket. I'm just going to hold shift and right click to
copy these settings. And then I'm going to go over to the terrorist one
and hold shift and left click on that one and that will
place it in the same, go ahead and save everything. And now you should see if you
go back to the terrorist, it has automatically
placed the camera up here because the spring
arm is actually attached to the socket camera. Okay, let us save everything. Now this is looking correct. Again for the game mode. In the class defaults, we need to remove the
default pan, set it to non, because now it is the
player who is going to select if they want to spawn as the terrorist or
counter terrorist. Okay, let's close it down. Also make sure in
the world settings, if you click over here that this default pan class
is set to non as well. Okay, now if you click on play, you can see you spawn
in a random area. And that is fine.
This is intentional. So now we are not spawning
as any character. We have to select it ourselves. Okay, to spawn players, we have to do this inside
of the Player Controller, the Player Controller,
inside of here. We do the UI as we did here, but we also do the spawning of items and
characters and so on. Every time you spawn something, you have to go into the
Player Controller UI and spawning is inside of
the Player Controller. Let's open up the
Player Controller. And inside of here, I actually, this time I want to work backwards because you
will understand it a lot better for the spawning.
Very, very important. We want to run an event, and it doesn't have to be inside of the Player controller. You can run the event from the player or from
anywhere else. So you have an initial
event you want to run. Then that event needs to
go through the game mode. Because remember the game
mode only runs on the server. The client cannot communicate
with the game mode. So the spawning of
items and players. We actually run through the game mode to make sure
the client is not cheating. So the server is always checking if what you're
doing is legal or not. And then from that game
mode, if everything is good, you are going to go to the Player Controller and
spawn that item or character. The final spawning is always
inside of the Controller. Since we don't have
a character right now and we actually want
to spawn the character, let's start this event from
the Player controller. Actually I want to
work backwards. The final event we want
to reach is if you write click and write a custom
event and do Saw player, we call that custom
event spawn player. You drag from here and say
spawn actor from class. This is the function that is used to spawn
things to the world. Now for this one, instead of just selecting what
we want to spawn, we are going to let
the player decide, I'm going to just drag this
input or this pin here into the event and it
will automatically create this variable for me. And I'm going to
do the same thing for the spawn transform. Now for this class,
I'm just going to select team or call it team because it is
either counter terrorist or terrorist that
is going to spawn. The player selects the team, then it will spawn at some
point here for the collision, I have to set it to try
to adjust the location, but just make sure that you
always spawn this player. Okay. It is always nice to have a variable
of this player. Let's right click,
promote a variable and call it player pawn, Okay? This is the final step
that we want to reach to. We want to, for example, run an event that's
called Select Team. And then that select Team is going to go through
the game mode. And the game mode
is going to go back into the Player
controller and run this one spawn player
if everything is good and we are going to
spawn into the world. Okay, let's save everything now let's go over
to the game mode. Inside of the game mode, we want to run
this spawn player. I'm actually working backwards, right now I'm working backwards. This spawn player has to
be run inside of here. To do this, let's actually
make a new custom event. And let's call this one
request spawn player, we're requesting to spawn
the player for this one. Again, I want to run this event. We don't really have a reference to our
Player controller. Let's actually add
it to this one. I just click on the and
I search for my PC. I believe it's called
PC counterstrike. This one. Go ahead and select
your player controller. And I'm going to call
it Player controller, we can drag from here now. And then what did we
call it, Spawn Player. I drag from here and say Spawn player and go
ahead and select it. Okay, so now you're
running this. Now we can see you have to set the team and the
spawn transform. Now for the team, again,
the team is going to be determined whenever the
player presses this button. So this one is going
to go the whole way back to the button press. So I'm just going to click and drag this into here as well. So now for the spawn transform, we have to determine where in the world we want to
spawn the players, and it is on top of those spawn points that
we created earlier. So let's go ahead
in the next lesson and write the logic for that.
71. 6.11 Player Spawn Location: All right, so now we have to determine where we want
to spawn the players. And remember we already placed the spawn points here for the terrorist and
the counter terrorist, and we already stored those spawn points
inside of those arrays. Let's go ahead and take the counter terrorist
spawn points and the terrorist spawn points. Let's strike from here
and write random. So we have a function
called random array item, so we're just going to spawn the player at one of those
Spain points by random, going ahead and selecting one of these Spain
points by random. And then we're
going to take Spain point and say get act transform. Okay, do the same thing here. We're going to write random
and then get transform. Now we have the actors location, rotation and the scale. You can see that if you right click here and split the struct, you can see that spawn point that it has selected by random. You have the location
of that saw point, you have the rotation of it and you also have the scale of it. I'm going to recombine the struct pin because I
actually want to transform. Now what you can
do, very cool here, is you can drag from this team, and now you can say equal
like that and select it here. If this selected team is
equal to, for example, counter terrorist, let's select this one BP counter Terrorist. If the player selected
the counter terrorist, what we can do here is
we can drag from here and say select, use this one. Actually, let's use this one
called select transform. But you can also use
this one called select. And then you can
just place this into here and use this
false or right. By the way, this is the same
thing, the select transform. It already gives us a bullion. Let's actually
just use this one. Let's go ahead and
connect it. Now what it is saying here,
let's connect it here. What it is saying
is if the team here that has been selected is
equal to counter terrorist, if it is true, go
ahead and pick A. If it is false, go
ahead and pick B. That is what it is saying. If it is true that I
selected counter terrorist, I have to take the
counter terrorist points here and then I have
to plug that into A. Because it is true, I have selected the counter terrorist. I'm going to take the counter
terrorist spot points and plug in the transform here. However, if it is false, it is the terrorist
that the player has selected and set it to here. If you have multiple
teams for your shooter, you have to use this
one called select because this one actually only gives you the
option of two. This one gives you the
option of more than two, just as you saw before. If you plug in an
enumeration here, it will give you the options of all the enumerations that
you have selected for. Now, let's just delete this one. Let's focus on
that for the team, I'm going to
reconnect it up here. I don't know why
it disconnected. And let's go ahead and organize
things a little bit more. All right, so now it's
going to go ahead and spawn that player at random to one of those
points depending on if the player selects
counter terrorist or terrorist. As you can notice here, for those events I never
select run on server again, remember the game mode
only runs on the server. You don't need to run this on the server
or on the client. And by the way, you
can never run on the client on the game mode, because again it only
runs on the server. You don't really need
to replicate it here. It will automatically run
on the server as well as here in the player
control. You can see here. Or notice that I didn't run
this on the server as well. Remember what I said before, it is always the server that spawns things
into the world. Realistically, it should
be a run on server. However, remember, you are
coming from the game mode. The game mode only
runs on the server and it runs this spawn player. This is automatically
still on the server. This never runs from the client. This comes from the game mode which is run from the server. So this one will always
be run on server, so you don't really need
to replicate that as well. Okay, now if I go back
to the game mode, so now we have this
request spawn player. And this actually comes
from the play controller. So if I go back here, I right click and make
a custom event. And let's call this
one Select Team. We're almost finished.
Select Team. And I also want to make
another one run on the server called
Server Select Team. And this one is run
on server reliable. Okay, so now we are
going to select a team. When we are clicking on the UI, for this one select team, I want to run the
server select team. So now it's going to
run through the server. For this one I am going
to run the game mode. One called Request Spawn Player. Now I can't run the
request spawn player because as you can see here, I don't have a
blueprint interface for my game mode and I don't
have any references to it. So let's go ahead
in the next lesson and create a blueprint
interface for the game mode.
72. 6.12 Game Mode Blueprint Interface: All right, so let's
go ahead and create a blueprint interface
for the game mode. Now you can do it
yourself because we have done it so many times. Now if you don't remember, just go ahead and follow
me here in this lesson. Let's go ahead in the
blueprint interfaces folder. Let's right click, go to Blueprint and select the
blueprint interface. Go ahead and call it
in and I'm going to mode. Go inside of this
blueprint interface. Let's call this function, get game mode reference
inside of here. Let's create an output. You have to select what you're
trying to reference to. I'm trying to reference
to my game mode called GM, I believe. Counterstrike. If I click up here again, right,
counterstrike. Select my game mode and
then call it game mode. Okay, now we're finished here. Remember to compile everything. Let's go back to our game mode in the Blueprint game mode. Inside of here, let's click
on the class settings, go to the interfaces
and then select the interface you just made
this one in game mode. Now let's double click
on the interface. And inside of here, let's
write self reference. Now we have defined
this game mode. Go ahead and compile
and save everything. Now we can go to the
Player controller and I can here in my begin Play. Actually let's go ahead and say and right click
here say get game mode. Now from this we can say get game mode reference
we just made. And it is message because it comes from a
blueprint interface. And go ahead and connected. Now for this one, you
can now right click and promote this to a variable
and call it game mode. Now we have a reference
to our game mode. Now that we have a
reference to our game mode, what we can do now is we
can take this game mode and say if I go back to my game mode and remember
what I actually called it, and go back here, we called
it Request Spawn Player. So now we can direct from
this game mode and say Request Spawn Player,
just like that. Okay, so now we can use
it into the next lesson. Let's go ahead and compile and save everything,
and let us move on.
73. 6.13 Finishing the Team Selection Logic: Okay, now let's go ahead
and finish the logic. Now let's go ahead and
connect this request, spawn player event from the game mode lets us connect
it to the server one. Now if you connect
this one up here, you'll actually get an era as well if you connect it here. And then for this game mode, let's say you plugged
this target into here. This is the game mode reference. If you do this here,
if you run it, this is the game mode reference.
If you run it from here, actually get an era where it says this game mode
variable does not exist. I don't know what
you're talking about. This happens if you run
this on the client. Remember, the game mode can only communicate
with the server. If you try to run the game mode variable through the client, it is going to give you an era and it's going to tell you, I don't know what
this variable is. Remember to run this game mode through the server as well. Let's delete this variable. Let me connect my game mode
again, just like that. Now I have to connect my
player controller select. Remember we are already in the player controller drag
from here and write itself the team that you
have to select. Again, we want to do it
through the UI here. What I'm going to do is just
drag this into the event, and drag this into the
event as well, and compile. Now what we can do now, you can take this event
and run it through the UI. If I open up my
widget, blueprint, I click on my button
For this one, let's actually change
the name of it. If you click on the button,
and I'll call it BTN Terrace. Make it to variable, because if you don't have this
as variable in the graph, when you're going to code the functionality
for this button. You can see you don't have any variables. If
you put this to, you can now see it as
a variable over here. And you can make
events through it. Make sure to tick is variable. Do the same thing for
the counter terrorist. Let's call it BT N terrorist. Let's make it is variable. Go ahead and compile
and save everything. Let's go over to
the graph now for this one I'm going to delete
all of this. For now, I'm going to click on the
Terris first, for example. And now we have these events. We can select this one click. What should happen when I
click the Terris button? What I want to do
is when I click, I want to run this Select Team. I need a reference to
the Player controller. So the way you do this very, very easy inside of UI, you can write, click
and say get owning. And you can see you
have two things here. You can either do
get owning player and this will get the player
controller for the player. And you can do get
owning player Pon. This will get the player P instead of the
player controller. Right now we need the
player controller. I'm going to do the
get owning player. Now again we already remember have a blueprint interface for the player controller where
we can drag from this and say get player
controller reference. Go ahead and connected.
Now we can run that event called Select Team and
go ahead and select it. Now you have to specify
what is the team. It is the terrorist because we have clicked on the
terrorist button. Go ahead and search for the BP terrorist and compile
for the counter terrorist. Go ahead and click on it.
Go ahead and click here. I'm just going to copy
paste this whole thing. You can write it again if
you want more practice. Now let us select the counter instead or this one. Let's
go ahead and compile. Now just to explain to
you what is actually happening is if I click
on the terrorist button. Now it's going to go
through the player controls select Team event. It's going to run through here. Remember this one is running on both the client and the server. We run it through
the client here and then we run on the server first. When we run it on the server, we are now communicating
with the game mode. We're going to go
through the game mode and ask the game mode, are we allowed to
actually spawn this? And we're going to go
through all of this and spawn the player control. It's going to go down here. Remember it knows what to spawn because we have
set them here in the UI, we have set the team here. It's going to take this
value to the select team, it's going to take it through
here, plug it into here, log it into here, run it
through the game mode here. And then it's going to run
it in the spawn player here. And it knows what the value
is because we have told it what it is and it also knows
where to spawn the player. Okay, now let's go ahead
and click on play. And if I select one
of them, for example, the terrorist, you can see nothing is
happening right now. Let's actually go in the next
lesson and finish this up.
74. 6.14 Spawning the Player: All right, so there is a final
thing to spawn the player. And we have to
possess the player. If you actually click on this, you're actually
spawning the player. But you cannot see the
player in the level because you have to possess
the player as well. If you drag from display pon, remember we already made an interface for
the player base, so you can drag from display and say get player reference. We already made that
blueprint interface, and now you can drag
from the player. You have to possess the player in order to control that player. Go ahead and compile
everything now, and let us click on Play. If you click on the terrorist
now now you can see you can actually possess this
counter terrorist. However, there is still the UI in front of us and
we need to remove it. The UI is run
through the client. When you work with UI, you are working inside
of the client. Now, instead of doing it here, let's right click and
make a new custom event. And run it through the client. Spawn player, I'm just going to call it client spawn player. I know it is connected to this one. I'm
going to click on it. Go ahead and run on
owning client reliable. Let us run it through
here as well. Cl spawn player for this one down
here right now. I just want to remember we
call it show hide widget. So we can come down here and say show hide widget
and select it here. Now we can select
the team selection, and this one unticked. Now it's going to hide
the UI for the players. Let's go ahead and compile
and click on Play. And let us select, for example, the
Counter Terrist. Now you can see we
are inside of here. Now you can see here, I
can't move my character. And I can also see the
head of my character. Remember we actually removed
the head. This is a bug. If we go to the player, and I just want to check my code if you click on the player base, if you go to the event graph,
it is showing my head. Remember in the begin play, we remove the head, we can also not
control the player. I have a suspicion
that this code here, the movement code and the
hiding the head is not running. Because if I play and click, you can see I can see my head, this code is not running. This one as well is not running because I can't really
move my character. I believe it's because you can actually just
print a string here. Print string again, print a
string is really powerful. It should say hello here. If it does that, I know
my code is running here. If I click on my coots, you can see it's
not saying hello. But if I connect it
to the not valid. So if I just disconnect it, put it to not valid,
just like that. And I can reconnect this again. I click on play, and
now it says hello. It's actually saying
that this is not valid. Now, in multiplayer, you have to know that You have to give the player a bit
of time for them to spawn because it is
not like single player. They take some
time to spawn into the server or connect
to the server. So you have to drag from
this and let's say delay. Sometimes that actually
fixes the problem. If I just added delay and
not really a big one, just by 0.01 so very, very low and compile. And now
if I click on Play, Select the Counter Terrorist. Now you can see I can move my character and my
head is gone as well. Actually, the only thing that we needed here is to
add this delay. Because when you connect to
the network on the server, you have to have a
very small delay to make the player actually connect and then run this code. All right, so now as
you can see here, everything is working great. However, you can
see the mouse is disappearing every time
I click on the screen. And it's annoying,
I have to select my other screen before I can actually click
on the buttons. And I have to click
here before I can play. So you can see I have to click, or actually
minimize this. And now I can click on the UI. And I have to click again on the screen before I can move
my character with the mouse. So we have to fix that. And we actually have to do that in the next lesson
with something called an input mode
that we have to set. Let's go over to
the next lesson.
75. 6.15 Setting the Input Mode: All right, now
let's go ahead and open up our player controller. So if you open up the
Player Controller, right now as you can see
when I click on play, I can't see my mouse and I
can't press on anything. If I go to the player controller and I click on the
class defaults, I can select this
one called shoes. If I compile and play, now you can see I can
see my mouse cursor. However, sometimes when
I get into the game, I can't hover over my buttons. And this is where the
set input mode comes in. Over here in the
player controller. Let us strike from
here, from the begin. Play and let's say
set input mode. You have these different types. You can set the input
mode to UI only, to game only, or to game and UI. Right now when we
connect to the server, we just want it to the UI only. Because we just want to focus on our team selection
and select the team. We don't care about
the game right now, U will be sufficient. Then we have to specify
the player controller. Remember, we are already
inside of the player control, so I'm going to drag
from here and say self. Then for the widget to focus on, we don't have to
do anything here. And everything is looking good. So let's go ahead and compile. And now when I click on Play, it's actually not
focusing on my game. And I can go ahead
and do all of this. Now when the player spawns, you also have to
change the input mode. Because when we
go into the game, you can see I can't move anymore because right now your input
mode is set to UI only, so you have to
change that as well. Let's go down here.
And remember, actually, if you go up
here and you see the icon, you can hold the mouse over it, You can see that
this one at the top, you can see it says client only. It only runs on the client.
Let's go down here. When we spawn the player, let's actually run it to
the client. Spawn player. Let's drag from here
and say set input mode. Right now we need the game only because now we are in game. We want to move around. We don't care about the UI, the player controller,
let's drag and say self, just like before. That should be it.
Let's compile and play. Now I select Counter Terrace, for example, and now
I am inside of here. But as you can see, I
can see my mouse still. Let's drag from
here and say mouse. You have this event down here. The bullion called
set show mouseursa. I'm going to set it
to falls up here. You can always set it
to true by default, if you want to,
you can copy this. And you can paste it over here and plug it in and
set it to true. Now, we already have done that by setting it to
true by default, But just to make sure
that it is visible, just in case you do something in the future, you
can have that. But for now it's
actually not needed. But let's actually
just let it be here. Let's click on Play by
Select, No terrorist. You can see my mouse disappears and everything is
working perfectly. All right, so let's
close everything. Remember to save your
game and let's move on.
76. 6.16 Placing a Spectator Camera: Right now when you
click on Play, you can see that it
starts at a random point. And I actually want to
start at like a cool spot where you can see all of the players right
when you connect. That will be really nice. What you can do is
you can just set a camera up here, for example. Let me just place
my camera first. For example, I want
to place my camera like that here and I can see the whole level and
the players as well. Now when you're satisfied with the position
of your camera, you can click up here on the Viewport and then
click on this one. Create Camera here,
and select Camera. This will create a camera
actor automatically. Now if I click on the Camera, it has been created here. To make sure I don't move
the camera here by mistake, I am going to write
click and transform and then select Lock
Movement selected. Now now when you click on it and you select the move tool, you can see it is not there. I can't really move
this by mistake. Now it has locked the
movement for this one. Okay, I'm going to rename
this one and call it spectator camera. Let us save. Every now what we
can do is we can go to the player controller and remember what I said before. If you want a reference to
anything inside of the world, try to remember what
function we actually use. I'll give you just
a small second to think about what
function we can use inside of here to get the
reference for this camera here. Let's go to the Player
controller now. What we can do is we want to set this view whenever
the player connects. I'm actually going to do
it here in the begin Play. What you can do is I'm just going to do it
here after the mode, I'm going to drag this away. And then from here and say
act of class at Floss. This is the function
that you have to use. Then select the camera. If I search for camera, then you can go ahead
and select the camera. This is a camera, We're getting the camera
from our level. Now what we can do is we
can use this function called Set View Target, Blend. Set View Target with
blend is going to set the view for your
camera when you connect. Now it asks you
what is the view? The view is just this camera
that we have created. Go ahead and connect.
That was actually it. Let us just pick them here. Go ahead and compile,
save everything. Let's click on Play. And now you can see we start up here. And I can see this level. It looks cool if the players are playing and I
can select my team, as well as see the players
in the background. When you click on terrorist, for example, you go ahead and
spawn inside of the level. And everything is working
well for the other one. If I go ahead and spawn
as a counter terrorist, and I go over and you can
see they can see each other. Right now, you can
see there is a bug. Let's actually fix that. With the head disappearing when I see the client
as the server, if I quit here, it
actually shows me an era and it might be
because of this one. It says axis non trying
to read this era here, you can try to fix
it yourself now before you follow me
just for practice. Axis non means it tries to read this value called get
local player subsystem. If I click on here, this is the get local player subsystem. It's trying to read this value
but it says access none, meaning I can't get any
information from this one. Let's just strike this away. Always nice to do is just
strike from this and say is valid only when it is valid. We are going to run this code, let's us connect
it here as well. Whenever the player
controller is valid as well as
this enhanced input, it is valid, then we want
to run the code again. Just double click here
on the reroute node. Go ahead and make this
organized compile. Let's click on play
and see what it does. Now go ahead and select terrorists for
this one for example. We're going to go to the middle and select for the other one. Let's select the
counter terrorist. Let me see the
other guy here and see if they see each other. And now you can see it is fixed. It was just an issue with
that era that we got before. Now if you want to test it, you can play it as clients. You can play it as, for
example, three players. Let us open up all of
these three players. I'm just going to minimize
this large one for now and make those
slightly larger. Just like that for this one, let's spawn a counter terrorist. And for the other one, let's
spawn counter terrorist. For third one, let's
spawn a terrorist. Let me go to the middle here. For this one I'm going to
go to the middle as well. And for the other one as well. Now you can see they
are working perfectly. Everyone can see everyone. And the animations, they
can be seen the crouch, this one as well, the
sound effects working, And everything is good to go. Let's go ahead and save
everything, and let us move on.
77. 7.01 Pistol Blend Spaces: Now we're actually
ready to work with the weapons and place them
into the level as well. However, before we do that, let's actually do the rifle
and pistol animations because we are missing
those right now. Let's finish those before
we work with the weapons, because at that
time we will have all the animations
and everything will be a lot easier for us. So let's go back to
the blueprints folder, click on the player and go back to the animations folder here. What I want to do
is for this lesson, create the pistol blend spaces. Just like those,
but the pistol ones now if you want to
create it yourself. So it's a nice exercise and then you can
see what I'm doing. But you should know by
now how to do this. Because it's actually
the same thing as those crouch unarmed
and run unarmed, and walk unarmed as well. If you want to follow,
let's right click here. Let's go here in
the animation and select blend space for this one. Again, select our
skeleton style, one male and call
it blend space. Let's call this
one crouch pistol. Let's create that one first.
Let's double click here. For the horizontal axis, this is the movement direction
for the vertical axis, this is the movement speed. For the movement direction, it goes from minus 180 to 180. And then we have
eight deficients because we have an
eight way movement. As for the movement speed now, it depends on if we are crouching or if we are
walking or running. Now let's go back to, actually I can do it here,
over to the right. Let's go back to the
crouch for the unarmed. I want to see what the
movement speed was. There it is 100, so I'm going to set it the
same here for the pistol, 100. And the final thing here
for the weight speed, we put it to 6.5
If you remember, if you don't, you can click on the crouch, you can go down. And then you can see the weight
speed, we set it to 6.5. Do the same thing for this
one, so they are the same. And before I do anything, I'm going to save
this and I'm going to right click this
and duplicate it. This is because I don't have to do all of this
again and again. And this one is
called run pistol. And then I'm going to
duplicate this again and this is going to be
called S walk pistol. I'm going to open
up the run pistol. Now we just need to change
the movement speed. I think it's 350 and if
you don't remember again, click on the unarmed. For the run, you see it's 350. In the crouch or
actually the crouch, the run pistol, you have
to put it to 350 as well. Okay. And let's
check the pistol. This one I think it's 200
on the art. Yes, it's 200. So let's put the walk one to 200 as well and
let us save everything. So now you can see
when I duplicated it, I don't have to do all
of this again and again. So now they are all ready. Okay. Let's start
with the pistol one. Let's search for the crouch or I can actually just
search for pistol. That is a lot easier. And then I can take a look at
the crouch over here. Just like before. You first
have to have the idle. Let's see, crouch
idle, This one again, hold shift and plug
them into down here. Just like that. And
the same thing on the other side, just like that. Okay, up here is the forward movement like
that as you can see here. And then you have the
front left to here, and then front right to here. Then you have the left over here and you have
the right over here. And then you have the back left and you have
the back right, and then you have the back
on both of the sides. And I can enable the labels so you can also see
how I place them. But you can hold
the control button and move your mouse just to
check if everything is okay. Everything looks good. I'm going to save and close it down. And now I can open
up the run pistol. I'm going to search for the idle and I'm going to use this one called idle pistol And go
ahead and place it again. Hold shift and
place all of them. Now when you have placed them, let's search for pistol and I'm going to
find the run ones. Run this one, the
pistols now we need, if I can find it
here, the front one. Then we need the front
left and then front right. Then we need the
left, the right, and we need the back
left, back right. We also need the back over
here to both of the sides. Again, hold control just
to see what it looks like. Everything looks fine. Okay. We can close it down. Now let's open up the final
one, the walk pistol. Again, I'm going
to find the idle. Take the idle pistol and
place it down here again. Then let's search for a pistol. Now we need to find the walk
on this one walk front, place it here like that. And then we need
left, front, right. Then we need the left
and right over here, back left, walk back right. And then we need on
both of the sites. Again, I can enable
those labels so you can see and I can hold control. Move my mouse just to see what it looks like and
everything looks fine. So now we can save everything. And that was it for
the pistol once. Let's move on to the next
lesson and do the rifle.
78. 7.02 Rifle Blend Spaces: For the rifle. Again,
you can try to do it yourself now that we
also did the pistol. But let's go ahead
and do it together if you still have some
difficulty with it. Let's right click here.
Let's go to Animation. Let's go to Blend Space
and select our skeleton. Again, call this one S.
Let's call it Rifle. Let's go into this one. Call the horizontal one. Movement direction. The vertical axis. Movement speed. The direction goes
from minus 180 to 180. With eight grid divisions, the weight speed is 6.5 As for the movement
speed, this is the crouch. So it is set to 100. That is correct. Let's
close it down again. I'm going to duplicate this
and call this Un rifle. And I'm going to
duplicate this again. Let's call this one walk rifle. I'm going to open up the run rifle and change
the movement speed to 350. Yeah, we don't need to
change anything else. Let's open up the
walk rifle over here. Let's change the
movement speed to 200 like the other ones. And let's save everything
and close it down. Okay, for the rifle. Let's start with
the crouch again. For the crouch, I'm
going to search for rifle and then I am going to find the crouch idle rifle
and place it down here. And go ahead and place them
again, all the way down here. All right, when that is done, now find the crouch forward
rifle and place it down here. Sometimes I'm just holding
control to check if this animation I have
imported for you is correct. I usually just hold control and just checking
if this is correct. I don't make a mistake
here on this course. Now we have this front. Okay, so we have the front
left, we have front right, then we have the left crouch left and crouch right as well. Then we have the back
left and the back right. Then we have back
and back as well. Oops, I need to copy this
back like that again. Hold control, check if
everything is correct, everything seems to be correct. Let's close this down. Let's go over to the rifle
again. I search for idle. And I take this idle rifle
and place it down here. And place it again,
all the way down here. When that is done, go ahead
and search for rifle. And now I find the
run once and I find the run forward rifle and
that is looking correct. And let us put it on
front, left, front, right. And then we have
the left and right. And we have the back
left and back right, and we have the back
on both of the sides. And I'm going to hold control, checking if everything
is looking correct. It does look correct.
Let's close it down. The final one is the walk rifle. Again, I'm going to
search for the idle, drag it down the rifle and place it down all
the way down here. Again, let's go ahead
and search for rifle. And now we need the walk one. Let's go to the walk forward. Place it down here and let's
check it. That is correct. Then front, left. Front
right, and we have the left. We have the rights. Then
we have the Bccrights. We also have back on
both of the sides. I'm going to control, again, just to check if
everything looks correct and everything
seems to be correct. Let's save everything.
Let's close it down. And now the rifle and the
pistols are finished. Let's go over to the next
lesson and do the aim offset.
79. 7.03 Pistol Aim Offsets: Now let's go ahead and
do the Aim offset. Now you have done this before. Again, try to do
this without me. That is nice practice. And if you can't remember, let's go ahead and
do this together. Let us right click here, go to Animation,
and go to Legacy. And select them, Offset one D, let us select the character. Let us call it O for a offset. And let's do the crouch. And let's call this one pistol. And let's double click on it. For this one, the horizontal
axis is the direction. You can also just click on the other one just to
see what you have done. So you do the same thing. It's not really good to do different things
on your same game. So it's always nice just
to do the same thing. If you have called
it direction here, try to call it
direction here as well, instead of moving
direction and so on. So try to do the same thing. So you have consistency
in your game -90 And I think the deficients
are just staying the same. Everything is looking good. The weight speed
I have put to 5.5 I'm going to click on
the pistol and put the weight speed to 5.5 as well. I'm going to save
everything now. Let us search for the
crouch pistol offset. If I search for pistol and I go down to the Am offset and
these are the crouch ones. The center one I'm
going to hold and hold shift and place it here down. Then we have the up
and I'm going to hold control to see if everything
is looking correct. That is fine. Let
us close it down. I'm going to right click
Animation Legacy Am. Offset one. D. Select your skeleton and
call this 10 stand pistol. Let us open it up again. Call it direction going from -90 to
95.5 in the weight speed. And let us search
for pistol again. This time it is
the stand pistol, the center one I'm going
to put in the center. Then we have the down,
and then we have the up. And you can see the
label here as well. We have the down,
we have the up. Everything is looking good. Let's save everything, and let us move on to
the next lesson.
80. 7.04 Rifle Aim Offsets: Okay, so now we're only
missing the rifle. Aim offset again, try to do
this alone for practice. And if you don't remember again, let's go ahead and do it
together. Let's right click Animation. Select
Legacy and aim offset one D. And let us select
our skeleton and call this, let's call it crouch rifle. For this one I'm going
to double click, Call it direction for the minimum value -90 For
the maximum value it is 90. The weight speed is 5.5 Let us search for rifle this
time for them offset. This is the crouch one. We need the crouch offset. I'm going to strike this
center and put it here. Then we have the down,
Then we have the up. This here looks nice. Now, the animation
itself looks weird. I mean, he's really bent
and that looks so weird. But these are just
the animations like it's not your fault, we're not doing anything wrong. It's just the animation
that is done like this. Now, if I had better animations,
I would give it to you. Unfortunately, I don't really
have better animations. Maybe in the future I will have someone do
everything custom. But for now, this is the
best that we can do. Everything's looking fine. Now let's close it down. And let us right click again. Go to Animation and legacy here am said
select the skeleton. Call it AO stand rifle. Let's double click here
and call it direction. Then for the minimum value -90 for the maximum
90, for the weight, speed 5.5 And let us search for rifle and then we can
now select the stand rifle, this is the center. Then we have the down. And
then we have the old control to check if everything is correct and everything
is looking nice. Okay, let's save everything. Let's close it down. And now we have the
aim offset as well. Let us move on in
the next lesson.
81. 7.05 Blend Poses By Bool: Now we are ready to go back into the animation blueprint
and do some work there. Let's click on the player
folder Animations, and open up the
animation blueprint. Now inside of here, I want you to click on the
animation graph. So we are inside of
here. As you can notice, previously we have used
the offset for the stand. However, we have
used the other one, the aim offset, for
the crouch as well. We have only used the
one for the stand. When we are crouched,
we are not using the correct aim
offset. To do this. Let's right click and
search for crouch. This one offset player, right now we are in the, I'm just going to
copy them direction. And copy this one
as we plug it in. Now we have that.
But the problem is right now is I can't
plug this into here, because as you can see, only one input. We have to get something that will put these
two things together. The way we can do this
is if you right click and search for blend poses. You can see we can blend these two poses by many factors. You can
see all of those. However, what we need
is blend poses by, you can see there's something
called blend poses by bull. This makes it possible for you to blend the poses
through a bullion. If you have a bullion
that is true, it's going to use this pose. If it is false, it's
going to use this pose. We have to give it a bullion. The bullion we want to use is we want to check if the player
is crouching or not. If the player is crouching, we're going to use the aim
offset for the crouch. If the player is not crouching, we're going to use the
offset for the stand. Let's go ahead and find
the bullion over here, if we have already
done this now, is crouching and is walking. Remember we deleted them
previously from here. They're actually not used
right now and they are wrong. Let's delete the Is
crouching and is walking. Remember we switched them up with the movement state here. Let's strike this
one. And let us drag from here and say
get and get a copy. And now you can drag from
here and say last index, and then we can plug that in. We're checking if the player is currently pressing
the crouch button. We can drag from here and say equal if the last index
is equal to crouch, meaning the player is right now pressing on
the crouch button, then we can go ahead and crouch. Now we're going to plug
it in if it is true, meaning the player is crouching, we want to use this one where
the aim offset is crouch. However, if the player
is not crouching, we want to use this
one with the stand. Go ahead and compile and plug them into here.
Compile everything. And I'm just going to move everything here
and organize them. All right, so everything
is organized now. Now you can try to check
if this is working. So you can click on
the movement state. You can add an array here, add an element to the array. And you can just set
it to crouching. And you can see
what it looks like. So now you can actually
see it is working. Because if I set it to
crouching, then it is crouching. If I set it to something else, then it changes
to the other one. Now you can see it switches up, that is working correctly. Let's remember to go ahead
and delete this for now. Okay. So that is
working correctly. That's how you
blend poses through this one called blend
poses by bullying. Okay. So we have another
one that we need to use later on because this one is
just the unarmed movement. We also need the movement for the pistol and movement
for the rifle. So you can see it gets
a bit more complex because we need to create all of this for the pistol
and the rifle. We need another one called
blend poses by enumeration. But for now, let's jump over to the next lesson and
learn about the subject.
82. 7.06 Blend Poses By Enum: All right, here we are again. This time we want
to use this one called blend poses
by enumeration. If you write, click and write
blend pose or blend poses, you see all of those that start with an E. Starting with an E, that is actually an enumeration. And those are just enumerations that are created in
Unreal engine by default. Now lets us create our
own enumeration instead, let me minimize all of this. Let's go to the Enos. Let me right click this folder, go to Blueprint, and create
a new enumeration list. But let's call it weapon type. Let's go ahead and
enter the enumeration. And you can now add what
weapon types we have. We have the pistol
and the rifle, but we also have the unarmed because I need the
unarmed movement as well. So I'm going to make the
unarmed to begin with. And we can make one for the pistol and we can
make one for the rifle. Again, it doesn't matter
in what sequence they are. If it is like this, you have
created them or like this, it doesn't matter. That is it doesn't really mean anything. Okay. I'm just going to make it like unarmed pistol, rifle. Go ahead and save, these
are the weapons we have. If you have more weapons, you can go ahead and add them. But for now, let's
save everything. Let us go into here. Now we can right click and we
can search for blend poses. And then you can search for the enumeration you just made, The weapon type, we can
search for weapon type. And here it is. And
you can now select it. Now you have it
here. You can now blend poses through
this enumeration. We can right click this
default pose and then you can select and add a
pin for the unarmed and thing. Right click,
select pistol, right click, select rifle. Now you have pins for all
the movements that you have, so you can plug in
the unarmed movement, the pistol movement,
and the rifle movement. And you have to plug in the enumeration so you
can change accordingly. Okay, go ahead and
save everything. Now what we need to do here is, let me go back to the player, because now we actually need to know what the player is
equipping right now. Because if you're
equipping a rifle, we need to change your
pose into a rifle. If I go to the player
base and I just add a new variable that
we will use later, and I'm going to call
this one equipped weapon. I'm going to make this variable type
into the weapon type. We are going to use this
equipped weapon later on when we set which weapon
the player has equipped. And let's save everything. I think this one will
be replicated later on. Now let us do it replicated so the others can actually see what weapon
you have equipped. And let us go back to
the animation blueprint. Go to even graph inside of here. Remember we already have the
reference for the player, so we can drag from
here and search for equipped weapon and
get that variable. Now what we can do is we can right flick promote
this to a variable, call this one equipped
weapon as well. Go ahead and connect it. I'll click here to
make a re route node, just to make things a
bit more organized. All right, now that we have
this, go ahead and compile. Let's go back to the
animation graph now. Now we can plug in this
equipped weapon right here, and let us compile. Now for the default pose, you have to have a default pose. Usually what I do is I plug in the unarmed movement inside
of the default pose. For the unarmed, you have
to plug in the same thing. However, you can't really plug
this two times like this. You actually have
to copy paste this. Now to make this more organized, I actually want to disconnect. And this is why
it's so nice to do the cache notes because you don't have to copy
paste all of this. What we can do is we
can just place it here. And then I'm going to rename this one Unarmed Movement Cache. I'm just going to call it
Unarmed State Machine. Unarmed State Machine Cache. Remember this one was
called a state machine, Unarmed state machine cached. They are plugged
in here correctly. For this one I'm actually
going to drag and say cache and new save
cache pose For this one I'm actually
going to call it unarmed movement because this
is now the unarmed movement which includes the
aim offsets as well. This one now we can just
take here and use it here if you search
for arm movement, not the State machine
unarmed movement cached. And now you can see how easy it is and how organized it is. We don't really need
to copy all of this and plug it into here
again and again. Now we can just
copy paste this and use it as the unarmed
pose as well. Now for the pistol
and the rifle, we need to make those. Let us just drag this,
plug it into here, Go ahead and compile
it. So here what I can do now is I can click
on the equip weapon. And let's say in the game
I picked up a rifle. So you can see it is changing. However, we haven't really
plugged in anything. And this is what
this note is saying. It's saying that the pistol
and rifle pose has been ignored because we don't have
anything plugged into here. But as you can see,
it's actually working. And if you switch
it back to unarmed, it goes back to the
unarmed movement. So now what we are
missing is we are missing the pistol and the rifle
state machines here. So let's actually jump over to the next lesson and do the
pistol animation blueprints.
83. 7.07 Pistol Animation Blueprint: Hello and welcome back. Now we are ready to do
the pistol state machine. So now we have the unarmed. I'm going to copy this. Go ahead, click on Copy and control C and control V
again. And now we have this. I'm going to press on F two to rename this and I'm going to
call this pistol movement. Now I'm going to go into
this state machine now and remember to change all of the movement
for the idle run. Let's go ahead and switch
this up for this one. If you just search for pistol, actually don't need
to search already. Have them down here
at the bottom. And we have the pistol run. Drag this into here. Go ahead and delete this one. And plug in the movement
direction and speed. And go ahead and plug it in. Go back to the
walk now the walk. Let's delete it. Let's search
for the walk pistol here. Just make sure you drag in the correct blend space that you have created and compile. Now let's go back and
go to the crouch now. Go ahead and delete this
one and for the crouch pistol drag it in and plug in the movement
direction and speed. Go ahead and plug
this in as well. Compile, go back now
we have all of those. I don't think we need to change anything with the transition
rules and we actually don't. Everything is correct now. Now for the jump, we
need to press on here. Now for the jump starts, let's search for jump. I need to use the
one for the pistol. This one is jump start pistol. Go ahead and delete this
one and plug this in. Let's go to the air
and this is the jump a pistol delelete this
one, Plug the pistol in. The last one is jump end and jump end pistol, this one here and
plug it in as well. Now remember to change
the transition rule for this one because it's still
saying jump start unarmed. We need to search for time ratio and select the one
for the pistol. And it automatically knows that it is the pistol because we have locked in the animation on the other one. We
have corrected it. So go ahead and select this
one, ratio and pistol. And go ahead and delete this one and plug this one in instead. Remember we also
have it down here. Double click on this one again, search for time remaining
ratio for the jump end pistol. Delete this one
and add this one. Now, compile, save everything. Let us here, just check and see if there's something
we have missed. I don't think we have
anything anymore here. Now we have the pistol
movement and we can do is we can drag from here
and say cache again. We can call this one
Pistol State Machine hashed, just like that. And now we have the
pistol movement.
84. 7.08 Rifle Animation Blueprint: Right. So the final thing we are missing is the rifle movement. So let's go ahead and copy
the pistol, Ted here. And let's rename this
to Rifle Movements. Let me just again go into here. Double click on the idle for
this one run pistol instead. Let me just delete all of this. Go down, I'm actually
just going to search for a rifle that will be a lot
easier going down here. We only see the
rifle blend spaces. This is the Un rifle. Go ahead and plug in
the movement direction and speed and plug
this in as well. Let's go back to the walk. And let me delete this one. Plug in the blend
space for the walk, for the rifle. Lock those in. Just like that. The same
thing for the crouch. Go ahead and take
the crouch one. Lock those in Again, like that. The same thing for
the jump. Jump start, I'm going to search for jump and find the one for the rifle. Jump start rifle, this one. Delete the old one.
Place this new one. Now the same thing for the jump. A, select the jump, a rifle. Plug that in. The same thing for the jump end. Take jump end rifle and delete
this one. Plug this in. Remember to change again the transition rule
here for the jump start time remaining ratio
for the jump start rifle. Go ahead and delete the old one. Select this one, and the same thing for
this one. Jump end transition rule,
time remaining ratio for the jump end rifle. Delete the old one.
Place this one instead. Go ahead and compile,
save everything. And I think we are finished
with this one as well. Just checking quickly, I
think everything is good. Let's go back to the
animation graph. And inside of here, let's
strike and say cache again. And rename this one to
Rifle State Machine. Okay, you can organize this
a bit more if you wish to, but for now everything
is finished. Let us go ahead and
save everything. Remember to also compile
and let us move on.
85. 7.09 Finalizing the Animation Blueprint: Okay, now it's time
to finish this. We don't have much left, so let's go ahead and
finish all of this. What we need to
do now is we need to add the aim offsets as well. Let's start with the pistol one. I'm just going to
drag this away. Take the pistol here. Now we need to use
this cache pose. Let's right click and
search for pistol cache. Take this one, pistol state
machine cached and use this. Now we need to do
the same thing here. We need to right click
and search for AO Rauch. Search for the one
with the pistol Am offset player crouch pistol. Go ahead and plug it into here for the aim
direction as well. I can just copy paste this
variable. This is now correct. I'm going to use for them
offset stand pistol. Take the one with the
Am offset player. Plug in the aim direction, go ahead and take
the same cached pose and plug it into here as well. Now you have the one for
the crouch and one for the stand pistol,
just like before. Use this one blend
poses by Bool. I'm actually just going
to copy all of this. We don't really need to
write it again and again. So go ahead and take this. Let's set this one to crouching, that is actually still correct. Let's just plug the true one. If we are crouching, we're
going to use this one. If we are not crouching,
we're going to use this one. Go ahead and compile. And now I'm just going to organize
this a bit later. Right now, I just want
to plug this in because these ones will get a bit larger, just
like this one here. What I'm going to
do is I'm going to take this and save
a new cached pose, just like before you called
it unun movement cached. This one I'm going to call it pistol movement, just like that. And go ahead and
plug them in here. Now I am going to organize
this just like before. Okay. So now it is organized. I just tried
organizing everything. And now we have the
rifle over here. We can just move
it down for now. I'm actually going to
move the unarmed movement above the pistol, one like that. Try to be as organized as possible because when you're
creating a large game, it's going to be really messy because you will have
so many things going on. And it's always
nice to try to stay organized for the last one here for the pistol
or the rifle. Let us again, just like before, I am going to right
click and search for AO Rauch and choose
the one for the rifle. And again stand and choose
the one for the rifle again. Now we can go ahead and take
the state machine rifle, state machine cached,
plug it into here, take the direction and
plug it into here. We can now paste this
down here as well. Plug it into those inputs. Now everything is looking good. Again, just like before, I'm
going to copy all of those. The blend bulling
those here as well. Go ahead and paste it. Connect the crouch, If you're crouching,
you're doing this. If you're not crouching, you're doing this, that is correct. And we can drag from here
and say Cache again. We can save a new
cache pose and call this one rifle movement
Cached like that. Okay, everything is looking
correct. And let us compile. And I'm going to
organize this again just like before.
Now it is organized. And I'm going to take
all of this and move it right under the
one for the pistol, just like this here. Okay? Try to do it as best as possible.
Now we have it here. We have the one for the unarmed, we have the one for the pistol, and we also have the
one for the rifle. What we can do now is
we can compile and save everything just to make sure nothing crashes for the pistol. Now we can drag and says we
can use the now this one is just using the
movement because from the movement we determine if we should use the
crouch or the stand. From this search for cache and remember to select
pistol movement cached, not the state machine
movement cached. Then for the rifle, we can drag and search for cache again. And choose the one
rifle movement cached. Go ahead and organize
this as best as you can. I'm also going to
drag this a bit down. It looks a bit better, maybe something like this. And now let us compile. And now you can see the note has gone because we have
plugged everything in. And if I click on the
quipped weapon and change it to pistol,
it is working. If I change it to
rifle, it is working. If I change it back to unarmed,
it is working as well. Now, you can also change the
blend time if you wish to. So we can see if
you increase all of those and you try to change them Now what you can do is if you switch over to
the pistol and rifle, you can see it
changes instantly. What you can do, you can
also increase this time. For example, I can
increase it to two. It will actually
blend a lot slower. I remember to compile
else it will not work. Compile and then
change to pistol. You can now see
it takes a lot of time before it changes
to those poses. You can try to play with this. For example, 0.0 0.3
maybe two to extreme. Let us compile and let
us select pistol rifle. Maybe that is a lot better. I think it's still too slow. 0.20 0.20 0.2 Let us compile. Let us select the
unarmed rifle pistol. Just compiling, making sure
that it is working correctly. I think that is a lot better. 0.2 instead of 0.1
is a lot better. Now you can see we are
finished with the movement, and maybe we can place this
one here in the middle. This is the final one. And now everything is working. So we can always change
this equipped weapon later on in our player base
when we are looting weapons. And it will automatically, in the event graph, it will set that variable here and it will change
in the animation graph. But for now, for the
equipped weapon, I'm just going to put it
to an armed as default, compile everything,
save everything, and we are now ready to move on.
86. 8.01 Importing the Weapon Assets: Let us now go ahead and
import the weapon assets. For that, go back to the
Epic Games launcher. And inside of here, let's
go to the marketplace. In the marketplace,
let's go to Browse and go to Weapons In Weapons, you have to click the
free ones so we can get some free assets we can
use for the course. I have downloaded this one
called FPS Weapon Bundle. If you click on it, go ahead
and click on Download. If you haven't downloaded
it yet, then you can click Add to Project. Once it has downloaded again, click on Show All Projects, and then select our own
project, Counterstrike. And go ahead and select
the version that it is compatible with the
latest version, this one. It doesn't really matter that it's this version
it's compatible with, it's not going to
give us any problems. Go ahead and select it
and go to Add To Project. It's going to add
this to a project. And it might take some time. If this is the first
time you're doing it, I'm going to go back here. I'm going to download
this one as well because this pack here does not
contain any pistols. And I want to make
a pistol as well, course. So you know how to
shoot with pistols and so on. So it's not only rifles.
Let's click on this one. And let us again
download this one. Military weapons Doc. Go
ahead and download it. You can also use this one, military silver instead, but I'm just going
to use this one. Go ahead and download it
and Add to Project again, click on Show All Projects, Select our Project, and
select the latest version. And Add To Project as well. Then you can see once this has finished and
I can close it down, you can see inside of
our project now we have the FPS weapon bundle and we also have the
military weapon doc. And before I do anything, I'm going to select
both of them and then drag them into the
Marketplace folder. And select Move here. And this one is going
to take some time, so I'll skip ahead until
it's finished. All right. So now they have been moved, and as you can see, the
Marketplace folder, I have now the
Military Weapon dock and the FPS weapon
bundle as well. But as you can see outside, I still have this FPS
weapon bundle folder. And this might happen
to you as well. You can see they are empty
and if I hit delete on my keyboard and select
Delete, it will not delete. And this happens sometimes
in on real engine. So what I do, I usually just save the project and
go ahead and close it. Then I open up the project file, so it's inside of here,
the counter strike. And then I open up the
content folder and then I delete this FPS bundle. So just make sure
that it is inside of the marketplace already,
all of the files. So you can see here,
the FPS bundle, it's empty and there's
nothing inside of it. I don't know why it's not
deleting for some reason. So let's go ahead and
delete this folder. And then I can go ahead in the library and run
my project again. And it should be deleted
now, as you can see here, once I'm inside of
my project again, the folder is gone because
we just deleted it. And in the Marketplace
folder we have the FPS weapon bundle and
the military weapon doc.
87. 8.02 Setting up the Weapon: Now that we imported
the weapons, let's go ahead and set them up. Let us right click here
in the Blueprint folder. And let's make a new folder, and let's call this one weapons. Let's right click this one and set a new color for this folder. Again, let's open
up this folder, right click, go to
Blueprint class. For this one, we're just
going to create a simple act. Because a weapon is just a static Ta that
is there in the world. It's not a pawn or a character
that you can control. And it's not one of those
either, it's just an actor. Let's call this one BP Weapon Base. Again, I am
going to create a Base class. And from that one we can write, click and select Create
Child Blueprint Class. For this one let's, I'm
going to make an AK 47, so we can call it PK 47. Then you can right
click again and create a child blueprint
class for this one. Let's call it BP M41. There's the other weapon. The last one is a pistol. We can right click Create child blueprint class
and call it BP pistol. Let's just go ahead
and save everything. First let's open up the weapon base
because we have to do some work inside
of here First. Here we need a new component. The component we need is either a static mesh
or a skeletal mesh, because we need to add the
three D model for the weapon. Now if you click on this
and search for mesh, we have either the skeletal
mesh and the static mesh. If you don't know the difference
is the static mesh is just a static three D model
without any animations. And we have a skeletal
mesh which is a three D model with animations. If you go back, actually
we have to check it here for the
marketplace weapons, what they come as if you open
up the FPS weapon bundle, you open up the weapons
and you open up meshes. And let's open up
this one K for seven. And you can see it
is a skeletal mesh. If you see this pink line or
you can also look down here, it says skeletal mesh. We actually have to add
it as a skeletal mesh. We can also check the other
folder just to be sure the military weapon doc open up weapons and it comes as
skeletal meshes as well. You can see here they
have animations. They have reload animations, shooting animations and so on. These weapons have animations. If we go back to the weapon
base inside of here, let's click on Ad, and let's
search for skeletal mesh. And select it here. And
let's call it weapon. Now for this weapon here, we also need a collision sphere. Because we need to
interact with the weapon. For example, if
it's in the ground, we need to go to that
weapon and loot it. This is why we need
a collision sphere so we can collide with
it and do some actions. If you just search
for collision, we can see that we can
either do a box collision, capsule collision, or
a sphere collision. Now they are the same, it's just the shape
that is different. So I'm just going to select a sphere collision for this one. And I'm going to make
this sphere radius a bit larger. Now, it
doesn't matter right now because we are going
to adjust it later. When we try the weapons
inside of the level, Then we can do the radius of how far away can the player
loot the weapon and so on. This is how you control it here. But for now, I'm just
going to put it to a random number and go
ahead and save everything. Now let us close down the weapon base and let's
go to the child blueprints. If you open up weapons. And let us open up
the AK 47 here. Now for the weapon,
if you click on it, let's select the skeletal mesh. If you just search
for, I don't know why it's called KA 47, but you can search
for that and you can find it and select this one. And let us open up
the second one. And you can click on weapon, open up this one here
and search for R four. You can select it here, then open up the last
one, the pistol, click on the weapon
and then select or just search for pistol
and select this one here. Now you can see all of the weapons are now
inside of here. Go ahead and compile or
all of the blueprints. But as you can see here, they're all turning this way. That's actually the
wrong direction, because in Unreal engine, the X axis is the forward axis. And you can see here,
the red pivot point here is the forward axis. The weapons need
to turn this way. Here they are all
turning the wrong way. As you can see, we have
to turn all of them instead of just turning
it one by one like this. And we have to go here
and turn it as well. Let's actually do
something else. Remember we have a weapon base which is the parent
blueprint class. Whatever you do inside of here will apply to all
of the children. If you click on the
weapon and you take the rotate tool and you
rotate it -90 degrees, you go ahead and compile. Now take a look at
the pistol M four, the AK. They're all turning the correct way now that is the correct
way they should turn. Go ahead and save everything. I believe that was
it for everything. Now that we have that, let
us just drag them into the level and take a look
at what they look like. I'm just going to
separate them a bit. I'm going to select
all of them and then move them up
here in the level. Again, you can click on G
to hide all of the icons, and you can take a look at them and everything looks good. For now, go ahead and save everything,
and let us move on.
88. 8.03 Enabling Physics: As you can see here,
when I click on play, all of the weapons are floating. If I go actually they are
on the terrorist side. If I click on play and
select terrorists, we can see that all of the
weapons are floating around. We want them to
fall on the ground. Instead of having them
to float like this. We need to enable physics. If we go back to the blueprint
and before I do that, I'm actually going to reduce
the amount of players that I spy lesson server. Okay, let's go to the weapons, open up the weapon
base. Inside of here you click on the weapon. You
can see something called Simulate Physics here under
Physics Simulate Physics. However, for some reason I can't selected and I have no idea why. But what you can do is just
delete those events for now. In the Begin Play,
let's do it here. Let's take the weapon.
Let's drag from here. If you just write
the same name as what you can see here,
you click on Weapon. It's called Simulate Physics. If you drag from here
and just write Simulate, you can see it's this one
called Set Simulate Physics. If you just select it
here and connect it and just set it to true so it simulates physics and
go ahead and compile Now it doesn't work still
because the collision is wrong. If you click on weapon and
you go down to the collision, you can see it has no collision. If you click on play right
now and select the terrorist, you can see they're not
falling down still. They're still flying on the air. Let's close it and
for the collision, let's change it to custom. For now, I'm just
going to click on Ignore the Collision is going to ignore
everything for now. I'm going here for
the no collision. Go ahead and select
physics only. We just want physics. What query means. It means that if we can interact
with the weapon or not. We don't really
need that because our collision sphere is
actually a query only. This is like we are
colliding here. We're doing some action
with this collision sphere. This is a collision and you can interact with
it without having physics. But for the weapon, I
don't want that because we already have the collision
sphere for this one, we just want the
physics enabled. Then I'm going to
ignore everything. However, you have to block the world static
and world dynamic because it is the floor now. If you ignore everything,
you can see if I click on play now and
select the terrorist, the weapons are gone. This is because you haven't block the ground. They're
falling through the ground. We have to block the ground, the world static and dynamic. Go ahead and compile and click on play and
select terrorists. Again, I'm actually
going to take all of those and just have them
here instead like that. Just have them in the middle
so I can actually see them faster if I click on
play, go to terrorist, you can see they are
now being blocked by the ground and they're
falling on the ground, okay. Now you can also see if I walk into them as the
terrorist or as the pawn, nothing is really
happening and this is because I am not
colliding with them. Now if you want the pawn
to collide with them, I'm not going to do it
inside of this project. However, if you want that,
you can also select that your pond that you're controlling
will also block them. And that means you can now interact with them
as the pawn so we can walk into them and the
collision is working as well. You can do that as
well if you wish to. However, for this project, I'm not really going to do that, I'm going to ignore
this for now. So now we have physics enabled, and we are simulating physics
for all of the weapons. So let's go ahead and compile and save everything,
and let us move on.
89. 8.04 Replicating Actors: Previously we
replicated variables, but you can also replicate
blueprint actors. And we have to do
that for them to show correctly for
all of the clients. If you open up the weapon base and here in the class defaults, you can see that it's
also called replicates. And you have to select
that if you want to show the correct information
from the server to all of the clients displaying
these weapons, as well as the movement
for the weapons and so on. So you have to press replicates. So it works in multiplier. You also have to replicate
the movement as well, to make sure that the movement of them is not bugging as well. This was the only
thing that you have to do sometimes, if
you forget this, sometimes you do some code and you can see it's not working for the clients and you
get confused why it is. So, but it is because you also have to go in an actor
that you create, for example, this
is the weapon base. And you have to select replicates as well as
replicate movement. It works for multiplayer. Go ahead and save everything. As you can see, since it's
the parent blueprint, it also replicates now for
all of the children as well. Go ahead and save everything,
and let us move on.
90. 8.05 Weapon Overlap: Now we are ready
to do some events for when we overlap
with the weapon. To see it better, you can open up the weapon base for now, if you click on the sphere, you can click on this
one hiddening game. You can remove it. And if you compile, you can see the collision
sphere in the game. It's nice to see here. You can see how far away you can interact
with the weapon. You can always make it larger or smaller depending on your
game that you're creating. But it's always nice
to see inside of here. Let us do some
interaction events. What we want to do here
in the weapon base, we want to click on
the Sphere collision at the bottom. If you go
here in the details panel, you can see this one called
Component Begin Overlap. If you click on the plus, it will create the event for you. Now it says what should happen whenever you overlap with
this sphere collision? For this one, first
I have to check if it is the player that
is colliding with it. Because if you have
enemies running around or something
else colliding with it, it will actually fire this code. I want to make sure that it's only the player who can
interact with this one. The other actor
is the actor that is interacting with
this collision sphere. I can direct from this
other actor and say actor has tag and then I can
select this function here. And what this function
is saying is if the actor that is
interacting with this sphere collision
has this specific tag, I can go ahead and
fire the code. I can make a branch here. If that is true, the player has this tag that we
are about to write. The events can fire here the tag that we
need to write here. We have to assign a
tag for the player. If you just open up
the player again, player base here, inside of
here in the class defaults. If you search for tag
in the details panel, you can see this
one under actor. It's not under tags. You have to make sure
it's under actor. And you can see the tags. It's called actor has tag. It needs to be under the actor. If you click on the clause, and I can just call
this one player. Now we added a tag here
for this blueprint clause. We added the tag player. What we can do is we can go to the weapon base and just ask, does this actor has
the tag player? If that is true, we can
fire off these functions. Now, it is only true for the
players in the player base. They have the tag player. And this will apply to both the terrorist and
counter terrorist, because again, this is the
parent blueprint clause. Let's open up here. Now
for collisions here, for the component overlap, you always have to
make sure that you run it through the server
to prevent cheating. From here, drag and say
switch has authority and then we can write the code
from this authority here, which is the server always make sure that you run this
code through the server. Because if you don't, let's say the client is standing here and they
are cheating somehow, they have some
software downloaded, they can actually interact with the weapon even though
they're standing here having it run
through the server. The server checks if the player is actually
interacting with it or not. Okay, from this other actor, what we can do is we
can drag as well. Now we know it's the player and now we run it
through the server. We can drag from here and
say get player reference because remember it's the player who is interacting with it. And we also made this get
player F from the interface. Earlier we have the
players reference, so we can go ahead
and connect it. Double click here to make reroute notes
and make it cleaner. Just like that, God and compile. And now we can actually
interact with it. Now to see if this is correct, you can drag from here
and write a print string. You can maybe
connect this player to it. Go ahead and see if it this out. If you click on play and actually let's
select the terrorist, so we're not on the
other side of the map. Now if I go over to here
and interact with it, you should see that it
says here, BP terrorist. Now it is actually correct, we are interacting with it. Everything is working, so go ahead and delete this for now, compile and let's move on.
91. 8.06 Setting the Weapon Type: Though, before we continue, I need to add the weapon
type to each weapon. And this is nice to use
later on because it's always nice to know if
the weapon you're looting is a rifle or a pistol. We need that later on
for the inventory, so we don't loot
multiple rifles, multiple pistols, and so on. You can of course, do that in your own game, but
also checking, for example, you cannot loot three rifles and
things like that. So you have to know
if it is a rifle or a pistol that you're looting, because right now we have no
idea what we are looting, we're just interacting
with these items. What we can do is here
in the weapon base. Actually, before
we do that, let's go to the enumerations. And we already have this
one called weapon type, we actually already
have this one. Let's go back in the weapon
base and let's add it here. Click on the plus in
the variables and just write weapon type here. For the type of variable you
can search for weapon type, this is our enumeration. Go out and select it, and click and compile and save everything. Now the cool thing about this
is you have added this to the weapon base which is the parent class of
these weapon blueprints. Really nice is if you
open up the AK 47 now and you click on
the class defaults, you can now see the
variable weapon type and you can select which
type of weapon this is. If you add variables
to the parent class, they are usable in
children classes. You can see now if I open
up the 44 or the pistol, I click on the Class defaults, I can see the variables
of the parent class. Whatever you add here can also be applied to all
of the children. Now clicking on the AK, I can now select the
weapon type to be a rifle. I can compile now. I
can go to the four select the weapon type
to be a rifle as well. If I open up the pistol, I go to the class
defaults and I click up here and select pistol
for the weapon type. Go ahead and compile for
all of those blueprints. And now we can save them. Yeah, now we know what the weapon type
is for all of them. This is a pistol,
this is a rifle. And this is a rifle as well. And we need to do that so we
know what we are looting.
92. 8.07 Checking if Player Has the Weapon: Let's now create some,
a weapon inventory for the player and check if the player already
has the weapon. Because what I'm trying to do is if the player interacts
with the weapon, it needs to check if the player already has the weapon or not. If the player has
the weapon already, they can't loot the weapon. It's only going to loot the rifle if they don't
have a rifle already. And they're going to
loot the pistol if they don't have a
pistol already. Let's go ahead in
the player base and inside of here,
let's click on the plus. I'm going to make a new variable
called Weapon Inventory. Here we just search for the weapon type or
the weapon base, because we need to add the
weapons to that inventory, they need to be the
type of weapon base. And go ahead and select
the object reference. Now, since it is
an inventory now, let me just go ahead and
click on the X here. Since it is an inventory, we have to change it from a
single variable to an array. Remember, an array is just like a box where you add stuff to it. We have to add the different weapons that you have looted. You can see if I
click on the plus. Now here I can't select because
it is the parent class. And we can't really
just add stuff here automatically. But you can see you can add the rifle and
the pistol during gameplay. You can add multiple weapons
inside of this inventory. But for us, we want to add, for example, a
rifle and a pistol. And you can have a shotgun
and so on for your game. But for now we just have
the rifle and the pistol. Go ahead and just
delete it for now. This was just for example. Let's go back to
the player base. Now from the player base, since we already
have the reference, we can drag from here and search weapon inventory and
we can get that array. Now for this array,
we want to loop through this whole
inventory and check if the player has a rifle
we can drag from here and say for each loop with brake. And you can
go ahead and select that. Now you can see the
weapons through this spin, if you hold the mouse over it. Now it is a single element. It's the BP weapon base. It's going to take
every single weapon inside of here and
loop through the code, loop through this array, and you can do
something with it. Now what we're trying to do
is we're trying to check if the player already has this weapon they're
trying to interact with. What we need to do is we need to take each of the weapons in the inventory we need to drag from here and check
their weapon type. Remember, you just made
this one weapon type, so you can call it here. Now it is looping
through each of them. You're taking the weapon type, you're just asking here, dragging and saying equal, if this weapon type inside
of your inventory is equal to this weapon type
that you are trying to loot. And we can make a branch, if that is correct, then you can't loot the weapon. We have to do it later on that
you can't loot the weapon. However, if it is false, we can actually loot it. This is how you do it. Now
we need to make this one replicated because
the client also needs to see this information, what type of weapon you have. I'm going to select
replicate it. Go ahead and compile
and save everything. Now you can see here we're
taking the weapon inventory. We're trying to check if the player has the
weapon already. We're taking the weapon type with the weapon inside
of the inventory. And we're checking if
this weapon type is equal with the one we
are trying to loot. If that is correct,
we can not loot the weapon because we already have the weapon
in the inventory. If it is false, we
can loot the weapon. Okay, this one with break,
we can use it later. I can explain what that
means, but for now, we can now save everything and we can move on
to the next lesson.
93. 8.08 Looting the Weapon: Now let's go ahead and make it possible for the player
to loot the weapon. So now we checked that the
weapon is in the inventory. If this is true,
let's go ahead in the player base first and
let's make a new bullion, and I'm going to
call it loot weapon. I'm going to change
it into a bullion. Let's change it to
a single variable instead of an array.
Let's compile. Now This one is going to be true if the player
can loot the weapon. And it's going to be false
if the player can't. What I'm going to do is I'm
going to put it as default. So the player can loot
the weapon by default, unless we find it here
in the inventory that the player already has
a weapon by default. Go ahead and set it to true. Let's save everything and let's go to the weapon base now. Now what we can do is break
from this player again and search for this can
lot weapon bullion. We're going to set it here. If we find this weapon that we're
trying to loot, if we find it in the inventory, we're going to set it to faults. It is true by default, but we're going to set it
to faults that the player cannot loot the weapon if we actually find it
in the inventory. This loop here doesn't find it in the inventory
for the player, it's just going to be fault for all of the items it's
searching through. At the end, when the
loop is completed, this one is still true. If we did not find any
weapons, it's still true. So we can go ahead and loot the weapon we can
drag from this one. Now again, and I can search
for can loot weapon. Depending on if this
is true or false, we can do some action
here when it is complete. First it's just going to
loop through the items. And after that we're
going to check if this can loot weapon is
now false or true. Now I'm going to organize
this a little bit. Going to add a rear rock node
here and plug it into here. Instead, if this is true, if the player can
actually loot the weapon, let's go ahead in the player
base and let's go down here. I'm going to write click and
make a new custom event. Let's call this one
lot weapon again. I'm just going to run
it through the server. Just making sure now it is already running
through the server. Because you remember you are running it through
the authority. It is already running
through the server. However, I'd just like to do it this way so I stay consistent. You can just write this
server one right away. You don't have to do
this because we're already running through
the server for you. You can just use this
one if you wish to, but I just like to stay
consistent with my code. I'm going to run it
through the server here. Again, I'm going to drag from
this one and run this one through the server like this. Then I'm going to write
my code over here. Now again, you can just write a code over here if you wish to, but in the future, if you're not running it
through the server, you have to run it through here. Now we have this written. Now what we want to do
when we loot the weapon, we just want to add this looted
weapon to the inventory. We're taking this
weapon inventory and we're saying
set array element. Because we want to add
it to the inventory, it asks you, what index
do you want to add it to? I just want to add it to
whatever index is available. So I'm going to direct
from here and say length, then I'm going to add it here. Now remember, arrays start from the index of zero and then
they go to 123 and so on. If you drag from here and say, last index right now, the last index is three, or this array here. If you're taking this last index and plugging it into here, you're actually
going to overwrite whatever weapon is in
the index of three. If you want to use
the last index, you have to take the last
index and say plus one. You're finding the last
index and then you're actually adding the new weapon
here in the index four, which you can plug into here. Now a better method to do it
is just finding the length. The length is 1234. It's actually going to add
it to the index of four. We don't have to do this here. This is why I use length. It's going to output four. And you can also see
this if you just write a print string and
you connect this to here, always nice to add
print strings. If you want to check values
for what you are doing, I'm going to add
it to this index. Now, what item do
we want to add? It's the weapon we want to add. Now, we don't really have
any reference to the weapon. Let us do that. Let us click
Loss on this event here. And let's search
for weapon base. And let's select it here
and call it a weapon. You can also call it looted
weapon if you wish to weapon. And then I am going
to take it from here and plug it
into this event. And now we can use it over
here in the weapon base. If lot weapon is true, then we want to
take it here from the player base and
search for a lot weapon. This is what we called it. Go ahead and select
it and you can now connect it here again, I'll click to make
re wrote notes to make it a bit more readable. Just like that. Now it's going to ask you,
what is the weapon? What is the variable for it? Now the way you define this is, remember you are inside of the weapon base if
you just strike and write self because it is the weapon you are
interacting with. If you interact
with this one here, it knows it's the 41 because it is the one
you're interacting with. And if you write self
as the reference, it knows this weapon is actually the one blueprint
clause down here. If weapon is said to
false, it can loot weapon. So it means you can't loot the weapon because
at some point it actually found the weapon in the inventory and you
cannot loot the weapon. Now if it finds the weapon in the inventory at let's
say for example, the first index, it
actually found the weapon. And it doesn't make sense
to loop through all of the other weapons because it already found the weapon
and you cannot loot it. Anyway, this is what this
is, what this break means. I want to break the loop. I don't want to loop
through this array anymore. When I find the weapon
through the inventory and I can set the can
loot weapon to falls. I actually want to drag
this and set it to break. I can double click now and make some rear out notes so
it's easier to read. What I'm saying is, is when you find this weapon
in the inventory, go ahead and break the loop. Because it doesn't make
sense to loop through all of the items when I already found the item and I cannot
loot it anyway. So it's going to break
and this can loot, weapon is set to falls. So you're not going to loot anything because we
haven't any code here. But remember, you
have to set this one to true again
because it is true. By default it has to be true. This will bug out next time you're going to
interact with a weapon. It's going to be
false by default because you didn't remember
to set it to true. By default it's
going to be false. And even though you
can loot a weapon, even though it didn't
find anything, this one will be false. The next time you loot a weapon. Remember to drag from this
again and search again for can lot a weapon and set and then remember to
set it to true again. By default, whenever
you interact with a weapon again in the future
you can actually set, but you can actually
loot the weapon if you don't have it
in the inventory. I can also just
click and drag this into here is actually going
to look a lot better. Something like that. So
now it should be true, you can go ahead and
compile everything again. Remember if you did it like me, go ahead in the player
base and in the inventory, I'm going to delete all
of those here that I just made to demonstrate
the weapon inventory by default should
not have anything. Go ahead and save everything. And now for this weapon here, let's take it up here, organize it a bit better. And now what you can do now, you can connect this
weapon because we have defined it here
as the self reference. Now you can take, this weapon
is going to run through here and it's going to be
added to the inventory. Again, double click to
make rear route notes. Now you are looting
it to the inventory. And go ahead and
select size to fit. It's going to make sure
to add it to that array. Go ahead and compile. And now it should work
correctly to test it. To make sure, go ahead and drag from here and
write a print string. And you can always
take this one, let's paste it here. And let's drag and say
gets and get a copy. And we can always get the
index zero because this is, remember in arrays it
starts with the index zero. We're getting the
index zero and making sure that we're actually
looting the weapon. This. And add it to the string so it knows
the name of the weapon. So now we're going
to print the name of the weapon to the screen
that we have looted, go and compile and
save everything. And let's make sure
everything is working. Let's click on play.
Select Terrorists And if I walk into here it's going to say AK 47
as you can see here. Now the one doesn't
really matter, it's just the number
for this blueprint. We can take this one. Now you can see I can't
interact with it because I already have a rifle
in my inventory. So now if I play
again and select the terrorist and I
go through the 41, it prints the 41 to
the screen up here. Now, if I go through the pistol, because you can
see it for the K, it doesn't print
anything because I already have a rifle
that is working correct. Now if I go through the
pistol, it should print it. And you can see it is printing however it's printing
the wrong name. And remember for
the print string, we're only printing
the index zero, so it's only just
printing the 41. We just loud it
can always set it to index one and it
will print the pistol. Now if you want to
print everything inside of this inventory to see
what is inside of it, always drag from here and
say for each loop now you're going to loop through
this whole array and you can connect the loop. And then you can select
each of the single name of the item that is
inside of here and you can print it as a string. I can go ahead and pick
up the AK for example. Then you can see it
prints it to the screen. I can go to the pistol and
now it's going to print both the AK and the
pistol to the screen. It is working as
it is supposed to. Let us save everything and let us move on
to the next one.
94. 8.09 Creating the Weapon Socket: Before we can attach the
weapon to the player's hands, we have to create a socket. Remember, we created
a socket earlier. When we created the
player camera and we attached that camera to
the head of the player, we need to add another
socket where we attach the weapon to
the hand of the player. Let's go to the Marketplace
folder and go to the military character Silva to go into that skeleton here. Remember this is the camera, this is the socket for the
camera that we added earlier. Now what we need to do is
we need to add a socket for the hand of the player so
they can hold the weapon for the hand, right? This is where you usually hold a weapon. Having it on your right hand. For the hand, right,
I can right click and add a socket here. I'm going to click
on two to rename it. And I'm going to call it Rifle. Now I'm going to
add a socket for a rifle and socket
for the pistol. Now, I tried earlier just
adding one for the weapon. Weapon and I could
add the pistol and the rifle to it. However, position in the
hand are different. It's a lot better to add one for the rifle and
one for the pistol. It looks a lot better
selecting S rifle. Let's go ahead and add
a preview animation so we can actually see what it looks like if I just search for rifle and I search
for one of them. For example, the
animation idle rifle. I'm going to pause
this animation to the first frame just so it's
still and it's not moving. And I can adjust the socket. Clicking on the socket rifle, I can right click now to add preview D. Let's just
go ahead and add, for example, the 41,
or it's called R four, actually over here
and select it. Now we can preview it and
we can adjust the socket. So go ahead and
click on the socket. And go ahead and select
the rotation tool. And now you can rotate
it 90 degrees this way. And I'm just trying to adjust it to the hand so
it looks better. I'm going to reduce my camera
speed. It is way too quick. Now you can see the
one mistake here, you can try to
adjust the socket. Right now, the one mistake for this character is he's actually holding the
rifle like this. It looks weird
because he's going to shoot forward down here. If I'm standing in front of him, he's actually shooting in the air when he's
supposed to shoot on me. That is a bit like
wrong on the animation side. You can't really do
anything about it. Let's try to do it
as best as we can. This rotation should
actually be like, this should be shooting forward. We're going to remove the
snapping for the rotation. And I'm trying to make it aim forward as
best as possible. You can also go to
the right view. Actually go to the front view. For the front view,
you can again, just rotate the weapon as
best as you can. Here it is. Maybe better to see how he
is aiming forward like that. You can go back to
the perspective and take a look at it, make
sure he's aiming forward and everything is looking great,
maybe, something like that. Then you can go ahead
and move it up, try to place it in the hand of the character,
Something like that. Just try as best as
possible to place it correctly in the
hand of the character. For example, having
this trigger over here, making sure it
doesn't go through his fingers like this here. Trying to move it
forward a little bit, but still having it in
the hand of the player. Now you can't really
do it perfect. If this was a serious
project, the characters be designed in a way that they are holding this
weapon correctly. The weapon and the
character fit together. For example, in counterstrike, they're designing it like that. However, here for this one, it's just a random character, random animation.
With random weapons. You can't expect this
to be 100% doable. We're just trying to fit
it as best as we can. Now, this one is looking good. Everything is looking great. I can just try to drag
it back a little bit, just like that. Everything
is looking great. He's holding the weapon now. And you can see if I animate it, it's going to look like
this. Looking awesome. Now you have to test it
with the other rifle. Just to make sure, I'm
going to right click this one and remove
all attached assets. I'm going to right
click again at review. Now let me add the KA for seven. Let me add the AK. You can see the AK is clipping
through slightly. What I'm going to do is
I'm going to move it up as much as I can without making
it book something like that. Now it's going to clip
through slightly here, but whatever, like we can't
really do much about it. These weapons are not designed
for these animations. We can't be 100% accurate. But something like this here. And again, I can
select the rifle, suck it right To
move it down as much as you can without making it look buggy,
something like this. Maybe that is the best I can do. If you just right click, remove attached asset,
right click again. Add the AR four as the preview just to make
sure what it looks like. It's a bit more upwards. But this is the best we
can do for this weapon. Like we can't really
place it better because it's going to
bug for the AK as well. Now we can look through the ice of this character and make sure the
rotation is correct. I think it's rotated
a bit wrong side. I'm going to click on the
socket again and I'm going to hold and then rotate it
in this direction here. I think it's tilted
a bit, maybe. Something like that. And
it looks a lot better. Okay, this was it. That yeah, everything
is looking good. Now, just to make
sure, I'm going to right click this
again. Remove it. I'm going to right
click at the AA 47 just as the last time just to make sure that
everything is correct. Now what we can do is we can always drag it a
bit more this way. It's not bugging here
through the handle. Something like this. Okay, it looks better now,
everything looks good. Now you can always adjust
it slightly up and down. I think it looks good. Now
let's save everything. Now you have to remember to add this to the other
skeleton as well, but let's add the pistol first. Before we do that, let's
go to the preview now. Or not previews.
Preview animation. And let us search
for pistol now, let's take one of the
pistol animations. And I'm just going to select
this one pistol idol here. Let's pose it at the
first animation. Now for this one, I'm going to remove all attached assets. Let's right click on the
hand and add a new socket. And I'm going to call
this one pistol. Actually pistol. We
know it's a socket. Now for this one,
let's right click and add the pistol as
the attached asset. If we just add our
pistol just like before, let's rotate the socket. I'm going to add this
snapping tool on rotated 90 degrees again to rotate it this way so
it's pointing forward, you can always go back
to the front view. Go ahead and zoom in.
Select the pistol or the socket here and
remove the snapping. I'm going to rotate it slightly down so it's aiming correctly. And go to the perspective view. Check if everything
is looking okay. Try as best as you can
to make it aim forward. And we can always
adjust it later. Now let us move it into
the hand of the player. Like that, this way,
maybe this way. Again, try to place the finger on the trigger
as best as you can. So something like this, again, we can always
adjust it later. It's not really a problem. If something is a bit messed up, you can see the rotation is a bit messed up. It's
tilted too much. I'm going to, again,
rotate it this way, so it's not tilted like
this. I think this is good. We can always adjust it later. Now let us try to
move it as best as we can in the hands of the player. I think something like
this is looking good. I think I'll move it just
slightly up, just like that. Okay, now he's holding the weapon and he's
shooting it forward. We can always try to preview it. You can try to preview with other animations if you wish to. For example, if I search for pistol and I take
the pistol fire, you can see what it looks like. Looks good. Now let's go ahead
and save everything. Now you have to copy those. Let's right click and remove
all the attached assets. You have to copy those to
the other skeleton as well. So I'm going to
take this socket, I'm going to right click here
and copy selected socket. Or you can click on control C. Go to the other skeleton,
the military doc. Click on the right hand
and control V to paste it. Let's go to the other
skeleton as well. Copy the rifle one and click control V to
paste it here as well. This one have it as well. Now, both the counter
terrorist and the terrorist should work now. Okay, so that was
it for the sockets. Let us move on to
the next lesson.
95. 8.10 Creating the Remaining Sockets: Now let us create the
remaining sockets. So let's go back to the skeleton for the character silver. I want to add the
rifle to the back of the character if the character is already holding the pistol. So we don't want to add
the pistol to the hand of the character is already
holding a weapon. Let's go. Let's say for example
the pistol animation. Just select one of them.
Let's just select this one. Idle one again. I'm going to
pause it at the first frame. I'm going to add a socket here
to the back for the rifle. I'm going to add the rifle on the back if they
are not holding it. I'm just going to, if you're
not sure what bone to use, you can always click
on Character Bones and then show all the hierarchy. And then you can try to choose the best bone that you can see here on the
player that will fit. For example, you can
choose the spine two or you can choose
the spine three. I think I will choose
the spine three. You can choose the spine
three. Right click. Add a socket. I'm going to
call this one is weapon. The weapon is going to
be here on the back. Let's right click again, add
a preview mesh and let's just add the K are called KA 47. Actually let's select this one. Let us just rotate this weapon. I'm going to hold or select this snapping tool and I'm
going to rotate 90 degrees. This way I'm going to move it outwards and just try to
place the weapon as you like. There's not really an answer
for what is correct or not. Whatever game you're
trying to do, try to do it your
way, your style. You can always drag it to the back of the
character if you wish. You can always tilt it
like this to make it look better and just place it on the back of the character
as best as you can. And maybe something like that. I think that is looking good. I can move it up just slightly. I think this looks
good if you just play an animation to make
sure everything is good and everything
is snapping. If you just make
a run animation, for example, front right, unarmed, you can go out
and play the animation. And I can click on
character bones. And select it only to remove all of the bones so I can see what it actually looks like. And it looks like that. Okay, Everything is
looking correct. The weapon is moving
with the body as well. I can also select
Remove Attached. And I can select the AR Four just to see what
it will look like if they're holding that instead. Okay, everything
is looking good. Yeah, that is attached
to the player. Now we can right click
and remove all attached. The second thing I want
to add now let's go back to the idol and
let's select one of them. For example, the pistol idol I'm going to posit
in the front one. What I want to do is I
want to add the pistol to the side of the character when they are holding the rifle. This one was for the rifle, the other one here
is for the pistol. But this one again, you can click on
the character bones all hierarchy and you can
select a bone here that fits. For example, this one.
This is the thigh. We're going to create it here, the thigh, right click, add a socket and call this
one is weapon just like that. Go ahead and right
click this one. Attach a preview asset
and select the pistol. This one just like before, I'm going to add the snapping tool and I'm
going to rotate it this way. For example, let me move
it forward as well. The pistol when
realistically place it here, going to actually be on the opposite side,
something like that. Instead, I'm going to
rotate it if you wish, you can rotate it somehow and try to place it as
best as you can. Now realistically, if it was a player
designed for this game, I would not place this one here. So we could actually
place the pistol here. But we can try to place it
under this bag as best as we can and try to move
it outward a bit. We can also move it or
rotate this direction and try to place it as best as you can on the thigh
of the character. I think this looks good. Now if you just
save everything and let's just try to have
the run animation again. Select one of them, for
example, run front pistol. And if you just play it now, you can see it here. Now character, I'm
going to select bones. Select only so I can
remove the bones. And here is the pistol
when you run with it. Okay. That is attached
to the thigh. We can now stop this animation. And I can right click or
another pistol, the thigh one. If I can find it here, this one down here,
I can right click. Remove all attached assets. And remember to copy this as
well for the other skeleton. If I just double click here and I open up
the character doc, I open up the skeleton as well. Let's copy the thigh socket. And I'm going to find
the thigh right here. If I can find it. This one
control V to paste it. I'm going to go back
and I'm going to find the back socket Over
here there is weapon back. I'm going to copy this one. And for the spine three again, I'm going to paste it and it will be correct
for this one as well. Let's save everything and let us move on to
the next lesson.
96. 8.11 Attaching Weapon to Hand: Now that we have
created these sockets, we can go ahead and attach
the weapon to the hand. Let's go back to
the player base. In the player base
previously, if you remember, we already made the
loot weapon logic here. We can actually make the player
equip the weapon already. What we can do is we need to use something called attach if
you just search for attach, so you can use one of
those, for example, attach to actor, or actor
to component and so on. So you can just select one
of them to see what it is. You're basically here for
this one, for example, you're attaching an
actor to a component. For example, you're attaching
the weapon actor to the mesh component where you select which socket
you want to add it to. For example, the pistol. And then you can
snap it to there and you can attach
it to the hand. Now instead of doing this, remember we are inside
of a multiplayer game. This is not single player. If this was single player, we could just do
it up here without all of this server and so
on, and it would work. However, since we are
in a multiplayer game, we need to replicate information from the
server to the client. For visual changes like this, you have to use something
called a rep notify. And we haven't used
that before yet. If you just right click on this weapon and you
promote it to a variable, and I'm just going to
call it looted weapon. Now four variables. Let's now first collect
or connect this one. Let me double click, actually we already have a rear
route node over here, so I'm going to
drag it down here. Double click on this one. Now we have this variable. And if you click on it now, instead of setting
it to replicate it, you have something
called a rep notify. And where rep notify
is if you have any visual changes in your game that needs to be
sent to all of the clients, you need to use a rep
notify replicate. It is only used for
information like numbers that are going to
be sent to the client. Previously we have this one called equipped
weapon, for example. This one we said to replicated. Because the client needs to know if this variable
information, what it is set to, if it's set to unarmed pistol or rifle. However, for this one I am
going to do a visual change. It's not just number and
information like text. I have to update the weapon. So it is attached
the player's hands, it's actually a visual update. This weapon is going
to teleport to the player's hands and it
is going to stay there. So I have a visual change
that I need to do, and this is where you
select a rep notify. Now if you remember, we
also use a multicast. So if I go back
to the footsteps, we use this one
called a multicast. Multicast also sends information
to all of the clients. Why are we using
something called a rep notify instead
of a multicast though, a rep notify is used
for if you have visual changes that needs to be shown to all
of the players, even those that are not
connected to the server yet. Let's say someone
connects to the server, like I go here and I
loot the 44 or 41. Someone connects to my
server 2 minutes later. If I do this code
inside of a multicast, the connected player
will not be able to see that I am holding this 44. The multicast is only usable
for temporary things. For example, footsteps
here and now. Or if I play some
firework visual effects that will disappear
after 2 seconds. The connected players don't, the player who is
connecting right now doesn't really need
to know about this. Because it probably already
disappeared in the level. For example, the visual
effect for a rep, it is used for visual
changes that also needs to be seen by someone who is going to
connect to your game. 2 minutes from now, I want to see players who
is connecting to my game. I want them to see that
I am now holding the 41. Let's go over here. And let's click on it. And
let's click on Rep, Notify. Go ahead and compile.
And you can see it already created like
a function for you. This is going to be called, so you're going to
loot the weapon. And this one is going to be set. Whenever, this is going to
be set and changed in value, it is going to automatically
run this function. So now we can write the code
inside of this function. And whatever we write
inside of here, this will be notified
to all of the clients. Okay, so first before
we attach anything, I want to take this looted
weapon that we just looted and let's strike here and let's search for
the weapon mesh. So if I go to the bottom
and select weapon. Remember, this weapon here. If I go back to the weapons
and select the weapon base, this is the weapon
skeleton mesh. I'm going to select the
skeleton mesh because remember we are
simulating physics. We don't really need
to simulate physics. Whenever this weapon here
is in the player's hands, we need to remove the physics. What I need to do is
first I need to drag from here and say set
simulate physics. Let's go ahead and connect it. Let us set it to be false. We don't really need
to simulate physics when it is in the
hands of the player. The next thing is I also
need to remove collision, because when it is in the hands of the player,
we don't really need to collide with anything. Again, drag from
this weapon and say Set Collision and
select this one. Set Collision enabled, and let us connect it
and no collision. Now the weapon don't
have any collision. We don't really need it when the player has
it in the hands. Now remember in the weapon base you also have the sphere here. You need to remove the
collision from this as well. Else other players can
actually walk into you when you have the weapon and they can loot the weapon from your hand. Now you can have it as
a feature in the game, but for this one,
let us remove it. Let's take the
looted weapon again. And I'm going to
drag from here and search for my collision sphere. And it's at the bottom here. And actually it's called
collision just called sphere. And I'm going to rename it
actually to pollsionsphere, just so it's more obvious. Collision sphere. Go
ahead and compile. Let's go back here and search
for pollsion sphere now. And let me go to the
bottom and select it here. Okay, just like before, drag it here and say set collision enabled this one here and let us set
it to no collision. Now when other players are walking into this
collision sphere, they are not interacting
with it because it now doesn't have
any collision here. I'm going to remember
to make this false because we don't need to simulate any physics.
The collisions of weapon and the collisions for the collision
sphere as well. Now when we use the
attach the function, we actually need to
do something before. Because when I was doing this
before, there was a bug. I was playing here. And I
attached the weapon to my hand. Whenever I walked into these
weapons for some reason, even though I attached
them to my hand, they kept being on the ground
and I didn't understand. The reason is here for
the simulate physics. You can see here at
the bottom it says, Note that if this component is currently attached
to something, beginning simulation
will detach it. This means when I
simulate physics here, it will actually detach this weapon from the
default scene root. Right now, it's just like if
these two are not attached, this is separate from this one. I actually have to
reattach the weapon to the default scene root.
Let's actually do that. Let's take the
looted weapon if I drag from here and search
for default scene root, the same name here at the
bottom, and select it. Now what I want to
use is I want to attach a component
to a component. Remember, these are components
if drag from here and Seach and you can select this one attached component to component I'm trying to attach. Not this one
actually. I'm trying to attach the weapon here. The fi just rag and search for weapon and go to the bottom
again, select the variable. I'm trying to attach the weapon to the
default scene route. It looks like this again. Let us go ahead and connect it. Now we have to
select the socket. The socket, we don't
really have anything. We're just connecting the weapon with the default scene route. This one is fine for
the location rule. All of these needs to
be snap to target. It snaps to it just like this, and now it is correct snaps. Let's go ahead and
compile. And now everything should be
working correctly. Now if we try to attach the weapon to the
hand of the player, so we can drag from here. Now for the attach,
we're trying to attach an actor,
this weapon base. I'm trying to attach an actor to this mesh here,
which is a component. We need to attach an
actor to a component. If I drag from here and say attach and you can search
for actor to component, I'm trying to attach the
looted weapon actor. If I just copy pasted here
to the mesh over here, which is a component, the socket we're
trying to add it to right now is let's
say for example we called it rifle. Let's
try for the rifle first, and we can always do
the pistol later. Again, snap to target
for all of those. Let's go ahead and compile
and save everything. Let us see how it works
if I click on Compile now or Play now and
select the terrorist. Now if I walk into the rifle, you can see it's
actually in my hands. You can see it here
on the shadow. It's actually in my hands. Now the reason why
I'm not holding the rifle animation is
because we also need to update the equipment,
the equipped weapon. Remember, if I go back to
the animation blueprint, this is some time
now that we did it. If I go to the player, animations and
animation blueprint. Remember that we're switching these animations here depending on what this equipped
weapon enumeration is. This one is coming from the
player equipped weapon. We need to change this one in order for the
animations to change. What we need to do here
is let's do that quickly. If we go back to the van graph, I can right click and
make a new custom event. I can call this one
set equipped weapon. Again, I'm going to copy
this name right click, make a new custom event, run it through the server. This one run on server reliable. I'm going to run the server one through this normal event set weapon. Now for this one, the only thing it's doing is it's setting this
equipped weapon here. If you just connect
it like this. And if we connect it
like this, again, the only thing this event
is doing is it's setting this variable here to whatever
we wish to set it to, and we're going to
use this one later. Let us compile now.
Remember, you can only set variables and replicate them when they are running
through the server. You can't use this one up here. You have to run it through
the server before you can set it and replicate
it to all of the clients. Okay, now this is done. Let's double click
on this variable. Again, you can open up the function here or
you can just double click here and it will
make you enter to here. Now remember we need to set the equipped weapon for
the animation to update. If you drag from
here and search for the set equipped
weapon we just made, then we have to select what is the thing we
want to set it to. The thing we want to set it to is whatever you have looted. Remember in the weapon you
made, this weapon type. If you take this looted weapon you drag from here and
search for weapon type. Now you know if it's a rifle
or a pistol for example, and it knows what
animation to use. If you connect it here, compile. Let's click on
play. If you select the terrorist, just so
we spawn beside it. And if I walk into
this AK for example, it's now going to change the animation to
the correct one. Now if I open up
the client as well, just to make sure that
everything is working. If I play as the server here, and I'm going to minimize this, and I'm playing as
the client as well. So I open up the counter
terrorist for this one, and I'm opening up the
terrorist for this one. I'm going to walk over with the counter terrorist and just to see if everything
is working correctly. If I work into this four, you can see I have looted it. If I go close to the player, he's not interacting with my collision sphere because I have set it to no collision. And now for the other one, if I walk into this AK, you can see it is
looted as well. I think I'll reduce the AK size. Maybe the weapon
looks very large. You can see now
it's only looting the rifle because now if
I walk into the pistol, it's also going to set it to
the socket for the rifle. And it looks weird like this. And we have to
change this later. So let's do that in
the next lesson. For now, we actually attached it and we can make this
a bit more complex. So it is also working
for the pistol.
97. 8.12 Attaching Weapons to Back: All right, so let's make
this code a bit more complex instead of just
attaching it directly. Now I have to ask if the player is already
holding a weapon or not. If the player is already
holding a weapon, I want to attach this
weapon to the back of the character because they're
already holding a weapon, so we don't want to
attach it to the hand. What I want to do is take this equipped weapon and drag from here and
say, is it equal, equal to an art? Right now, do you have no weapons? If that is the case, like
you're not holding any weapons, I actually want to attach it
to the hand of the player. What I can do is I can
connect it here, here. Instead of just attaching it to the rifle socket,
maybe it's a pistol. What I can do is I
can drag from here and say select this one. We have used this one before, but now we can see
another example of it. Now we have to select depending on what
the weapon type is. If it's a pistol, it's going
to use the socket pistol. If it's a rifle, it's
going to use socket rifle. I'm going to copy
this weapon type again and I'm going
to connect it here. Or if the weapon type
is equal to unarmed, we don't really need
to do anything. If it's pistol, I want
to attach it to pistol. That's what we call the socket. If it's a rifle, we want
to attach it to rifle. Now it knows what socket to use, depending on what
the weapon type is and everything
else is correct. Now let's actually just
move it over here. However, if you are not unarmed, it means you already have
a weapon in your hand. Let's copy all of this again and now, instead of depending now on what the weapon type is, I'm either, if it's a pistol, I'm going to add it
to weapon thigh. Remember that's what
we call the socket for the thigh weapon. If it is a rifle now it's going to put
it to those as well. This is going to
be connected here. If it is false, I'm just going to move all
of this closer. Now it is more organized and we can go out and compile
and save everything. We only want to set
the equipped weapon whenever we have
nothing in our hand. Because if we do have
something in our hand, we just want to
add the weapon to the back of the character.
Let's save everything and let us click on play. And if I select Terrorist
here, and I walk to here, let me actually just open up this one so we
can see if it is working for this character if
I just maximize this a bit. So you can see if I now
walk into the rifle, you can see I hold
it in my hand. If I walk into the
pistol right now, you can actually
see that the pistol has fallen through the ground. I actually want to fix this. And I believe it's
this mesh here. It's really thin, so it's
falling through the ground. Let's actually fix that. Let me take the
box here, if I go, let me remember
where I saved it, the super grid
folder, stata pack, and meshes. And let's use the super grid box for the
ground instead of the plane. I'm going to take this box. I'm actually going to snap it to 100 here for the movement. First I'm going to put this
box to something like here. And let's move it down
to the ground again. And I'm going to push it back just like where
this ground is, I'm just going to
move it like this, I believe. And here. Okay, now it is on the ground. Now I'm going to
scale it the same as the scale for the ground. I'm just going to try
as best as I can. Let me actually just scale it up first. Let me scale it up here to 1010 for the Z. We don't really need it. Let
me just click on this lock. And let me write one here. I'm going to click
on the ground, actually it is further
down like this here. And I'm going to snap it over here and over
on the other side. Okay, now it snaps
on the ground. And I'm going to
click on the ground. I'm going to hold shift and
right click to copy this. 80, 81. I'm going to
click on my box here. I'm going to hold shift and
left click to paste it. And now it should be correct. Now if I go over to the
other side just to check if it covers the ground
and it does, okay. Now what I'm going to do is I'm going to select the plane. I just click a couple
of times here. It's going to select
the super grid plane. I'm going to delete,
and I'm going to copy this material
to hold again. Shift right click the ear, shift left click to
paste this ground here. And it looks just like before. Okay, let us save everything. And now if we click on Play, it should not fall
through the ground. The ground was pretty
thin and I have a suspicion that it's white's
falling through the ground. Let me again
maximize this a bit. Now if I play as this player, and I dilute a M four
and I dilute a weapon, it should add it to the thigh. You can see on the
side of my character, I can now see the weapon. Awesome. Now for this K, I can loot as well
as the other player. Right now it has disappeared. You can see the client
cannot see it on the server. You can see that it looks
correct because remember, the server has the authority
and can do anything. However, for the player,
it is on the back. As you can see here
on the shadow, there is some, a
replication issue, some value that is
not going over. The only thing I can think of this unarmed equipped weapon, because this one
chooses if it puts the weapon in the
back or in the hand. The way you fix this
issue where you can't see the weapon
when you loot it is. Let's actually do
this another way, the set equipped weapon. The reason is it's
not really knowing this value because sometimes
when I play as the client, it puts this weapon on the
back of the character. You can see here, instead
of looting it to the hand. The reason that it puts it back on the back of the character
is a replication issue. For some reason
this equipped we, this is the one that controls we should be on your hand or the weapon should
be on your back. For some reason it's seeing that this equipped
weapon value is not armed like you have
a weapon already and it puts it on the back of the character instead
of in your hand. This is actually
because we're running this one through the rep notify. We don't need to do that
because it will buck the game. I'm going to remove
this. Let's go to the event graph instead. Let's run it here on the server. Because we have to set values through the server
instead of through the rep, notify, instead of just
changing it directly. Remember, you only want to
set the equipped weapon whenever you are
here in the unarmed. Whenever you are unarmed, you want to set the equipped weapon because you don't want to change it whenever you
put that weapon on the back. Instead, for this one, we have to take the
equipped weapon. And again, we have to ask
if it is equal to unarmed. And let me just move this away. Make sure to ask, are
you unarmed or not? Because we only want to run
this code if you are unarmed. If you are unarmed, yes. Let's go ahead and I'm going to put a delay on the code
before we actually do this. And the reason I do this is I'm giving a chance
for this rep, notify to run out of this code. Remember it is going to use this equipped weapon variable to check if you are
unarmed or not. And this will be bugged
If you instantly put this equipped weapon and
change this weapon type, we're making sure
to delay it a bit. Make sure that this
code runs through before we actually change the weapon type or the
equipped weapon here. This delay needs to
be as low as possible because it will look
weird if you're running around without the
animation applying. But let us just try it like this one before
we do anything. So let me click on play
here as the terrorist. Now I can click
on play and I can walk into the weapon and
see if it is working. Now you can see it's working. I have to a couple of times just to make sure
that it is actually working, and now you can see it
is not bugging out. I think this fixed the problem. However, in the future, if we still have a
problem with this, we will try to fix it. But I think it is actually fixed now and we don't have
a problem with it. Okay. Now let's try to
reduce this number, 0.05 something very low. And we can try to play
and try to reduce it, but it is still going to work. Now you can see it
is still working. If you reduce it too much, you go into the
risk of the code in the rep notify not being
able to reach at this point. Before you actually do this, make sure it's slow
but not too low. You'll run into problems, but as you can see here,
everything is working. And just make sure that
you comment this delay out because if you come back
three months later, you have no idea
why you did this. Make sure to hold, click on C on your
keyboard to add a comment. For example, you can
for this comment, make sure that the
weapon is attached to the hand before changing
the player equipped state. Just like that.
You can even write that you're waiting for
the rep notified to apply. Go ahead and compile
and save everything. And that should work
if you click on play. Now if you walk into the pistol now, you
can see it's changing. If you walk into this
one it's putting on your back and I can see
everything is working right now. Another buck that we have, the last one hopefully, is when you place two weapons
on top of each other, it's going to be a
bit confused because you're overlapping two spheres and I don't know which one to loot and it's going to
bug out if complain now. And here is the client. I
walk into both of them, I try to run into both
of them like that. You can see that it's actually
holding the pistol and the four at the same time
and it's a bit confused. We have to fix
that buck as well. Let's actually do that
in the next lesson.
98. 8.13 Overlapping Two Weapons at Once: The problem we are
facing right now is if I walk into
two weapons at once, it will bug out because now
you can see I'm holding the pistol and the
rifle at the same time. So this is a bug
that we have right now and we need to fix somehow. We need to check for both weapon overlaps
and not just one. Because right now we're just checking for
one weapon overlap and we're not checking
if there are two weapons that are overlapping
at the same time. To fix this, let's actually
go to the player and let's open up the player
base inside of here. Right now we have
this loot weapon. Instead of just
looting the weapon, I need to make a new array where I gather all of
the overlap elements. And then from those
overlap actors it will go ahead and loot the weapons instead of directly
looting the weapon. Let's take all of this
and push it down here, and let's right click and
make a new custom event. I'm going to call this
event a overlapped item. Okay, with that one, again, I'm going to run
it through the server, custom server, and
add overlapped item. And then remember to run it on the server and reliable as well. And I'm going to run that server one up here in the normal event, add overlapped item,
just like that. What we need to do is
I'm going to create a new array called
overlapped items. Again, this is a weapon base actually not overlapped items. It's probably more accurate to call it overlapped weapons. And then right
click, or just click here and search for
the weapon base. Go ahead and select it. Let's go ahead and
select this array again. Now instead of overlap item, it's probably better to call it a overlap weapon that is more accurate so we
don't change our style. A overlap weapon just like that. And go ahead and
take this array. What we can do here, whenever we overlap an item or a weapon, we can go ahead and add
that weapon to this array. Now we need to know what weapon
are we overlapping again. Go ahead and add a variable, search for weapon base. Just call this one weapon and go ahead and connect
it up here as well. It goes from here whenever we overlap and then the
information is here. Just like before,
what we did here. Go ahead and take
this and say set array element and connect it. This is the item we
want to add to index. Again, just what I
told you before. Let's use the length. Take from this search for length and it will automatically
find the correct index. It will add it to go
ahead and organize this. All right, What we
are simply doing is instead of instantly looting
the weapon from the ground, we are adding that overlap
weapon to this array. And then from this array we can go ahead and
loot the weapons. We make sure that all of the overlapped weapons are
getting looted from here. When I overlap a weapon, remember to again run this loot weapon because
else you will not run it. Let's actually go back first. Let's go back to the weapon base instead of the weapon base now, instead of here with
the code we wrote, instead of looting the weapon instantly when you know
you can loot the weapon, go ahead and add it to the
overlapped weapons instead. Let me remove this. Let's search for here from the player. Remember this is the pin player. Let's take this and search
for the ad overlapped weapon. Go ahead and add it here. The weapon is self just
like that and compile now. It's going to add
that overlap weapon to the array first here. Let's go ahead and
run the lot weapon. Let's strike from
here and search for a lot weapon. The weapon here. Actually, we don't need
it because remember now we added it to this array. Instead of just taking
it from here to here, we can now use this
array down here. We actually don't need this pin. If you click on this
pin, remove it. Also click up here and
remove it, just like that. And for this one to remove it, hold Alt and click on
it and it will remove, or you can click up here
and refresh all nodes that will also remove
these red era pins. Now you're looting the weapon. It's going to go through here. Now, before you add it directly, let's first check something. Let's take this
overlapped weapons First, let's ask if this
is empty or not. Because if it's empty,
we don't want to loot. Let's strike from here
and say is empty. Let's say it is not empty. If it is not empty,
we are going to O. We can drag from here. And write a branch and go
out and connected. Now if it is not empty,
we are going to loot. All right, what is the
weapon we are looting, We can drag from here and
say gets and take this one. We're simply just
getting the first item that is inside of the
overlap weapons array, Getting just the one
in the index, zero. So the first weapon
that is inside of here, let us connect it with
the overlap weapon. Now we're adding this
weapon to the inventory. Then it's going to go here, add it to the inventory, It's going to set it
to the loot weapon. We're going to check
if we're unarmed, If we are, we are going to
set the equipped weapon. Now remember to remove
overlap weapon, the one you're adding right now. Remember to remove
it from the array, else it will stay here forever. You have to take this array now. Then after doing this, maybe we can take
the overlap weapons. We can say remove item and
go ahead and connect it. Then remember to take
this one you just added. You can go ahead and
connect it up here instead. Again, double click to make a rear route node and just make it another level
with the other ones. Now we're remembering to
remove it from the array. It will stay here forever and you will have
box in your game. Okay, so now we're removing that overlap item from the array because now we added it to the inventory and everything is finished, so we removed it. Now remember this function here, this event here, is only running once,
whenever you overlap. It's running the lot weapon
event as you can see here. When we finish,
we stop the code. What if you actually have ten weapons in the
overlapped weapons? You need to keep running this lot weapon
until it is empty. And when it is empty it
will not do anything. You have to keep
running this event to check if you have
more overlapped items. Because it keeps checking if it is empty or not to run it. Again, up here, let's
make a new event. And I'm going to call it, let's strike from
here, a custom event. Let's call this one, check
for overlapped weapons. Going to check for more
overlapped weapons. This one we can take
and run down here. Check for overlapped weapons. When we are finished
adding the weapon, we are taking this check for overlapped weapons and
we're running it again. And then the code here will run again and check if
this is empty or not. If it is not empty, it is going again to take
that new weapon. Keep adding them to the
inventory as we can. However, if it is empty, we are going to do nothing. All right, a problem
we have right now is what if the player overlaps
with multiple weapons? Because every time you collide with a weapon
and you can loot it, it's going to add to
this overlap weapon. And it's going to
actually run this again even though we
are in the middle of the code and this will bug out the game every time you
overlap with something. This will run the
whole thing and it will actually also
activate all of this. Instead, let's put
some a barrier. This only runs once. And what you can do is drag
from here and say do once. This node makes sure that
this is only ran once, even though I overlap
with multiple weapons. It's not going to
repeat this code here. It's actually going
to repeat this code, it's going to add to this. But this part of the code is
not going to get repeated. It's actually going
to do it once only. And we can control when
it should do it again. We only want to do this once, even though we overlap with
maybe like 100 weapons. We only do this once
because remember we are doing like an infinite loop until this is not empty
anymore and we stop the code. We don't really need to
love it from here as well. Okay, do once. When can we reset this? The reset means I'm only
going to do this code once. You tell me when I can reset, so I can run this code again. The reset, let's drag from here and make
a new custom event. Let's call it can
lot weapon again. I can loot the weapon again whenever I stop
looting over here. When this is empty,
the overlapped weapon. Whenever this is empty, we can drag from here and
say can loot weapon again. We can run this code again
because it has stopped. And I'm going to drag a bit from here and make some space
and organize this. All right, so now this
is more organized. So let us go in, compile, and let us also compile
here, save everything. Let us now try to
click on play and see what happens.
Select Terrorist. I actually let me just
copy these weapons to all of this point
points so I don't have to keep running
to that spot again. Just copying a couple of times
and placing them around. Select terrorist
and let's walk into it now nothing's happening. We probably made a buck here it is,
overlapping, probably. But how you can do it is you
can drag from one of them, for example, this
server overlap, and write print string. That's how you debug your
code if you have a bug. I don't want to remove
this from the video because I want to show
you how to debug as well. You connect this print string
and you click on Play. Whenever it prints the string, as you can see, it's actually
printing the string. This means this part of
the code is working. Nothing is wrong here.
It's going through. Yeah, I think it's here. I forgot to make
this size to fit. Maybe let's try to play
it again and test it out. And that was the problem. I didn't make this size to fit. And what that means
is because for array, when you create them, you actually have to drag
from here and say resize. And then you have
to tell the engine what size is this array. For example, I will
give it 20 slots. Now with these 20 slots, I can now add items. You have to do
this, for example, in the Begin play or
something like that. However, with size to fit, it tells it that you can
automatically create a new slot. That is fine. I don't mind
how long this array is. That what you're doing here, size to fit was the problem. Now if you have problems, again, drag from here, write a print string, see if the string prints
to the screen. If it does, there's probably
something else wrong. Again, remember, you can
print values as well to see if it is actually added into this overlapped
weapons array and so on. But for now, it seems to work. Let's click on Play. If you
want to check it better, you can also click
on the spring, make it, for example, 600. Just so I can see my character. Let's try to lot again. Now you can see it's on my
weapon or on my hand and back. I'm just going to do this a couple of times just
to make sure that everything is working correctly
and it seems to work. So you can see that
fix the problem, because right now it keeps
looping through all of this. It makes sure that it goes
through the overlap weapons array before it stops and we
can loot the weapons again. So it's making sure that
everything is looted. And as you can
see, even though I overlap with multiple
weapons at once, it is working correctly. The rifle is in my hand and the pistol is at
the side of my leg. Right? So now that we are
finished with this logic, go ahead and save everything, and let us move on
to the next one.
99. 8.14 Creating the Weapon Structure: Okay, with this game, I want to show you
everything that we do when we develop a game, even though it is advanced. In this lesson, we are going to create a
weapon structure. It is a lot better than keep creating variables
for the weapons. Before this gets too big, let's actually start
creating the structure. Now I can try to show you and you'll understand
a lot in the blueprints. Let's right click and
make a new folder. Let's call this one Structures.
And right click again, set the color to
this color here, just like before
Inside of this folder. Let's right click
and go to Blueprint. We have something
called a structure. Click on it and I'm
going to call it ST as a prefix for structure. Let's call it weapon info. This structure contains
the info for the weapons. Now when you open
up a structure, the only thing you do inside
of here is add variables. If you add a variable, you can choose what this variable
should be called. You can choose the
type, just like here in the blueprint where you
create a new variable. Same thing. Now inside of
the structure, you can have weapons info all together here. You can add multiple
variables inside of here and you can have all of the info for the
weapon inside of here. For example, how fast
can the weapon shoot, what is the name of the weapon, and all of these
things that you want. For example, the thumbnail for the weapon when you
add it to the inventory, what should it cost in the
shop when you buy the weapon? You can have a coin value
or $1 value and so on. All the information for the
weapon can be inside of. Here you can see you can gather all the variables
inside of a structure. Don't have to make 100 variables inside of this blueprint, they're actually containing
it inside of the structure. Let us go ahead and
start making one. I'm going to delete all of them. The first one here I'm
going to call name. I need a name for my weapon. And I'm going to change it to
the type of string because string is just some
a text we can write. Now very important, the difference between
a string and at a text can be localized or translated to
different languages. For example, if I want my game
to be German or Japanese, or Chinese, in the future
I have to select text. For example, if I want
to translate the name of the weapon, if
you choose String, you cannot translate
it in the future. Make sure if you want
a game that can be translated because you want to translate it in the future. Go ahead and select text. However, I'm going to select string weapon names
like an AK 47 or 44. Even though I change it
to different languages, it's not really
going to translate. I mean, what is AK 47 called in different languages?
It's the same name. That is why I choose a
string instead of a text, even though I want to translate
my game in the future string for the
name. Then remember we added this weapon
type as well. This weapon type we can actually have inside of the
structure as well. I can just call it type, you can call it weapon
type, that is fine. Call it whatever you want to make it more visible
for you over here. Let's change it to weapon type. Remember, we made
that enumeration weapon type for example. We can also add a new
one and call class. A class is if you search for weapon base and take it here, select this class,
reference A class is you can spawn a new
weapon from this one. Maybe we need it, maybe not. It's always nice to have a class for whatever
game you make, because maybe in the
future you need to spawn that weapon back
again into the world. Always nice to have
this class here. Now we have a structure. It is small, but it is nice
and we created one later on. You can add, for example, shooting speed for that weapon. And then you can
select a float for the number of how
fast it can shoot. Later on you can say
reload speed and so on. So you can see you can add a lot of information
about this weapon. Maybe you want to add like a shop value or you want to add like description, or you want to add a thumbnail
for the inventory. You can add a lot of things. But for now, let's
just add these. And I'm going to add more to the structure later
when we need it. Now that we have
created this structure, we can move on to
creating a data table. I will tell you in the next
lesson what a data table is, but for now, awesome, you created a structure,
and let us move on.
100. 8.15 Creating the Weapon Data Table: In this lesson, we are going to create a weapon data table. To create a data table, you have to be in Google
Drive or Google Sheets, or if you have Excel you
can use that as well. I'm using Google Sheets. Go ahead and make a Google
account if you don't have one. And then inside of here we are clicking up here
and going to my drive. Inside of your drive,
I just made a folder inside of here to stay
structured inside of here. When you are inside of Google, you can write, click, make a new Google sheet. Click here, and then
it's going to make one, and I'm going to call this
one up here, data tables. I'm going to make a space
here, inside of here. I'm just going to
organize this a bit. I'm going to click Control
A to select all of it. I'm going to click up
here, Align its center. Click up here, Align its center. Click up here, select
the text wrap. Then I'm going to change
the phone to this one. Up here for this row, I'm going to click on this bold. Again, control to select it all. I'm going to just make
everything wider like this, and this is just preference. Okay, now we are inside
of Google sheets. And what a data table is, is we can write all of those values from a structure
inside of a data table. So people who cannot program, they can actually use
this data table and they can modify information about
your game, for example. Let's begin here and you
can see what I mean. We created this structure
here with the name variable. What we can do inside of
this data table to write, you have to write
those variables exactly as what you
have wrote them. Inside of a structure. For the name, we can write name, and then we have the type, and then we have the class. This is what we have inside
of a structure right Now, remember to write it exactly how you wrote it here
inside of the structure. Else you will get box, write it here for the
name of the item. For example, the first one
we have an AK 47 K 47. The next one we have one if you see here in the
blueprints weapon, this is what you have. And then you have a pistol. You can also give it a name. However, my pistol
is called pistol. I don't really have
a name for it. Now you have to write
the type of this weapon. Remember inside of
the enumeration you made this weapon type. Inside of the
structure, you can also see what you selected
weapon type. Now for this weapon type, you have to write it exactly as the weapon types that
you have written here. Else you will get box
inside of a data table. You have to write things exactly as what you
did inside of here. For the weapon type,
we can have a rifle. This AK is a rifle, the four is a rifle. The pistol is simply the
type of pistol like this. For the class, we have
to do something else. Let's create the
data table first because this one I
can't get a reference to unless I actually have the data table inside
of the blueprints. Let's make a new folder. Let's call this one Data
tables inside of this folder. Again, let's right click Set the Color inside of this folder. Let's right click, I believe it's inside of Michelaneous,
not blueprint. Here it is, the data table. Go ahead and created.
Now it tells you, which structure do you
want to create it from? I want to create it
from the weapon Info. Go ahead and click. Okay.
Now let's call it DT table, and again
call it Weapon Info. I usually just call it the
same as the structure. However, DT for prefix, because this is a data table. If I open up this data table, you can see it is
empty right now. If you click on
the plus, a pure, you add a new entry
for the data table. You can see here, you
can give it a name. For example, AK 47. I can make it into a
rifle and the class is this BPAK 47 that we created. Here you can see we
have the information now instead of a data table, we can actually extract this information and
use it in our game. Let us do this from our data table here
from Google Sheet. I'm going to click on this one, this entry that you
created right now, and just select one
of those by random. For example, this PPK 47. Then you can write, click now
on this one and say copy, because now you're
copying this reference. Here you can see this
is how we actually need to write it inside
of your Google sheet. We already did this. We wrote the name here
correctly, like this. We wrote the type like
this rifle, for example. For the class, you have
to write it like this as well if I just control
V inside of here. Remember to write,
Click over here, copy it, control
V. Inside of here. I'm just going to
make it log so I can actually see what I'm
doing. Just like this. Okay, in here, this
is how you do it. Now you copy this one and
paste it to the other ones. Remember, instead of
an AK 47, this is 44. So you have to write it
exactly as the reference. I'm referencing to this PP
44. I can go back here. These are the correct
folders, blueprints, weapons. And I just need to
change this 1141. The last one is the
pistol called BP pistol. I write P pistol
pistol here as well. Okay. Now I have that
information correctly. What I need to do
now is click on file to download and select CSV. This is the format
we need to use. Now if I open up my
downloads folder over here, let's call it T for data table. I'm going to call it the
same name as inside of here, so it can be imported. Remember to call the same
name, ET Weapon Info. Now you can click and
drag it into here. If you click and
drag it into here, it says Expected
column Name not found. I'm not sure what I call
it. I called it name. This is because we
actually need column here. We need to right click and add one column to the
left and call it ID. For some reason
it creates an ID, we need that as well. What I usually do is just copy all the names and paste
them inside of here. It's actually going to extract
information from the ID. And when you extract, for
example, this ID here, it knows the name, the type, this class, and so on. So it knows all of
this information. You actually need an ID first. Okay, so let us now try to
download it again as a CSV. Let's go back to here. I'm going to copy this name. I'm going to delete the old one. And for the new one I'm going
to rename it like that. And now I can drag it into here. Now you can see it
works correctly. So we need that ID. Now you can see when I import
my data table, it automatically fills in
all of the information. So I, I click on the first one, you can see it has the AK 47 the rifle and it is set
to the correct blueprint. And the other one, for
example in four a one you can also see the correct
information is here as well. So you can see how
really nice it is for people who can't program. They can actually
just go in here, change the type of the weapon, or they can change the
name of the weapon. And the only thing you have to do now is just click on file. Download that folder or file and just drag
it into your game. And it will change
all the values. Inside of here, you can imagine you can have a
shop value and you can have coins cost for the weapon if you buy
it from the shop. And the game designer
can just come here and edit all of those values
inside the Excel sheet. You can even make formulas
inside of here and calculate. Then you can just click Download
and you can just drag it into here and it will change all of the coin values
inside of here. You don't have to do it
inside of the engine. Really nice to use a data table, especially for people
who can't program. They can come in here and
change it from the data table, now we have it inside of here. The next thing is we need
to use a function library. Let us do that in
the next lesson.
101. 8.16 Using the Function Library: The final step before we can use this data table is if we
create a function library. A function library
simply just as the name says a library and inside
of it is functions. Let's just right click here
again, make a new folder. Let me call it libraries. And let's change the color
of it inside of this folder. Let's right click
Go to Blueprints and use this one called a
blueprint function library. You can see we've already
used a blueprint cow. We're using the
blueprint library. We used the blueprint interface. The macro library is just
like the function library. We've used the enumeration and we've also used
the structure. You can see we've actually gone through most of these
blueprint classes. Really nice that
you got through all of this and you're
getting the experience. Let's create a blueprint
function library. And let me call it
BP function library because I only have
one in my game. Let's open up this
function library inside of a function library. You can make functions and
you can make them here. The good thing about
a function library is that you can use the
functions globally. If I make a function here, let's, let me just call it, for example, random
if I compile. Now if I go to my player
blueprint for example. And I write click and say random, that's what I called it. You can see, I can now see functions from a
function library. It doesn't matter
where I write this. If I open up the game
mode and I write, let me get out of
this one, actually, let me get to the event
graph and say random. You can see, I can see the function inside of
the function library. Whatever function
you make inside of here can be seen globally
through all of the blueprints. Just keep in mind, don't just functions inside
of here for no reason, because it takes up performance. If this library is huge, the only thing you should
use it for is if you have a function that is used
in many blueprints. For example, you're
getting the weapon info, You might use that
in the player base. You might use that
in the game mode. You might use that in
the play controller. If you have a function
that you are going to use across
multiple blueprints, then go ahead and
make it inside of a function library so you don't have to make
the same function again and again in
each blueprint. But specific functions don't create them inside of
a function library. This is only meant for
functions that you are going to be using a lot of times
across blueprints. For example, for this
one we're going to call it Get info. We're getting the
weapons information. I'm also going to tick pure, pure just makes it
that green function. If I compile and you can see if I go to the player
base for example and say get weapon info, you can see it got green. And the reason it got green
is because I clicked on pure. And here you can see it. It actually gets like
those green functions if you have created one. This one for example, for this one we're getting
the controller, you can see it is green because it's simply getting information. If you set information then you need these pins
here and they are blue. These are set functions and
these are get functions. They're simply
getting information without modifying anything. This is what we want
to do. We want to get our weapon info. We set it to pure
because we're not modifying anything
inside of here. The main function that we
need to use inside of here, if you right click it, is yet data table row. This one down here,
yet data table row. This is the main function
that we need to use. And we need to select
our data table. So we need to get information
from T weapon info. Now you have to tell
it what information do you want to get from it? Now this needs to be dynamic, depending on what you're
doing inside of the game. Let's just make it, and I can explain it later for
the weapon info. Now let's create a variable and let's call it weapon name. And I'm going to make
it into a string. I'm going to take
this and say replace. And use this function
called replace. Now the reason I use this is if you inside of your
data table here, let's say you have a
name, for example, let's say you have a
weapon called four in one. Let's just pretend
that this is a weapon. You have spaces between
your name for the ID. Now when you create something
inside of a data table, it actually removes the spaces. If you open up the data table, let's say you import
this one in space one a. If you import that into here, it would actually
remove the space and it would just write one
A without a space. What I do usually here to remove all the spaces from here, when you upload them, I take the weapon name
here in the from. I press space, make
sure to add one space. The two can just be empty. Nothing inside of
here, that is it. What this is simply
doing is it's taking all the spaces
from these names. Let's say it's this one. It's taking the space and it's
replacing it with nothing, meaning that you're actually deleting the space like this. Then it will find the correct ID inside of this data table. Because this data table automatically removes these
spaces when you import them. When you search for a name
like with this space, it will give you an era. We're removing all the spaces, and now we're going to
plug that into here. It's automatically
going to convert the string into a name variable. Then we can right from
here and say return. You can connect this
output into the return and you can call this
one weapon info. Okay, now we are finished
and I need to explain the whole process to you because this might be a bit confusing. What we're doing here now is
we can now say, for example, here inside of the
player base we can say get weapon info. And we can call that function we made in the
functions library. We're getting that info. Now we need to plug
in a weapon name. Let's say for example, we're going to do that in
the next lesson. But let's say for example, I plugged in the name AK 47. It's going to take that name. It's going to go inside of this function into
the function library. It's going to take
the name here, going to remove all
spaces, if there are any. It's going to put that AK 47 that I wrote here
into the row name, which means it looks
here in the name, it looks for the AK 47, it looks for this one. Now it knows we are
talking about this row. It knows the name, the type, the class, and so on. So you can drag from
here and say break, you can break structures. And now you can see all
the variables since it takes the information
from this data table, now knows the name of the AK 47, it knows what type of weapon
it is, what class it is, because it's taking all of that information from
this data table. That's how you use it
and now we need to actually make those
weapon names. List this for now. Let's compile and save,
and let us move on.
102. 8.17 Adding the Weapon Name: Now what we need to do,
let's close everything. Let's go back to the weapons, and let's go to the weapon base. Now inside of here, let's make a new
variable called, let's call it weapon name. Let us give it the string type. So it's just a text. And if you compile, you can see, you can write something here
now for the weapon name. Since you create this variable, remember since you
created inside of the parent blueprint class, all of the children will
inherit this variable. If you open up the Q 47, you can see in the
class defaults that you can now
write a weapon name. You can make it specific
for each weapon. Now you add the variable inside of the weapon
base and then you can edit this variable to be something specific
for each child. The weapon name for the AK 47
is just K 47 for the four. I can see it here. I don't
have to click up here. The weapon name for
the four is 41. Let's close that down as well. For the pistol, it
is just pistol. I'm actually going
to remember to compile up here just like that. Save everything. Now you have written the weapon
name for each of them. We need that weapon name, extract the correct info from the data table because if
the weapon name is pistol, we're going to plug in
that weapon name and it's going to extract all of
this information from here. Okay, let's close it down now. Now what we can do, for example, is we can go to the player.
Let's go to the player. I'm just going to show you you shouldn't really follow here. I actually just want to
give you an example. We have for example,
this looted weapon. This looted weapon I
can drag from here. And now I can say name and take this weapon name variable. From that I can say
yet weapon info. That is the function library. Now we can actually
plug that in. Let's say I walked
over an AK 47. I walked over it and now I can actually extract the
information from it if I just print a string to my screen and I
connect it down here. Let's take this and say
break this structure. Let's just print out the
name of this weapon. If just accomp, I walk over, actually I need to choose, so if I choose terrorists
and I walk over this pistol, it's going to print out pistol. If I walk over this in four, it's going to print out in 41. So you can see it is now
correctly extracting information depending on
what the weapon name is. Let me delete this for now. Remember very
important when you add this variable to
the parent class, remember that you have
to go into each of the children and change
the value of this. Okay, go ahead and save
everything and let us move on.
103. 8.18 Replacing the WeaponType Variable: All right, in this
lesson I'm going to replace the weapon
type variable. If we go to the weapon base, remember we made this weapon
type and we're using it here to check if the player has the weapon in the
inventory already. This weapon type, we already made this inside
of the structure. If you go to the structure,
remember we made this type. Now we don't need these extra variables
to be laying around. We can actually just use our
structure to replace this. What we can do now,
instead of all of this, instead of taking the
weapon type like this, we can now say get weapon info. We can take this here, plug
in the name like that. Remember we are inside
of the weapon base. We already have the
name already here. Now to get the weapon type, we have to drag and say
break and we can break this. What you can do,
you can also write click here and say split struct. And you can get those like this. However I like to just write break and having them
out here instead. Now that is just the preference. I can now take this type, this is the weapon type, and
I can plug it into here. Now you can see this
is the same thing. Now I can actually delete this weapon type variable to hide those pins that
you are not using. To make it look better, you
can click on it and press hide unconnected pins.
It looks like this. Okay, I have to organize
this a bit later, but let's just let it be
here for this weapon type. Here I'm dragging from this
and saying name again. Get the weapon name,
get weapon info. And then you can break this. Then you can plug in
the type over here, instead, we can
delete this as well. Now you can see we're not
using this variable anymore. We have all of the information for the weapon
inside of this one. Okay, I'm going to
organize this a bit. All right, now it is a
bit more organized now to take a look at if you have other references of
this weapon type. Instead of looking for it, I know a fact that we also
used it in the player base. But if you don't remember, let's say you come in
here one month later and you don't remember
where you used it. Elsewhere, you can see if
you try to delete it now, it says the variable weapon type is already used. You
want to delete it? I am pressing no, because we're still using it. Right click here and
say find references. Now this down here
is only finding the references within
this blueprint. But if you click on
this small icon, it's going to find it
in all blueprints. It's going to search in
all of the blueprints. And you can see it's used
in the BP player base. If you double click
on the variable here, it takes us to and we used
it here in the loot weapon where we set the
equipped weapon type. Instead of doing this again, let's take this looted weapon. Let's say get weapon in. Actually get weapon info. Get name, get weapon name. Instead of doing all of
this again and again, I'm actually just going to go
over to the weapon base and I'm going to copy
this and this here. So the Git weapon info
and the brake structure. So I can just paste
it in here and I can plug this into here,
it's a bit faster. And you can now plug
the type in here. And you can delete
this again just to try to make it as
organized as possible. But you can see it is very
long now compared to before. However, again, you have all the information contained
within this structure, so it's going to be a lot
more cleaner for you. All right, so now we
have that and let us open up my references again. I'm going to double
click on this one now. And I'm using it here
when I want to switch or attach the actor
to my mesh component. Again, just like before. Let's just copy all
of this because we were actually just using
this looted weapon. Again, I'm going
to go back here, rep looted and I'm going
to delete this and make space past this and
then connect it here. And then just push them back. The same thing down here.
Delete them and connect it. Just like that. Okay, now you have it compile,
save everything. And that should be
all you can see. You don't have more references.
This was all of them. If you go back now to the
weapon base and press delete, it's going to
automatically delete it because you are not
using it anymore. Now you can see we
replaced all of them. Blueprints are getting
cleaner in the future. We don't have like ten
variables for the weapon. We have them all inside of our function function,
our structure. And from that structure, it's taking this information
from the data table. And we can always make
it longer later on. But for now, this is all
the information we need. Let us now save everything
and let us move on.
104. 8.19 Drop Weapon Input Action: Okay, before we do the
Lot functionality, like when you press a
button, for example. If I press E on a weapon on
the ground and I lot it, I think it's a lot better to
start with a drop weapon. Because if you're holding
a weapon in your hand, you need to drop it as well
when you loot the other one. Let's start with dropping
a weapon first before we lot it with a key
on the keyboard. Let us go to the input
here in the player folder. Go to Input right click. Actually, you can try to do
it yourself if you want. This is a good
moment for exercise. We already have done
a lot of those. You should be able to do it yourself. Try to do it yourself. If possible, try to create an input action or
dropping a weapon. And add it to the
input mapping context. And also add the event to
the player base as well. Now let's do it together here. Let's right go to Input
and select Input Action. Let's call this one
weapon. Let's open it up. Actually, we don't need to change anything inside of here. Let's go to the mapping context. Let's add a new mapping. Let's select the drop weapon. I'm going to drop the weapon with the G key on my keyboard, just like in counterstrike. Now you can use
anything else that is fine for the modifier. I'm going to click on Pressed, because you have to press
the button and it will play the code once it
doesn't span this. Okay, Now we have this.
Let's close it down. Let's go to the
player, player base. And inside of here, let's
go to the event graph. Down here you can right click
and write the name again, just like what you did with
the input or the drop weapon. The right click and say a drop weapon and here is the
event that you need to use. Now we can code in the
drop weapon logic, let's save everything and let
us move on to the next one.
105. 8.20 Drop Weapon Logic: All right, so let's
get going here with the drop weapon logic. Now we need to know
which weapon do you want to drop
from the inventory. Now let's run it
through the server. Again, we need to run it through the server to prevent cheating. So I'm going to make
a new custom event called SRV Weapon. Let's run this on the
server and reliable. Let's run the server
one inside of here. Okay, so when I press the
G key to drop my weapon, it's going to go through
this custom event. Now we need to know what
weapon we are dropping. We're dropping the weapon we
are holding in our hands. We need to know which weapon is it that we are
holding in our hands. Right now, it's actually
this equipped weapon type. It knows if we are
holding a rifle, pistol or if we are unarmed
for this equipped weapon. I'm actually going to rename
it to make it sound better. It's not equipped weapon, it's equipped weapon type. We also need to
change the name here. Actually, set equipped weapon. It's set equipped weapon type. I'm also going to
do it down here, Set equipped weapon type. And the same thing here
for the variables. They are called equipped weapon type and equipped weapon type. Equipped weapon type. It's
more correct than before. Now we already know what the
equipped weapon type is. We need to find this
in the inventory. We need to take the
weapon inventory. And we can save for
each loop with break. And let us connect
it here again. Remember we made the
name in the last lesson. Let's take this and say name variable and take
this get weapon name. Now we're getting the weapon
name of the item right now. The weapon here. Then from this weapon name again
get weapon info. The structure here,
let's break it. The thing that we're interested in is we're
interested in getting the type of weapon
right now from the inventory that we
are looping through, if this type that we are
looking at currently in the inventory is equal,
equal enumeration, if it is equal to the
equipped weapon type, this means that we
have this weapon in the inventory and it is the
one we are holding right now. If that is the case, we want to drop this
weapon right now. Okay, If it is the fact that the weapon I
am looking right now in my inventory is the same as the equipped weapon
type right now. This means that
this weapon here is actually the one we want to
remove from the inventory. If that is correct,
let's right click here and promote
this to a variable. I'm going to call this
one weapon to drop. And we can now
connect it to here. Just like before you
made this one where, let's see if we can find it. You made this one loot weapon. When you loot the
weapon, you remove the collision here from
the notify function. The same thing we actually need to do down here with
the drop weapon, because we have to enable
the physics again, remember we had simulate physics on the weapons from
the beginning. We actually have to do the
same thing here for this one. Let's add some rear route
notes for this weapon to drop. Let's click on it and
say, let's compile. Let's do that function
in the next lesson. But for now, let's
continue here, we're dropping the weapon. And also remember to remove
it from the inventory. I'm going to take this
inventory here and I'm going to paste it here and
say remove item. Let us say remove
item like that. Let us now select the
item we want to remove. It's this weapon item
or inventory item. Now we are removing it from the inventory because
if you don't do that, it is actually still
in the inventory. If you drop it on the ground, then we have to
remember to update the equipped weapon
type as well. Drag from here and say
set equip weapon type. For now, let's just
set it to unarmed. We can modify it later
if you have a pistol or whatever you have right now
when you drop the weapon, let's just set it to unarmed. And that was it. Now you're
actually dropping the weapon. Now we are finished
with this one. However, we still need to make
this rep, notify function. Let us do that in
the next lesson.
106. 8.21 Drop Weapon Rep Notify: Right, let's open up the
weapon to drop rep, notify. If you don't remember
what we did, you can always go back
to the alluded weapon. And here what you did is
removed the simulate physics, you removed the collision for the weapon because
now you're holding it in your hand and you removed the collision sphere
collision as well. You can opposite of this, if we go
back to our weapon dropped, we need to first detach
the weapon from the hand. Because remember in
the looted weapons, you attached this
to the character. What we need to do first is
take this weapon to drop. We need to say detach. And you can select this one. Detach from actor. Now you're detaching
this thing here, this weapon to drop
from this actor. Let's keep the location, rotation and the scale to keep world wherever it is
right now in the world. It just keeps the
location and so on. Just to the opposite
of the looted weapons. Let's take this and say let's first set collision because we can't
simulate physics. If you actually don't set
the collision correctly, let's set the collision enabled, It's
actually the weapon. If you go back, if
you don't remember, always go back to
the weapon base, check what needs collision. Remember it's the weapon that
needs this collision here. We actually need to take this
and take the weapon first, the weapon variable, get that. Then we can say set collision enabled here. Let's connect it. The collision, remember
was physics only. We don't need query for this
mesh here, physics only. And we also need to
simulate physics. And we do that on the weapon. Remember, if you go back
and click on the weapon, it is here that you
simulate physics. It is not in the class defaults. You have to drag from the weapon and say simulate physics. And select that God and
connect it and enable physics. Go ahead and make some reroute
notes to make it nicer. Okay, now we simulate physics on and we also have
some collision enabled. Now remember you also
disabled the collision. If I go back to looted weapon, you also disabled the collision
for the collision sphere, you need to take this one and you need to take the
collision sphere variable. You go down at the bottom here, take the collision
sphere and then again set a collision enabled
and go out and selected. And yeah, just like that. Now you have to set the
collision to query only because the collision is actually query only for the collision sphere. You can see it here. Query only, we need to set it to query only. I believe that is the only
thing that we had to do. Let's test it out. Let's
see if everything works. If we have some box
we need to fix them, let's play as the terrorist. Now, if I loud, for example
the AK and I click on G, drop the weapon, you can see
it is dropped on the ground. Just like that. Awesome. Let's actually play
as the first person, so I can see it better. I'm going to click
on my spring arm for the player base
and set it to zero. Let us play as first person. Now let's take this K.
Now I'm holding it, I press on to drop it. Now you can see
it's on the ground. Awesome. Let's try to take this one here and
drop it on the ground. Now you can see we have a buck. I don't think it is invisible because you can't
see it on my back. I'm wondering what is happening. Let's take the spring.
I'm going to set it to 600 to see what is happening. And it's actually
only the M four. So you can see the pistol
is working correctly. The K is working
correctly as well. Nothing is happening
but the M four. I am loading it correctly
the first time. However, if I drop it
and I walk into it, oh, it's actually under me. You can see it on my feet. It's there. Let's actually
fix that quickly. I think we need to
reset the location. If you go to the rep notify
for the looted weapon. Whenever you loot a
weapon, you have to reset, transform. Let's actually
do it here after we attach the component
to the root component. What I can do here is I can take the weapon and I
can just say reset. And you can see something called reset,
relative transform. It's going to reset the transform of this weapon here inside of the blueprint. Because it is not enough that we reattach it to the
root component, we also have to reset
the transform of it. Let's compile and play and
see if that fixes our issue. I take them four, I drop it. I take them four again, and now you can see
it's working correctly. If I go back with my spring
arm, set it to zero. Play now as a terrorist. I can now take this in
four and I can drop it. Can take it again.
I can drop it. You can see now it is
working correctly. It's a good mechanic that we
actually need to go out of the collision sphere first
before we can loot again. Because you can
imagine if you drop it and you don't have
this functionality, you keep looting the weapon. When you drop it beneath you, you have to walk out
and the walk in again and everything is working
perfectly, all right. The final thing we
actually forgot as well, or I forgot, is to
break the loop. Because if you find
the weapon here, we actually need
to break the loop. We need to take this and run it all
the way back to break. And let's double click to make reroute nodes to
make it look better. Because now if we
find the weapon, we need to stop the loop. We don't need to loop through more because we already
found the results. We have to break it
here through the loop. That will make it
more optimized. Now let's compile and
let's click Play. And play the chara just to test if everything is
working correctly. Now we can see everything is working fine with
the pistol as well. Everything is working
fine as well. Now sometimes you
get an error if you drop the weapon and
you don't have anything actually over here. Instead of just keeping
dropping the weapon, we have to check if you
actually have a weapon or not. We need to take this equipped weapon type and we need to say, is it equal to unarmed? Actually, we can say
is it not equal? That will be a lot better. If it is not equal to unarmed, you can go ahead and
drop the weapon. If it is unarmed, you don't have
anything in your hand and it doesn't make sense
to drop the weapon. If it is not unarmed, you can go ahead and
drop the weapon, and that will make
it a lot better. And also remove
some box that you might have later on if
you drop the weapon. And you can see now everything is working as it's supposed to. However, don't get too tricked because now let's try to
play it as the client. Now if I played as the
client as a terrorist, now if I walk into a weapon, you can see it's
loted correctly. And if I click on G
to drop the weapon, okay, everything is nice. However, if I go
to loot it again, you can see I am holding something and I'm actually
holding the weapon. However, it is still
on the ground. What is happening? This bug is happening because
rep notifies. If I go to the player
base, rep notifies only being called if
the value changes. For example, here, if
I lot the weapon here, let's say I allude the
weapon. Okay, nice. I set this variable, this rep notify it
is set to pistol. Now if I drop it, let's go back to the game. If I drop it here, if I allot the four, okay, nice drop it. If I go to the
pistol works okay. You can see I can do this. However, I can't lot the
same weapon two times. It is going to, But
I walk into it, you can see it is
bugging out and something is weird.
This is because if it is the same value that is being fed into here
as the last time, it is actually not going to
call a rep notify function. The rep notify function
will not be called if it is the same exact value
you have plugged into here. And this goes with everything. For example, let's say you had a vector variable and
you're setting some, Let's say you set
the weapon location. Let's say you're setting
the weapon location and you're actually running
it through a rep notify. Let's say the weapon
location needs to be 000 and you plugged it in here. Now the next time
you run this and the weapon location is
the same exact thing, it's actually not going to run this rep notified function. The rep notified
function will only run if you are
changing the value. Let's delete this one here. Let's delete this on rep weapon location
that we just made. What we need to do here is
we need to change this. Let us actually do that
in the next lesson.
107. 8.22 Resetting the Rep Notify Value: All right, so now let us reset the rep notify function
so it works correctly. So what we can do
here now you are running this drop weapon. You are running it correctly. Now let us reset it here. When the loop is complete
and all of this is finished, let's go ahead and
reset this value. So the next time we set it, even though it's the same value, it's going to run this notify, because we have reset
it before that. Down here what I
need to do is let's just take this weapon drop. Let's take that here.
It's down here, the weapon to drop.
Let's take it out here. Let us connect to the complete. Actually, that is the
only thing you need to do if you don't plug
anything into this value, it's going to throw out all of the information
that is inside of it, and that will reset
this variable here. What we can do now, there
will be a small bug, and you will probably
see that as well. Now if we click on
Play, I take this, I drop it, you can see
it is now in the air. We are picking it up correctly. However, it is still in the air. This is, let me just
close this down. This is because you're actually still running this
function here. And at the same time you are
resetting this variable. We need to actually
give it a small delay to give it a chance to
play this notify function. Before we reset it. Let me
just delay by something very small like 0.1 and then we
can reset this variable. Let's compile, let's play
and see what happens. Now, if I play as a terrorist, I pick it up and I drop it. See it works correctly.
If I pick it up again. Now there is still a
mistake here and we have to do the same thing
for the lute weapon. Now it says X non trying to read the property weapon to
drop detached from actor. Now what we need to do here
because when we run this, remember when you run
a rep notify function, you are changing the
value even though you're putting zero into this. Even though if you're emptying, you're still changing the value. And it will actually
run all of this. Again, the way we can do this is we can right click
this weapon to drop and we can convert it into
a validated get and we can connect it here
whenever it is valid. We can go ahead and
connect and run this code whenever
it is not valid. Meaning this here, whenever we don't plug anything into here, this will make this not valid and we don't do anything
if it is not valid. Let's compile and see if that
actually fixes the issues. Before we continue,
I can drop it here, go into it, and you
can see it is still invisible and we have to
empty the other variable. However, you can see we
don't get any errors, so these are fixed.
Let's go back. Now, let's go up to
the looted weapons. This one we need
to reset as well. Remember, this is also set to the same variable because you're looting the pistol
over and over again. Now for this one, what we can
do here, remember we have, this is not empty, so we're checking if the
overlap weapons array is empty or not. If it is empty, we set the loot weapon
again, over here. Again, I can say delay by 0.1 second to give
this a chance to play. Whenever that is done, I can take this
looted weapon and set it like this and empty
the values inside of here. Now remember to go into
this again and make sure that this is valid
whenever you do it, let's right click convert to a validated get,
just like before. Only when it is valid. We want to run the code
because if it is not valid, we don't want to do anything. Let us compile, save everything. Let me click on play now,
and that should work. If I play as a terrorist, I drop the weapon,
I looted again. You can see it is
looted correctly. If I drop it lot again, you can see now it is
working perfectly. It is correct. Now it
works as the client. And if I play the
game listen server. So if I play as the server
and as the client as well. Now here's my server. I'm going to spawn. And here is my client. I'm going to spawn as well. I alluded the pistol as my client and you can see
it here on the server, and if the server lots K for example, you
can see it as well. If I drop it I alluded, you can see you can see it on both the screens
here as the client, I can drop this lot, everything is working correctly. If I alluded to the info, it lots correctly as well. Okay. Everything is
correct, looking nice. Now, there is a small problem. If I go to the player and
the player drops the weapon, you can see I am now
holding the weapon. However, as the player, as the client I
cannot see anything. But as the server you can
see, I can see the K. Now what is happening? You might be thinking this
might be a replication issue, because as the server I can
see the correct information, but as the client I cannot
see the correct information. This might be a
replication issue. Because you can
see on the ground, I can actually see the weapon. There is something wrong. Now, I would not suspect
a replication issue. I can actually see the
weapon on the ground. If it was a replication issue, the weapon should be on my back. Because then it thinks
that I have something in my hand already and it
would put my Ak on my back. But for some weird reason, the weapon is actually
on the ground and here it is in my hand. The problem is most likely that you are
looting the weapon. As the other player, you're actually looting
the weapon before you have had a
chance to play all of this code in the drop weapon. Let us actually do that
in the next lesson. Let's fix this issue.
108. 8.23 Weapon Interaction Boolean: To make sure that we can't
interact with this weapon until this has actually run through and this
has been reset. Then we actually
want to interact with the weapon because right now the players are interacting
with it way too fast. Let's go to the weapon base. And inside of here I'm going
to make a new variable. Let's call it, can
be interacted. Let's make it just
into a bullion. Now let's go to the player base. Let's actually make it by default that you can
interact with it. If we just click
on this bullion, I am going to set it to true default. What we can do now
is go to the player Now, I don't want them to
interact with it. Once we have actually found this weapon and we
want to drop it, I'm just going to
drag this away. Now we have this weapon. I'm just going to double here. And I can take from
here and say and be interacted with and we
can set it to be false. Now we don't need to replicate this and the reason is we're just running it
through the server. Sometimes you think sometimes
you're replicating stuff, sometimes you're not
replicating stuff. What do I actually
need to replicate If you need some variables that you're actually only using
during the server functions, these do not need
to be replicated. You're setting if this can
be interacted with or not. If you're only using this
information inside of the server functions to do some logic and the other players don't need to know about it, you actually don't
need to replicate it. However, if you want to
other stuff, for example, what weapon are you
equipping if you're using it here you can see
equipped weapon type. I'm actually using it here where the client also runs the code. Now if this is not replicated, then this will give an
era for the client. However, can be if I use it up here where
the client is as well, I have to replicate it. But since I'm only using it
in the logic of the server, then I actually don't
need to replicate it. It's like an internal
thing. You can save it now. Now I can't interact with
the weapon down here. Whenever it completes, I want to set my can be interacted
with to be true. Now we need to set
it before this one, because remember you are
deleting the variable. Before we delete the
variable, we need to use it. Let's take this and say
can be interacted with. And I'm going to set it to true because now we
can interact with it and then we want to delete this variable. You
don't want to make this here because you
delete the variable, so this one would be invalid. Now that is deleting it. Now what we need to
do, we need to go to the weapon base here. We need to also write here that if you can't
interact with it, don't do anything after the authority. Let's
strike from here. Remember, we did not
replicate this variable. If we write something here, it will give us an era
since we are writing it, after the switch has authority, so we're only using it
inside of the server, then it will be fine, we
don't need to replicate it. Let's take, this
can be interacted with and let's make a branch. Let's say, can this
be interacted with? If it can, go ahead
and run the code. If it can't, I'm going
to delay the code by, let's say 0.1 seconds. And then I'm going
to run this again. So I keep looping
through this code. I'm actually going to
organize this a bit more. So essentially what
I'm doing here is I keep looping
through the code to make sure that I can interact with my weapon before I do
some interaction code. So let me just try to organize this here,
let me push it down. So now what I'm
basically saying is go ahead and take a look and see if this can be
interacted with. If it can, nice
ahead run the code. If it can't, I'm going to loop or delay the
code by 0.1 second. And then I'm going
to go back and check if this can
be interacted with. I keep looping through
it and I'm waiting for this to be true because
whenever you drop the weapon, this will be true very quickly. So you won't even
notice this one. Don't worry, this
is not heavy on performance because this is
going to loop really quick. And it's not going
to run many times, because this one is going
to be true very fast. So this one is actually
not running many times. So don't worry about that. Let's try to click on
play now and see what happens if I play as the
terrorist maximize it. I loot something and I click on, you can see I'm actually
looting it instantly. And this is the problem
that we have right now. If I drop the weapon
really quick, I keep looting it because it's actually going here and checking if I can
interact with it, even though I am
the same player, the same player dropping the
weapon can interact with it. So this is something
we have to fix. However, right now
the code is working. We can only interact with it whenever this has run through. So we don't get any box
from it being invisible. So let's move on to
the next lesson.
109. 8.24 Removing Interaction from Dropping Player: All right, so now we need to write quite some code here
before this can work. Because we want
to make sure that the player dropping
the weapon right now, we want to make sure
that the player dropping this info is not
looting this info. Again, we only want the
other guy to loot the info. We don't want to interact
with it right away, else you keep looting it. We need to define
the dropped weapon. Let me go ahead and make
a new customer event. And let's call this one
set dropped weapon. And let's run it through
the server again. Server set dropped. We then we need to run this on the server
and being reliable and we need to run it through
the normal event here, set dropped weapon. Okay, down here, we simply just need to set this variable. I'm going to just click here, add a new variable. It is just the weapon base
because we need the weapon. Let's call this one
dropped weapon. Let's connect it
up here as well. For this one, let's
promote it to a variable and say
dropped weapon. Now, I don't think we
need to replicate it, because I think we only need to run it
through the server. But I can't really determine
this for right now. Let's do the code and later on, if we actually use this
within the client as well, we need to replicate this. For now, let's let
it be unreplicated. I like things to be unreplicated when they don't
need to be replicated. Because remember, the more
information you replicate, the slower your game will be. Because you're
sending information from the server to the client. The more information you
send, less performance. Just keep things unreplicated
whenever you can. Now we have this dropped weapon. Now when you loot stuff here, when you're interacting
with it in the weapon base, we need to make sure that you don't loot the dropped weapon. What I need to do is
here from the player, before I do all of this,
I can drag it away. Before I do all of this, I can take this and say dropped. We take this here. If the dropped weapon
is equal to self, this weapon, I'm trying
to loot right now. If it is equal,
don't do anything. If it is not equal, let's actually just delete
this and let me say not equal. That will be better
for readability. If the dropped weapon
is not equal to the weapon right now I am
trying to interact with, then we can go
ahead and loot it. However, if it is the same, then don't do anything. Right now, we haven't
defined the dropped weapon. Let's actually do
that. Let me say this. Let me go back to the
player base up here. Whenever we drop the weapon, let's actually set
weapon and define it. Let me call this
event down here. Set dropped weapon, Let
me just call it here. And the dropped weapon
is simply this one. You can just call this one here. And let's move everything
closer, just like before. Let's compile and
save everything. All right, now we
can try it out. Let's click on Play and
play as a terrorist. Now if I loot
something and I do, you can see I am not
interacting with it. The problem like this dropped weapon keeps
being the same. So I can actually never
lot this weapon again. We have to remove it whenever. You can see here, whenever
I load it and I drop it, I come in here again, you
can see I can't load it. However, whenever we leave
this collision sphere, I need to reset this
dropped weapon variable. We can do it in the
weapon base again. Remember we use the on
component begin overlap. Now what we can use if you click on the collision sphere
again and go down, you can use this one
on collision overlap. Now you can use that to remove the definition of
the dropped weapon. Now what we can do
is just like before, let's copy This actor has tech player because
we want to make sure it's the player stepping out
of this collision sphere. Let's connect that again. Switch has because
we want to make sure it's the server that handles all of that
to prevent cheating. The only thing we want
to do is we want to set the dropped weapon to just
like reset the variable. Take this and say
get player info. Or get player reference. Actually, not info, get player reference.
Let's connect it. Let's call the set dropped
weapon and set it to nothing. We're just resetting the
variable. All right, here it is. Let's compile and
save everything. And let us give it
a try to fight. Click on play and I
place the terrorist. Now I run into the. In four, I drop it, I run out of it, I run into it. Now you can see it is
working perfectly. I don't loot it instantly, I only loot it whenever I
leave this interaction sphere. And I enter it again. I can loot the weapon. Now let us try to click on play. And play as two players. Now if I minimize this client, actually this is the server. Let's play as the client
as well as the client. I can loot the in four. The server takes a look that
looks nice. I can drop it. Looks correct. I
can loot it again. Looks correct. Okay. I can try to give you
this weapon here. I'm going to drop it.
This guy now loots it. I can drop it from this guy. Now I can't actually loot it. Sometimes it bugs out, you
can see sometimes when I drop it actually bugs out. I don't lot it instantly. That is the collision
sphere, you can see here. I can't loot it anymore. I'm trying to walk into it. I can't loot it
here as the server. This is because the other player is actually standing on it and it's taking the collision from that other player
that is standing on it. Whenever the new player tries connect with it
or interact with it, it's actually not
doing anything. The problem right now with this beginning overlap is it's only checking
for one player. If there are multiple players overlapping this
collision sphere, it's actually bugging a bit out. We have to fix this as well. You can see we have a
lot of things to fix and that is simply
the nature of games. You keep getting problems
that you need to fix, but it's really nice
when everything is working and everything
is written. Now let's go over to the next lesson and keep
improving the code.
110. 8.25 Weapon Player Interaction Improvement: All right, welcome
back. Now let's us improve this code to make sure that even though multiple players are interacting with the collision sphere, it's taking that
into account now when we make sure that we can
interact with this weapon. Now instead of just
doing this here, let me drag this code away. Let me drag this
down, and let me drag this away this way so we have some more
space to work with. The way you interact with
multiple things is if you write click and say get
overlapping actors. Now you get all of the
overlapping actors. I can get all of the players
that are overlapping. This here, who is overlapping, It is the player base. It is the player
base, meaning it's all the players
here for this one. Now I can ask if the length is more than one or if the
length is actually one. I can take from this
and say length. I can ask if this
is larger than one. Because if it is not
larger than one, it means that it's just one
player interacting with it. That is crucial information. If it is larger than
one, I can do something. However, if it is
not larger than one, I can take this and get, get the first index, meaning just this
player, this one player. And I can now connect
it to this one. Instead of taking it
from this other actor, I can now take it from
this overlapping player. And I can connect
it here If it is less than or not
larger than one, meaning it's just one player that is interacting with
this collision sphere. I can get this one player
here from the index zero, and I can connect that
player into here. Okay, So that is
running perfectly. However, what if we
have multiple players? Right now, I'm just checking
if it is one player. So if you have multiple players overlapping
this collision sphere, I need to look through those. I can take all of those
overlapping actors I can say. Or each loop with break. I want to make sure that
whoever dropped the weapon should not be interacting with this weapon that I
have on the ground. I can connect this Now I can take from here and say
get player reference. Now for each of those players, what I can do now is I can
take the dropped weapon. I can ask, is this
dropped weapon for this player that I'm looping through right now,
is it not equal? We're actually just writing
the same code as down here. If it is not equal to the weapon I'm trying
to loot right now, then I can go ahead
and loot the weapon. I'm looping through each player. I'm trying to find the player that has not yet
dropped the weapon. If it is true, let
me just right lick here and promote
those to a variable. And call this
interacting player. Let me set it to here. Go ahead and set it a make some reroute notes to make
it look a lot better. Now when we have
set this variable, what we can do now is now
here in the complete, when I find my
interacting player, I want to take this
and break the loop. Remember, always
break the loop so you don't get any box here. Your code will also be a lot more optimized because you
don't loop through everything. I break the code,
break the loop. Now I have the
interacting player. What I can do now. Now we need to run through
the inventory. Because we don't need to
run all of this here. We already did that up here. So we need to
directly run through the inventory for the
interacting player. Instead of taking it from here, it can actually just take
the interacting player now run through this up here, one player and you run
through this here. What you can do is just right click on this one
and promote this. Or just just take it here. This is the interacting player. Now if it is just one player
and it will run through this and run this
correctly, you can do this. Instead of doing all
of that, you can always just take it from
here now and plug it into here so I can move my code slightly so it's
not too messed up. Just like that. Now I'm just using this
interacting player. You can take this and plug it into here. Actually,
not like this. I don't know why I set it, drag it out, plug it into here. Instead of going
directly from this, Now we're just using this, this variable that we set. I'm actually going to delete this one and just connect
it to each of them. Just like that. Or
what you can do. I'm actually going to
use it multiple times. I'm going to use the
interacting player here. I'm also going to copy it
down here on this one. And you don't need this one. I can just plug it in
directly, just like that. I can also plug it into here. I'm just replacing
those rear art notes to make it look a lot better for this one is going
to this one here. I'm going to delete
the rear art notes. And just plugging it into here, that looks a lot
better than before. Now we are looping through this. We're setting the
interacting player, and now we're looping
through the inventory. All right, so now I
have organized it. Now as you can see, we're taking the interacting player variable and we're running it
through the code. We're making sure that it is the interacting player that can interact with all of this. Let us try this code.
Let us click on play. And let us play as the
terrorist, for example. Let me play as the client. Again, select Terrorist. Let me just lot something. Let me just loot this pistol. I'm going to the player, I'm going to drop it to the player. The player
should loot it. I'm going to drop it back. Now you can see this
player loots it. I'm going to drop it back.
This player loots it, I'm going to drop it back. Now you can see it is now working and everything
is working fine. If I drop it out here, I can't interact with
it unless I go out of this sphere and I
run back into it. However, even though
it's in front of me, this guy can loot it
without any problem. Now you can see everything
is working correctly now. Awesome. Now it's
actually looking more of a game rather than
just a prototype. We are coming nearer to our goal and you can see
everything is looking nice. It's really fun to
play and it'll be a lot more fun now when we add the shooting and
reloading and so on. As you can see, everything
is working fine. If I somehow notice
some box in the future, I am going to make some
videos to eliminate those. Or you can always visit Pixel Helmet.com or you can
visit my Discord server. If you find any box somehow
that I did not notice, I'm always fixing those and
showing you how to fix those, but for now we can't
really see any box. Everything seems
to work perfectly. I am going to improve
the game later on. For example, we can improve
whatever we think looks bad. Looks beginner like we
can always fix those. Here I am testing it as
the server and clients. I can drop it to
the client as well. They can drop it back and forth. I can drop it on the ground. The other player can go
inside of it, loot it. I can drop it here
as the server. The client can run into
it as well and loot it. You can see we don't really
have any box right now and everything is working
perfectly in the future. Again, you can visit my website
or Discord server again, Pixel Helmet.com and I'll
make sure that if there are any box somehow that appear
during game development, we can always fix those. But for now,
everything is working. Everything is nice. Let us
move on to the next lesson.
111. 8.26 Looting Weapon with Keyboard Key: Let's now go ahead and add some keyboard keys
to loot the weapons. Before I do that, I want
to increase my UI size. Someone told me
that it is hard to follow when my UIize is small. If you want to increase
yours as well, you can click on Tools and then debug and then widgit reflector. I'm going to increase it to 1.2 It is maybe easier
for you to follow. You can see my UI is
larger now let me know if this helps or if I
should turn it back to one. With that done,
let's go ahead to the input and let's make a
new input action, right? Again, you can do this
yourself if you wish to. We already made a lot of them. Let's right click and go to
Input and go to input action. Let's call this one lot weapon. Then for this one,
let's go ahead inside of the input
mapping action. I'm going to click on the plus up here and going down here and adding this lot
weapon input action. I'm going to press on my Ekey
to loot the weapon again. Over here for the triggers, I'm going to set it to press, go ahead and save,
close it down. Let's go back to the player. Okay, inside of here. By the way, we are going
to clean all of this up very soon in a
couple of lessons. Because you can see we
have done a lot and we also need to organize a
bit before we continue. Before we do this, let's
go down here and right click and search for
the A lot weapon. And choose that event. Okay. What I want to do
is when I press on my EK, I want to lot whatever
weapon is beneath me. What we need to do is
let's make a new function because we already have
one here. Let me see here. We already have this
one called Lot weapon. This lot weapon. Remember
we add an overlap weapon from that one we call
the loot weapon. It's basically not
loot weapon directly. It's more like we're
requesting to loot a weapon if we find
an overlap weapon. If I can find it again here, if I find an overlap weapon, then I can go ahead and loot it. Let's make a new custom event. And this one we're going to
call request lot weapon. And let's run it through
the server and reliable. And let's call it up here
when we press on the Ekey. Let's call SRV
request lot weapon. Okay, so first we're
going to check if we are overlapping any weapons
because we don't want to play the code. If we are standing here and we don't
have any weapons under us, that wouldn't make any sense. Let's right click and say it. Overlapping actors. And let us switch this
one to weapon base. We're making sure that we're
overlapping with a weapon. Let's strike from here
and say is not empty. This just checks
that we're actually overlapping with one
weapon. At least. Let's strike here
and make a branch, and go ahead and connect it. When we have a weapon here, if it is not empty, this means we are overlapping
with a weapon. We have to check if we already have this weapon
in the inventory. Because if you're already
holding that weapon either on your back
or in your hand, you have to drop
your current weapon. You can't have two pistols at once and you can't have
two rifles at once. You can of course, do
that for your own game, but for this game
we're creating, you can only have
one rifle, pistol, one grenade or knife or
whatever for this one. Let's say here, let's try to
find it in our inventory. Remember, we're already
doing all of this. I'm actually just
going to take this and copy all of this here. I'm going to copy this
up here and paste it down here because we're
taking the inventory and then we are checking if
we already have this weapon through
this weapon type, for this type down here, it is simply the weapon
we are overlapping. So I'm going to drag
from here and say gets. And then let's get a copy. And let's just get
the index of one. If we're overlapping
multiple weapons, we're just getting the index of zero here and we're
going to check it here. Okay, so what we need to do, just like before, we need to
get the name from this one. We can't really say
weapon name right now and get this variable
because this one, if you hold the mouse over it, it's just a general
actor object reference. Remember this one?
This is the BP, weapon based object
or object reference. And so if you just have
a general to reference, you have to turn it into
this weapon base first. For this one we have to
get the weapon reference. I don't think we
have done it here. In the interfaces we haven't
done, get weapon reference. Again, try to do it
yourself because we have done it before,
just for practice. Try to make a function get weapon reference and
try to use it here. Okay, if you don't remember,
let's do it together. Let's right click, go to Blueprint and choose
Blueprint interface. Let's call this one weapon
base. Let's open it up. Let's say get weapon
F. Now let's compile. Down here, you have
to select what Eva you are trying
to reference to. I'm trying to reference to the weapon base and select
it and call it weapon. Let's compile and
save everything. Let's go back here. Let me think in the weapons, let's open up the weapon base. And let's now go to
the class settings and add the interface down
here called Weapon Base. Go ahead and select Compile. And now you can
open it up here in the interfaces and you can
track from here and say self. This is a self reference. We have now defined
this variable. Now what we can do is we can go back to the player base and here we can drag and say
it, weapon reference. Now we have a reference
to this weapon base. And now we turned this
general actor reference to a weapon base actor
or object reference. What we can do is we can
drag this now into here, log it in just like before. Let's drag and say, can actually just copy
paste all of this. Let's just copy it. We
don't have to write it 100 times. Go
ahead and connect it. I'm actually going to
drag this one below this here and connect
it over here. Let's drag from here and make a branch and connect this one. Okay, so just before
we get too confused, maybe what we're doing here is we're getting that weapon
we are overlapping with. And now we're looping
through the inventory. We're trying to see if we
already have this weapon. If I just don't click to make a rear out note so you
can see what's going on. What we're doing is
we're looping through the inventory and we're checking if we already have this
weapon type in our inventory. If we have this weapon type, we have to drop it first. Let's say I'm
looting an AK 47 and I already have an
M41 on my back. I have to drop that 41. So we have to drop weapon. Remember we already
made that drop weapon. We call that. Now we don't need to call
this event from here. This is because we are actually looping
through the inventory. We don't need to do that because we're already doing it here. We actually have this part here, but what we need is
this part where we make it so the player can't
interact with the weapon. And the weapon will
be dropped and so on, and it will be removed
from the inventory. We actually also setting
this weapon type. We need all of this, you can
just paste it down here. However, for good
coding practice, instead of just copy pasting it, better to turn it into a
function so we can use it again. Go ahead and here in the server, drop weapon from this one. Select all of this, just select all of it here
without this branch. And right click go to collapse. To function, we make
this into a function, let's call this function
drop weapon. Drop weapon. Let me just double click up
here to make a rear out node. It is redouble for
this input pin. It is actually if you double
click on this function, I just make it a bit better
to look at right now. You can see it is a
bit messed up here. It ends here. Let me see if we actually need to do anything. After the true, it
drops the weapon and then it goes back
and breaks the loop. That looks fine. We
don't really need to do anything over here. All right, so now it
looks a lot better. Let's compile and save now
for this input pin here. Let's call it weapon to drop. Okay, we're doing all of this just like before and we're
just stopping the loop. We're just doing the
same thing as before. But now we made it
into a function. And we can now use
this function. If we go down here now and we found out that we have
this in our inventory, we can now take this weapon.
And now we can select. What weapon do you want to drop? I want to drop this weapon in my inventory
that I just found. So I can drag from this,
plug it into here. I will click to make rock notes. Okay, now we drop to the weapon. The next thing we need to do is we need to add it to
the overlaps here. Because when we add
it to the overlaps, remember we add it
to the overlap array and then we go ahead and
start looting the weapon. We need to call this
ad overlap weapon. Let's go down here and say
add overlapped weapon. And now we need to select what weapon
are we talking about? The weapon we're talking
about is this one. Remember, it's not this one. Because you can't drag from
here and plug it into here. This will not work
because remember this is just a normal
actor object reference. And this one needs a weapon
base object reference. Remember, you already
did this up here. So you can drag from this
one and plug it into here. Again, double click to
make reroute notes. Here you have it.
Remember when you found this in your inventory and
you're done with all of this, remember to drag from this
one and also break the loop, so you don't continue the loop. So again, double click and
make at notes here as well. Okay, before we end
this here in the loop, remember when you drop
a weapon as well, if you go up here
for the drop weapon, you have this where you set it to be interacted with
again and so on. So let's copy all of this again, and let's go down here
and paste it into here. Just like that, because
remember you are using this drop weapon and
inside of here you're making it so you can't
interact with a weapon. So you have to make it so
you can interact again. And we add that to
the complete it. Right now if you click on play and we can
select Terrorist. Let's run around, pick
those weapons up. Now if we click on the K, you can see nothing is
really happening right now. If I move out and then
again something is bugging. And we also have an error here. If I click on it,
it's just telling this one cannot be found.
Don't worry about this one. This is related to something else which we will fix later. But for now you
can see I dropped the weapon and I added the
overlap for the weapon, but for some reason it
is not picking it up. Instead of removing this from the video and instead of
giving you the solution, I'll try to show you how
I usually debug errors. This is a good place to do it. Now we are dropping the weapon. So we know all of
this code works. Because it reaches the point where it actually drops
the weapon from you. But something goes
wrong here from the add overlap weapon
for the first thing. Now when you debug, you have to add print string. We call this event here. Let me just add a
print string here. Search for print string, select it and it should
say hello over here. When I alluded, I
select Terrace. Now I go over to the AK. Let me, actually, I
didn't pick this one up. Let me just click here. You can see in the corner
up here, it says Hello. The code reaches
this part correctly. Now I need to check
if this is correct. Now I think this one
is wrong. But we can. The first thing here, I'm
just going to check here if this once is actually
running or not. Let's click on Play.
Select Terrorist. Go ahead and select
or pick this up. Click on here on the AK and
you can see nothing prints. Now I know that this
part of the code works, but this part doesn't work. It never reaches the point where it actually
lots the weapon. There is something wrong here
with this part of the code. Maybe it never opens. This note again. It says can lot weapon again. Remember this one
is one node and it only does this code once
until we open here, we reset this one node. Does this again.
There is something with this lot weapon again, can lot weapon again, we're calling it up here. There's something
wrong with this part. Maybe we're not removing stuff correctly from
this oval lap weapons. What we can do is we can always click here
and print string. Let's just print a string
here and see what happens if I click play now and
I take the terrorist. I lot all of this. Now
you see it removed. Instead of doing all
of this, let's just break from this index. We
actually know what it is. Removing the overlap popping, we're getting the index
and we're removing that. Let me just plug this
in instead into here, I can actually see
what I am removing. Phyclicplaylutephld.
Remove the ph. It does that as
you can see here. If I loot the pistol, it should remove the pistol, but you can see
nothing is printing. That is because
it's only removing the Inp but not the pistol. Something is wrong and the thing we're doing
wrong here is right now we're only removing this stuff whenever we are in
the unarmed state. If I click on Play and play now, whenever I am in
the unarmed state, right now it is
removing correctly. However, if I am not
unarmed anymore, it's actually going to
run this code here. And it will never run
this part of the code. What we need to do here, even though we are not unarmed, we need to remove whatever we loot after the first weapon. If we loot the info, we are not unarmed anymore. When we loot the pistol, it runs this part and
we don't do anything. Actually, what we need to
do is direct from here and also remove the pistol that
we looted after the info. So go ahead and connect
it to this remove. And let's compile now. Let's click on Play and
see if our code works. Now if I loot this one, now if we go to the AK
and if I click on E, you can now see it
works correctly. If I go to this one, actually I looted the pistol,
it bugged out. This is something we
fix in the next lesson, but for now you can see the info is working and
when we overlap the pistol, we need to fix this issue
and we are going to. But you can see it is looting the rifles correctly,
nothing wrong anymore. This is what we did
drawing before. You have to add some
rewrote notes as well here. All right, let's compile. The next thing is, you see here, if we press on E, I just keep spamming on my
keyboard and I like escape. You can see we have some
error here and says, Access non trying to read
the property looted weapon. It gets some error here and we will be fixing
that in the next lesson. As well as the era down here
that it gives sometimes. For now everything is working, let's save everything and let's move on to the next lesson.
112. 8.27 Setting the Equipped Item Type Correctly: Okay. Before we fix the
access, non errors. Right now what you can see
here is when we click on play and we loot the
info and the pistol. And when I go over to
a pistol and press E, it switches to that
pistol view mode. This is because remember
in the drop weapon we defined that you
should just switch to unarmed whenever
you drop the weapon. Now we have to improve this and because when you're
holding a rifle, we don't want to
switch to unarmed. Or when you're switching out
the weapon on your back, you don't want to
switch to unarmed. What we can do
here, very simple, is we can take the
equipped weapon. Right now, equipped weapon type. Let us try to ask if it is the same as whatever
we are dropping. If the equipped weapon type is the same as the weapon
we are dropping, it means we should
go to the unarmed. However, if we are dropping a weapon which we are
not holding right now, we should not go to the unarmed because it
was on our back. And we don't need to switch
the weapon type here. Let's drag from
here and say equal. Let's take the weapon we
are dropping right now. Let's drag from here. Let us say, for
example, weapon name. Let's get the weapon name again. Say get weapon info. This one. Let's break this. Let's take the type here and connect it. And ask if it is the same here. Let's connect this branch and
let me just organize this. Now what we're asking is, is the weapon we are dropping, is it the same type as the
one we are holding right now? If it is, we are going to switch to unarmed. If it is not, we are not going to do anything. We're not going to switch. Let us compile now and
let's see if it works. So if I go here and pick up the rifle and if I
click on the pistol, you can see it drops the other pistol that
I was holding now, it's not switching to the
wrong movement state anymore. If I loud this one as well, you can see the same
thing is happening, Okay? Now this is working and
the only thing right now is we get some axis non era. And let's do that. Let's fix
that in the next lesson.
113. 8.28 Fixing the Looting "Accessed None" Error: Okay, so the problem
right now with the access non is if we're trying
to spam the key. If I just keep spamming the
E key to loot a weapon, it gives me a access non era. If I just try that here. If I try to spam the
key just like that and I click on escape
because see we are getting this era saying access, trying to read the
property, looted weapon. This one access non means
that this variable is empty. And this is probably because
we are resetting it up here. And it doesn't get a chance to process the whole code before
we're trying to loot again. Because if you
spam the loot key, you're simply just spamming
all of this code here. And it, it reaches this
point and then it reaches this point as well
at the same time and it says access
none. It gets confused. What we can do is we can pause the player from looting whenever it's actually
looting the weapon. If I go over here and
make a new variable, let's call this variable
looting weapon. Compile this one when we
are looting the weapon. Let's take this and
say looting weapon, set it to true. Whenever it finishes
looting the weapon, we can take this and say false. Okay, This prevents the player
from spamming the code. We have to do it over here
when we are pressing the key, we have to tell the player that you cannot do it
whenever you're looting. Drag from here and say not bull. When you are not
looting a weapon, we can go ahead and
make a branch and say now you can go ahead
and request lot weapon. When this one is set
to true over here, when it starts
looting the weapon, you cannot do anything. But when we are finished
looting the weapon over here, then you can go ahead and
request to loot a new weapon. Now, this one is going
to give you a problem, and maybe you already can
see what the problem is. Now if I go as the client and try to
loot the weapon here, you can see it's
giving me a problem. Right now, if you remember
we are in multiplayer. And this one right now, you are setting it
through the server and over here you're trying to use this variable on the client. Remember, you can drag and write a print string to see if you are on the server
or on the client. If I play here as the
server and I press, you can see I print
hello as the server. But if I play here
as the client, now I play and press. You can see I'm spamming
this as the client. I can play this code through
the server and the client. This means we are
also on the client. When we are down here, you're using the variable
on the client, but you're setting
it on the server. Remember as the server, you have to replicate
information back to the client, else the client have no chance of knowing if this
is true or false. When you set something on the server and you need
to use it on the client, you have to replicate that information back to the client. Let's
compile and save. So now if I play as the client and I go
ahead and click on play, let's try it out
here as a terrorist. Let's pick up the weapons and let me go over
to K. I press on, everything is working now. Okay, it is working. And I can also
switch my pistol on the back and I can
switch this one as well. You have to do this
if I spam now, spamming my lot key, set a delay if you wish to. If you don't want the player
to switch this quickly, you can set a delay for looting. But as you can see here, it is working correctly. And if I click on Escape, you can see we don't
get any errors. This is because it's actually
waiting for this to be false before the player gets
a chance to loot again. But the player don't notice this because the code is
running so fast. But now we have set this barrier and everything
is working correctly. Sometimes if it does
say error with weapons, you are trying to drop. If you're trying to play
here and you're trying to spam the key and I
press on escape. Right now I'm not
getting any errors, but if you get an
era in the future, you can always take this. This is the era we got before. You can right click convert
this to a validated get, make sure it is valid
before we make all of this. Yeah, that's how you get rid
of the era before we had where you actually got an era
from dropping the weapon. You can see I'm
trying to spam it. Nothing is happening.
I think it is fixed. But if you get that problem, you can always do this. Let's compile and
save everything. For now. Let us move
on to the next lesson.
114. 8.29 Cleaning up the Code: Okay, so before we continue, what I want you to do is
I want you to clean up this whole project
because it's getting quite large and we need
to fix some things. If we can optimize stuff and we can comment out some things, it will be a lot
better to do it now than later before it
gets too complex. So what I want you
to do, for example, you can go over
here to the Begin. Play. Try to make rear route notes if you don't have already. And you can select everything. Click on C on the keyboard and you can, for example,
write begin, Play. That is better than
having nothing here on the code. And you
can click on it. You can click on
the comment color, You can change the comment
color to something. For example, I can choose
this blue purple color. I can put down the saturation 20.75 and I can put the
alpha 20.25 for example. Just try to stylize this
as best as you can. Also, for example, I can
make the text to 24 instead, so I can read it a lot
better when I'm zoomed out. But you can see here. And
you can also save the color. If you click here and you can click and drag this up here, that is safe. Now when you comment out something
down here, for example, let me just drag all of this and move it down
diesel like this one. So I don't drag this down, drag all of this
down, for example. You can comment out this part because this
part is for the footsteps. What you can do is you can click on this one, for example. You can call Playing the
Footsteps sound effects. Again, just like before, I'm going to make the front larger. And you can click up here
and click on this color. And this will
automatically apply whatever settings you
have done up here. Okay, so I want you to
comment out everything. Try to make everything as
organized as possible. And also apart from this, I'm going to make the
comments in my own free time, so you don't have to look at me making comments
of everything. But just remember that you can make comments with comments. You have this one
and let's say I wanted to include the
movement with this one. So you can always select everything with the
comment over here. And you can make a new
comment and for example, call this one movement. So you have a head comment. And you can even comment small things inside
of here as well. But for now, I'm going to
do that in my off time. What is more important
right now is seeing if we can improve the code
somehow. We actually can. If we go down here, you can see we have
used this one before. A lot of times We're taking the inventory and
we're going into a loop and we're trying to find this item inside
of the inventory. We're doing that
quite some time here. A couple of times. We can
also see we're doing it here. So we're looping
through the inventory and we're getting
this item type. I believe we do that some other place that I
can't find right now. But for now, let's
actually make this into a function and this
will be a lot better what we can do. Let's
just copy it for now. Let's copy this part
of the code over here. Let's also copy this one equal. Let's just copy and
paste it over here. We can actually make
this into a function. What we can do is we can
select all of it. Right click. Actually you can't make it into a function because
we have a macro. If you say collapse to function, it says error and you
can show the message. And it says that it can only
have one execution pin. And you can see this one has
a lot of execution pins. What you can do is
right click and collapse this to a macro. For this macro, the difference between a function and a macro is simply that a macro can
have multiple execution pins. And functions can only have
one input and one output, whereas macros can have
multiple execution pins. And you can see
here, this branch that we're using is actually a macro and it has multiple execution pins for
this macro we just created. Let me click here
and click on two. Let's call this one M for macro. Let us call it Find
Weapon Type in Inventory. This is simply what it is doing. It's trying to find
the weapon type inside of our inventory. Let's make a new
execution pin here. If you just write
execution, I think execute. Actually, if you
click on this here, the type, if you
just write execute, we'll actually remove
the text over here. That is a secret
for macro writing execute. Let's connect it here. We also need an execution
pin to break this later. Let me make a new execution pin. Let's call this one break loop. Okay, now we have that. Let me connect this down here. And we also need an
input for this one. Let's strike this one into here. Let me just move it up once. If I click and
drag this up here, Let's change the
name for this one. And this one is
weapon type to find, we're trying to find
this weapon type within our inventory. Just go ahead and
double click on this and make some reroute
notes as well. All right, out here
in the output, we need to have all of
this inside of here. Now let's first take this loop
body and place it in here. And it already says loop
body. That is correct. Let's now take this one
and place it into here. Instead of return value. I'm saying weapon
found and we can make a branch to see if
this is true or false. Now for the other thing, I'm going to plug in the completed. Oops, not like
this. Taking this, plugging it into here. And I'm going to just for
clarification loop completed, we also need the
weapon reference later on so we can do
some things with it. And I'm going to
move it up here, Let's just call it weapon now. It doesn't matter if it is
moved down here, for example. If I move this down here or I move this up here, it
doesn't really matter. It's just staying
clean with the code. But I just like
having it this way. Again, I'm going to double
click this and make some route notes as well as for this
execution pin over here. Okay, so here we have
it and let us compile. Now let's go back
to the van graph. And now you can see
this is the macro that we have created. Now we can use this
one instead, whips. If I zoom in again
for this drop weapon. Instead of doing this, we're already looping inside of here. What I can do is
I can delete this and I can plug this
one in instead. Let me just move it a
bit away so I can see what I'm doing. Now. Instead of doing all of this,
we're already doing it. Let's delete this one as well. This equipped weapon type. We can take this and
plug it into here. Instead. This is,
remember this is what we're trying to compare
with our inventory. This is the same
thing as before. And if I connect this loop and I connect this branch with here. Now let's see, this weapon. This is what we need to use
over for the drop weapon. When we have found the weapon, I'm going to delete
these three route nodes. Going to move this
closer to here. And let's break the loop
after we drop the weapon. This code is just like before. It is actually just optimized. We didn't do something new here. We're just creating this macro to make it look better
and more clean. Yeah, when the loop is complete, let's connect all of this
again, just like before. Now you can see it's a
lot cleaner than before. This is how you optimize code. Now you can use this one. Let me just organize
this a bit more now. We can take this find
weapon type in inventory. We can, let's see here
over here where we try to find the item again in the inventory.
Let's drag it out. Let us delete this one. And delete this one as well. Let me just connect it
for now in the loop body. Just like before,
we're connecting this, all of this here we're already having
inside of the macro. I'm going to delete all of this. And this one as well.
This one is what we are trying to compare this weapon type from
the weapon info. What we can actually do, even though it looks a bit confusing, we can drag this and
put it back here in the weapon type
to find again, double click to make at notes
just so it looks better. What we're essentially doing
is the same thing as before. Without this macro, we're just
finding the type and we're plugging it in to compare it with the weapon type
from the inventory. It should do the same thing. Let me take a look over here. It's going through the branch. Remember we're going to
run this branch here. Let's also double
click on those to make rear route
notes for this one. For this weapon here, weapon to drop it is from the inventory. So we're trying to drop the
weapon from the inventory so you can drag it
here and connect it. Okay, now everything
is connected. And remember to break
the loop from here. Again, drag, break the loop. I just want to see if I
actually remember to do this as well for the
other one, and I did. Let's go down, and I'm going to push this a bit further away. They are not overlapping,
just like that. Okay, compile and now
for the loop complete, let's reconnect this
one down here it is. The weapon, we are trying to drop the weapon
from the inventory. And it's the weapon we
are trying to loot. That we will be overlapping
with just like before, but we have just made it a
lot cleaner than before. So it's always nice
to play the game and just to test and see if everything is
working as expected. So you can now see it is
working just like before. Yeah. So everything is working. There is a small mistake
right now with the code, and that is over here when we're trying to request
loot the weapon, we're trying to compare
it with the inventory, trying to find the weapon
inside of our inventory. If we don't have the
weapon in the inventory, then we are ending in
this part of the code. Because if we have the
weapon in the inventory, the weapon we're trying to loot, we're trying to drop the
existing rifle, for example. However, if we
don't have a rifle, it's actually going to end here. Instead, I'm going to take this and plug it
into the overlap, because we still want to loot the item if we don't have
it in our inventory. Just a small fix to
this code, okay? All of the other things, I don't really see more stuff
that we can try to improve. But if you want to make something to functions,
for example this one. You can make a function or things that you want to
function and try to clean out. Go ahead and do that it now. However, I think
this is sufficient and I'm going to
comment everything out. What you can also
do is you can put all of these variables
into categories. For example, the speed here, you can write something
in the category. For example, layer properties, that could be one category. And you can see
it is added here. And you can click on
the run speed as well. Click on Categories and add
it to the player properties. The same with the
crouch as well. Now you can see they
are in one category. You can clean up all of the
variables just like that. You can actually do that
as well with functions. However, you cannot do
it with unrep functions, you can only do it the other functions
that you have made. Okay? So with that said, I'm going to comment
out everything. And remember I'm going to
hand out this project to you. And you can download
it from the website so you can see all of
this that I've done, all the comments, and so on. But you'll probably also
see it in the next lesson. I'll go ahead and
comment everything out and I'll see you
in the next lesson.
115. 8.30 Fixing a Small Replication Issue: Okay, so before we continue, let's go back to
the player base. So you can see here, I have
cleaned up my project, I have put everything in order, and the only thing I did
is basically just create some comments and organize
things a little bit more. So we have the basic
character movement here with all of the things
we've done with the crouch, the walk, the jump and so on. And down here I have the looting
and dropping the weapon, or we have the overlaps, the looting for the
weapon and so on. And I also added a
comment for this one, make sure that the
weapon is attached. The delay we talked
about earlier, it's always nice to
write why you edit this delay so it doesn't seem random and you delete it
by mistake in the future. Okay, so let's save everything. And right now, before we
continue to the next section, we have a small bug
that I realized. If I click on terrorist
here and if I try to loot two things,
sometimes it works. So you can see I
looted things here. I'm actually going to click on the spring arm and make
it to something like 500. Just so I can see what is
going on and I can play again. I have to do it a couple
of times and sometimes you will realize that the player is actually
not looting the weapon. So I'll just keep trying to
loot the weapon like this and see if I can get the
buck to be there. Here. Okay. So I tried this a couple of times and after 1 minute of trying
again and again, you can see here
it is bugging out. I don't have a
pistol in my hand. If I just move it quickly so you can see my hand
doesn't have a pistol. The pistol is on the
ground and I can't really loot it like this,
it's bugging out. However, it is working
on the server. So if I had the server playing, I think we are playing
as two clients. So you can see this
is the second client. I join as the second inclined
and look at this player. I can see that this player
does not have a pistol. So you can see here, doesn't
have anything in the hand. I can't see the pistol
still on the ground. And I can't loot
either on this one. The bug is happening because this is just a
replication issue. If I click on G to
drop the weapon, you can see now it's
actually on the ground. If I walk back and I walk
to the front of it again, you can see I'm
looting the pistol and now I actually have
the pistol in my hand. So it's actually just
a replication issue and I realized that one, it took me maybe 1 hour or
30 minutes just trying to debug and see what was going on because everything
looked correct. However, the thing that is wrong right now is in the loot weapon. If you walk on the weapons. And the thing I did here
to get this bug is just to walk over two weapons quickly.
Like something like this. And I just try a couple of times and one of the times
you will get the bug, sometimes one of the
weapons doesn't work. This is actually because when this code is running and
you're trying to loot the weapon through this rep
notify sometimes if you walk over it quick enough
or at a correct pace, it will actually delete
your looted weapon here. And when the next one reaches it then doesn't have anything, it will not be valid. And then all of this will not happen and you will
be bucked out, and then you can see the
weapon is on the ground. But if you play as the server, then you can actually
see the client is holding the weapon. However, for the client, the client cannot see
the weapon in the hand. They can only see
it on the ground, even though they're actually
holding it in the hand. I knew it was a
replication issue because the server
looked at it correctly, but the client looked at the it seemed to be on the ground even though
it should be in the hand. It's actually this
one. This is what's, what's making it all weird. Instead of deleting the
looted weapon variable, remember what we did here? Just a quick walk
through so we don't get too confused because we have done a lot in this course. What we simply did is
we looted the weapon. And then we go through
this, we loot the weapon. We're checking if this
overlap weapons is not empty. If it is not empty, we
are looting the weapon. And then after all of this, we're removing it from
the overlapped weapon. And then we're re
checking if there are more overlapped weapons
which we need to loot, that will take us up here. Actually, let me
see where it is. It takes us up here, check
for overlapped weapons, and then tries to
loot weapon again. Again, it checks if it is empty. Now there is less items now because we removed
the old one here. Now it runs in again. Let's say it only
was the pistol. Let's say it only was the
pistol and we removed it here. This one should be empty now. And it says, if it is not empty, it will be false because
it is empty now. And then it says, can loot weapon again. It will delay it. Here, it will delete this. Remember, the reason we deleted a rep notify is because if you loot the same
weapon over and over. Remember a notify does not run if you update it
with the same value, if I updated with
the same pistol, this will actually not run. This is the downside
of a rep notify. If you apply the exact same
value it will not run. This is why we actually delete the variable and then
we can run it again. Okay, instead of
doing it up here, just a very simple fix, we can take it from here. Let us just paste it
somewhere around here. Instead, we can't paste
it here because we are actually using it here to set the movement state or
equipped weapon tight. We can add it here before
we remove it from this one. Or you can also add it over
here. It doesn't matter. I'm just going to add before this here and you go
ahead and connect it. And then I'm going to
reorganize things, right? So I moved the comments as well. Here we have it now it
is down here instead. And we can actually
have it down here because we are
having this delay. We can utilize this delay, So we're not overwriting this variable here because
we actually have a delay. And this code can play before we actually
delete the variable. It makes sense that
it is down here. And then we don't really
need this delay, this delay. We add it before because we wanted to wait for
this code to play. However, for this one,
let's just delete it. This one we can just connect
back. Just like that. Yeah, I think this
will fix everything. So let's save it all. Let me just click, actually let me switch over to
play as listen server. And I'm going to play
as three players. I'm trying to again play and see if I can get this
book to appear again. All right, so I've tried about 40 times now,
nothing is happening. And it seems to have
fixed the issue. This was a replication issue. Everything is working
as it's supposed to. Now let me just click on the
spring and set it to zero. Again, compile everything. Let us move on to
the next lesson.
116. 9.01 Weapon Switching Input Actions: Now it's time to create
the input action for switching the weapons and
try to do it yourself. Try to make an input action called primary weapon
and secondary weapon, and try to add them yourself. We have done that
quite some time now. Just a cool challenge. And you can try to
challenge yourself. And if you don't remember, let's go ahead and do it together. Let's right click here and go
to Input And Input Action. I'm going to do it
a bit quicker than before because we know
what we are doing now. Primary weapon. Let's try, click again, Go to Input Input action, and make the secondary weapon. Let's go to the input
mapping context. And out of here I'm clicking
two times because I need to add two mappings here. And I have no idea why
doesn't show me anything. Actually, I think I need to change this before I
can add the second one, a primary weapon. And I'm going to click
on the plus again. I don't know why they
keep maximizing, It's actually a bit annoying. I think you can press here. Yeah, you can say here,
collapse or expand. All you can collapse all.
I think maybe it works. A secondary weapon? Yeah, they maximized again for
no reason. Primary weapon. I'm going to click
on my one key to get my primary weapon
which is my rifle. And click on the two key
to get my pistol again. As the triggers I'm going to write pressed because I
only want to play it one time. When I click the button, I don't want to
update constantly. So these two are added. Now let's save everything,
let's close them down. And let's go to the player. Let's go to the player base. And inside of here, let's right click down here
and say IA primary weapon. And down here let's say
IA secondary weapon. Okay, so now we have
these two events. And we can use those to get our rifle or our pistol if we
have them in the inventory.
117. 9.02 Weapon Switching Logic: Okay, so for the
weapon switching, let's first go down here. I'm going to remove this to the side because I
don't need this first. We only need to work
with the primary weapon. So let's rightly here and
make a new custom event. And I'm going to run through the server and I'm
going to call it, let's call it equip weapon. Let's run this one on
the server and reliable. When we press on the
one key, for example, the primary weapon key, we want to equip the rifle. When I do something like this, I try to think one
step at a time. Don't think two steps
or three steps ahead, because you'll get confused. And I will get confused as
well one step at a time. What do we need to do when
we need to equip the weapon? First, if you have this weapon in your inventory
and how do you do this? Remember, we made this find
weapon type in inventory. We can drag this in here. The thing we want to find
is simply the rifle. Because when you click on
the one key I can actually drag from here and say
server equipped weapon. When we click it, we
want to find the rifle. Now first we want
to make sure we don't have the rifle already in our hands else it doesn't really make sense to re,
equip the rifle. I'm going to take what we
already have equipped. So the equipped weapon type, I'm going to say if it
is not equal to rifle, then we can go ahead
and run this event. Because if we already
have the rifle equipped, it would not make any
sense to run all of this, to go ahead and
connect this here. Okay, so down here, let's from this branch
and make a branch here, or from this bullion
and make a branch. And whenever it finds this
weapon in the inventory, so whenever it finds the rifle, I'm going to make a bullion. And this bullion is called a
weapon found in inventory. And now we can take
this here and set it to true, just like that. And remember to break the
loop like this, Okay, now we know it found the weapon in the inventory down
here in the completed. We can continue the code here. We was just searching for the item in the inventory
and now we found it. So I'm going to take this
pull in and make sure that it is true
only if it is true. We are going to run some code. If we have not found
it in the inventory, we don't really need
to do anything. What I need to do is
equip the weapon. Let us actually here, we can just right
click this one. This is the weapon we
found in the inventory. Let me just promote
it to a variable and call it equip weapon. Now what does this, does it need to be
replicated or rep, notify? You can try to answer the
question to yourself. And why should it be rep,
notified or replicated? Now I will give you the answer. This one needs to
be rep, notified. And remember, whenever
you have visual changes. So right now the player
is going to hold the rifle in the hand
that is a visual change. You need to make it
into a rep notify, so you can notify all of the clients of the
visual change. So go ahead and connect it here. And click on it and
set it to rep notify. And then also remember
to change your stance. Because right now
if you click on it, you will equip a weapon. So right now we don't
have this done, and we will do that
in the next lesson. So you also have
to remember to set your current
equipped weapon type because remember
we made this here. This one is controlling what is being played inside of
your animation blueprint. Let us go down here
and let's say, and you can find it here,
set equipped weapon type. Then the weapon type needs
to be rifle in this case. Also, you need to
set this to falls, because later on
when we do this, again, it will be set to true. Remember to set
it to falls here, we need to reset this
variable as well. We need to set it to falls whenever we have
finished the code, the next time it goes in, it runs the code correctly, else it will be
true automatically. And it will run this code
even though it is not okay. And I also want to reset this variable because when
we have done all of this, remember we need to reset the rep notify so it
doesn't buck out. And we can take this
equipped weapon and reset it here before
we end everything. And maybe we need
to add delay here so we give the rep
notify time to play. But let's actually
check it later. I'm not a fan of
adding random delays. I only add delays
whenever we actually need to because delays are nice. This one will not be noticed. It's 0.05 No human
will ever notice this, but we don't really need to add one if we
don't really need to. Okay, so the second
thing we need actually here is if you're already
holding a weapon in your hand. So for example, if you're
already holding a pistol, you need to unequip that pistol. We actually need to
unequip as well. So I need to ask if the
player is armed or unarmed. Because the player
might be holding a pistol right now
and we're looting the rifle and we're pressing on the rifle key and we already
have a pistol equipped. Then we need to unequip
the pistol first. Let us, from here I'm going
to disconnect it actually, and just drag this down a bit. Then we can take this equipped weapon type
and we can say, is it equal to unarmed? Let us make a branch here
and connect it here again. If it is equal to unarmed, we will just go ahead and run
the code we made earlier. However, if it is not unarmed, we want to unequip the
weapon we are holding. Just again, find the weapon in the inventory that we
are talking about. What weapon are
we talking about? We are talking about the current equipped
weapon that we have. This might be the
pistol right now. Then when you have found this, we are making a branch
just like before. When you have found this,
let's promote this to a variable and
call it unequipped weapon. And let us
make it to a rep, notify and let us
connect it here. Make some rear route notes. And then when this is complete, because right now you're running this code and you're
unequipping the weapon. But you have to equip
that weapon afterwards. So here in the complete, you have to run
this up here again. Let me just drag it out here to make some space and
make it look a lot better. And we can drag this up here. Okay, so something like
this looks a lot better. We're checking if we
are unarmed or not. If we are unarmed, we are going to equip the weapon instantly. If we are armed with a pistol, for example, we're going
to unequip the pistol. Remember to break the loop. I forgot to plug it in here. Let us break the loop as well. After we break the loop,
and it is complete, we are going to
equip the weapon, the unequipped and the equip. We will do that in
the next lesson. But also remember to reset the unequipped
weapon so we don't get box later in our game. Yeah, that was it for
the logic right now, we can't really test it out because we don't really
have the rep notify. Let us skip ahead to the next
lesson and work on those.
118. 9.03 Equip and Unequip Weapon RepNotify: All right, so doing the
unequipped equip rep notify. This will be very easy because
we have done it before. If we go over to the loot
weapon or looted weapon, if you go to the rep notify
for the looted weapon. If you go inside of here,
remember we did all of this with disabling the
collision and so on. So when you already have the
weapon in the inventory, we already removed the physics, we already removed the collision,
and we did all of that. So we don't really need
to do all of this again. You already did this when
you looted the weapon. So the only thing
we need to do is actually equip it from our back. So this one here, attach actor to either
one of those sockets. So let us just duplicate
this code here. I'm going to copy and
I'm going to go over to my equip weapon and I'm
going to paste it over here. All right, for this one, it's not the looted weapon. I'm going to delete those. It is our equipped weapon, so I'm going to drag it
and plug it into here. And I'm going to plug
this one into here. Okay again, I'm going
to take it over here and right click and say
convert to a validated get. I'm making sure that my variable is valid
before I do all of this, before we attach it. Remember right now
your equipped weapon, this one here right now, is attached to your back. For example, your AK 47 before
you hold it in the hand, it is attached to
the characters back. First what you have to
do, you actually have to detach it from that old socket. You have to drag it from here
and say detach from actor. We're detaching it
from the back first. And we can keep the position
to world on all of them. After we detach it from
the back, we can go ahead. I'm actually going to
delete this route node. I'm going to connect
it directly here. And we can break this down to make it look
a bit better here. And then this one you can actually delete and you can connect it here if you wish to. It's just to make it look a bit better,
something like this. Let me just move them
closer together. Okay, here we have it. This is the equipped
code for the unequipped. Maybe you already guessed it. We have to go to the
let's weapon to drop. We already did all of this and actually
not wap into drop. Let's go to the looted weapon. We need this code here
where you put your pistol, for example, on
your thigh when you have taken out the rifle. Let's just copy all of this here where you put it on the
back or on the thigh. And let's go to the unequipped
weapon, just like before. Let's paste this one. And let me take the
unequipped weapon instead and plug it in here. Let me delete this one.
Let me take it again, Right, Convert to a
validated get connected. Actually, let's just delete this one and connect
it here instead. Before we do this, let's
again detach from actor. And we're going to keep the position to world and we're going to detach
it from the actor. And then we're going to
connect it over here. Remember also here, we're using the unequipped weapon,
just like this. Okay, go ahead just like
before. Move it down. And move it closer, so it looks a bit better. Something like this. And let us go ahead and
compile and save everything. Okay, so now we're finished with those and we can go
ahead and click on Play to see if it actually works or if we have
made some books. And let's go ahead
and click on play. Let me here as the server play
as the counter terrorist. Actually, let's play
it as the terrorist. Because the weapons
are there right now. It is only the one
key that works. So I need to elute the
rifle as my second weapon. Now if I click on one, you can see I'm actually
selecting my rifle. And if I spam the one key, remember we can't spam the one key if I close this
down so I can show you, because here, let's
find the event graph. I'm actually going to
close all of this. So I'm going to move this here, right click, close
tabs to the right. So it's a bit more
better to look at here. Remember, we made this
bullion so we can't spam the rifle key because if
we already have the rifle, we don't run this code. This is good for
optimization as well. So you don't run
code unnecessarily. Everything is working great, and if we find any box, we can always fix them. However, everything is working. Next thing we need to do
is the secondary weapon, and let's do that
in the next lesson.
119. 9.04 Equipping Secondary Weapon: Right now let's do the
secondary weapon now. You can go ahead and copy all of this and
make a new event. And just copy paste all of this and change this to a pistol. However, this would not really
be good coding practice. Now remember I'm trying
to teach you the best code and we could copy
paste this down here, and it would work perfectly. However, when I see
something copy pasting, when I see code that needs copy pasting and the only thing I need to change is one value, for example, this
from rifle to pistol. I always try to hunt. I just have this
one event and I can re use this event instead
of copy pasting it again. Yes, we can try to
think for yourself, how can we use this
event here as well? It actually works here and here. Without having us to
copy paste all of this, what do we need to do now? We can post this video
and you can come back. And now I will give
you the answer. Instead of having it
as a static variable, we can have it to be dynamic. We can drag this into
here, into this event. This is the weapon type to find. I actually believe we need,
yeah, this one as well. When we switch the weapon, the animation, this one needs to go into this one as well. Let's double click this one
and make some reroute notes. All right, now we have
plugged it into here. What we can do is up here
in the primary weapon, we can just change it to a rifle up here instead of down here. What we can do down here, I'm just going to copy
paste all of this. And paste it down here. I'm going to connect it now instead of rifle. Now the secondary
weapon is a pistol. So if we don't have a
pistol already equipped, we can go ahead and
run this event. And this one I will
change to pistol now. It's going to have this
value plugged into here and now it's going
to search for a pistol. Okay, so now, very easy, we actually finished
this lesson. You can click on play and I can click on terrorist and I
can loot these two weapons. I can click on one
to have my rifle. I can click on two
to have my pistol. Now you can see we can switch between those two weapons
without any problem. And we didn't even copy
paste all of this. We just re used the same one.
120. 9.05 Creating Animation Montages: Okay, so what I'd
like to do right now is I think it's a
bit cheap right now. Because we can switch
the weapons like this. And it would be cool if we have an animation when we
switch the weapon. If you have played
Counter Strike before, when you switch a weapon, it kind of reloads the weapon
before you can use it. Let's do something like that and for this lesson, very simple. We're just going to create some animation or
animation montages. Let's click on the assets. Remember, it's not the animation,
it's not the old ones. It's the assets.
It's our character. Just make sure it's
our character. Instead of here, I'm just going to search
for reload because we have some reload animations
we will be using later. Now, I don't have
specific animations for taking out your weapon. You probably have if you have a serious project and you want to make
something like this. However, for this
one, let's just use the reload animation when
we drag out our weapon. And this is for good
practice as well. Let's right click on
the pistol first. For example, go to Create and create an animation montage. With the animation montage, we can add actually something
like reload animations, fire the gun animations
and things like that without disrupting our
running animation. And click the animation
montage and let's call it anion for animation montage
and call it reload pistol. Let's do the same thing for
the rifle, right click, go to create animation montage. And call it reload rifle. And if you open it up now, you can see we have
an animation montage. And we have some
stuff we can do here. And we're actually going
to use this part down here to create like an
upper body movement. So when we are running, we can have this
other animation, this reload animation, without stopping our running animation. So we can have two
animations at once and this is why we created
this animation montage.
121. 9.06 Adjusting the Animation Blueprint: Okay, before animation montages can work on your animation, you have to do something inside of the animation blueprint. Let's go to the player and let's open up the
animation blueprint. And remember this is what
we have done here so far. What you need to do
is you need to play an upper body movement,
as you can see here. If I go back to my
animations and I search for my animation and I take a look
at my animation montages. Now if I click on one of them, I can see here that it is using a slot called default slot. And we actually need to use
the upper body instead. Here in the animation
Slot manager. Let's click on a slot, let's just call it upper body, because I only want to
move the upper body when I reload and I still want my
character to run around. You can run around and reload upper body and let us save it. And now you see if you go
to the pistol as well. Here in the slot manager, you have this upper body. You have this slot whenever
you created on one of them, the rifle has it and the
pistol has it as well. Okay, You need to click on the slot here instead
of default slot. Let's now click over here to slot name and change
it to upper body. The same thing for the pistol, so both of
them click here, slot name and change
it to upper body. Now you can see the
animation is not playing because it's actually only us that know this is
the upper body. We haven't really
told neural engine what the upper body is right
now. We need to do that. Let's go to the animation
blueprint inside of here. We need to use a function
called layered blend her bone. This one layered blend her bone as the default. Let's
take the pistol first. Let's copy this. Pistol
movement cached, and let's place it here. What needs to blend to is try
to copy paste this again. And we need to drag here and
search for default slot. You can see here we
have this default slot. However, this is not what
we want to use right now. We want to use, if
you click up here, you want to change
it to upper body. Now we are using
this one instead. And you can go out
and connect it here. Whenever we play our
animation montage, it's going to blend
between the two. We have this blend here. Let's click on it here. And let's click on
the layer set up. Click on here and
click on the plus. Click the arrow here. Now
we are inside of here. What we're trying to do
now is we want to tell Unreal Engine what
is the upper body, because right now
Unreal Engine doesn't really know the upper body. You have to give it a bone name. If you open up the skeleton
or the character and you click on the character
bones and all hierarchy, you can see the bone
for the character we want to tell the upper body. Where does it start? Usually
for most of the cases, it starts here at spine 01. Sometimes it looks better
when it starts from spine 02. In this case, let's try
to use the Spine 01. You have to go back and
you have to write it exactly as what it
is called here, we will call it Spine 01. And the blend depth is one. And also mesh space rotation, blend is said to true. Let's compile and let us
delete it from up here. And let's connect this instead. Just like that,
I'm going to copy paste all of this and
delete the pistol. And instead, take over the rifle and plug
it here as well. Let's go ahead and
connect the rifle as well and delete this old one. I'm going to move this down and organize things a bit more. So something like this here. Then I can move it up
here just like before. And now we have
actually finished this. If I click can
compile, you can see my character is
actually moving now. Now if we play our
animation montages, everything should
work perfectly. Remember to change it. Here in your animation montage, remember to change
it to upper body. And remember here
for the upper body, for the layered blend per bone, remember to tell it, which bone do you want to blend from. Very, very important.
Save everything, and let us move on.
122. 9.07 Equip Animation Multicast: Let's go ahead and make it work. Let's go back to
the player and open up the player base here. Let's play our
animation montage. What you need to do is take
this mesh that we have and you can drag from here and search for animation montage. And then you can see it here. Play Animation montage. Okay, now we have to select what montage are
we talking about. I'm going to make it
dynamic just like this one. What we can do is remember this one is a temporary effect. Instead of using a rep, notify, remember a rep notify be seen by a player who has not yet
connected to your server. And if they connect,
for example, 10 minutes later, they can
see your equipped weapon. However, for the animation, like the reload
animation when you pick up a weapon and they
can see a reload, doesn't really need to show
for unconnected players because it's just an animation that disappears after 1 second. People will not really
feel sorry if they can't see that animation
when they connect, because it's just going to disappear after 1 second anyway. So I'm going to add to
a multicast instead. A multicast. Remember it's only the connected players
that can see this. And unconnected players, if they connect the same time
you're reloading, they cannot see it
until you reload again, let us make a new
customer event. Call it multicast. Let us call it Equip Weapon, because I usually just call it the same name
as the server one. Let us run this on
multicast and reliable, and let us connect it
here for the multicast. Depending on if we are
holding a pistol or a rifle, we want to play that
respective animation. Just like what we did up here. I'm going to make
a new variable and it's the type of weapon
type just like up there. Selected. Let's just
same thing here. I'm just going to equip. I'm just going to
call it to equip. I'm actually going to call
it the same thing up here. Instead of to find, to equip like this
weapon type to equip. Okay, everything looks good. Now we can drag
from here and say select and use this select node. Then we can connect
this one down here. Now it's going to
select the animation depending on what this
enumeration value is. If it's the pistol, I'm going to select and play the pistol. Animation Montage.
If it's the rifle, I'm going to play the
rifle Animation Montage. Now it's going to play it
depending on what we have selected up here for the rifle or down
here for the pistol. Let me actually just move
it beneath both of those. I'm actually going to
organize this a bit more. Moving this, moving this above. So these are together and
this one is below them. And we can move this one up
as well, just like that. Okay, so now we have it and now we need to add it to the code. So I'm just going
to add it here. Right after when we change
our movement state, I want to play my
reload animation. And we called it
MC equip weapon. And remember, multicasts can
only run on server events. This is a server event. Remember very important,
multicast cannot run here. So you cannot call a
multicast up here. This is wrong. You have to
run it through the server. Let us break those out and
let's say MC Equip weapon. Let's connect it here.
And let us connect this weapon type to it so it
is correct when it plays. And let us compile now. Now we can go ahead and
click on Play to see if everything works or
if we have any box. If I click on play and I select terrorists and
I select them here, now I click on one, you can see I play
the reload animation. If I click on two,
I reload as well. Now let's see if it
blends with our running. If I run and I click here, you can see I'm actually
running and I'm reloading. If I click on control
and I reload, see I actually, if
I just click on the spring arm and
make it 500 so we can actually see what it looks
like, I click on play. And if we take those now, let's do it now. If I switch, you can see I'm actually crouching and
reloading as well. It is working now. Everything
is working correctly. Awesome. So now I'm
clicking on the spring arm, make the target arm
length zero again, and everything is working. Now we also need to
add it somewhere else. Because when we loot the
weapon from the ground, right now it is not playing. Whenever you loot the items
or here in the lot weapons, whenever you loot the item here. When we set the lot weapon
equipped weapon type, we also have to
play the animation. So it's correct. Let me just
move this a bit away here. And let us call it
again MC Equip weapon. And let us add in whatever
the weapon type is. It is this one. Go ahead
and make a rear route node, and now we have it correct here. So we're going to organize things a bit more
just like that. Okay, so now it is inside of here as well in the loot weapon. And now let us click on play. Now whenever I loot my weapon, it's actually going to play this animation before
I can shoot my weapon. So this is how you add animations to your
weapons as well. You can add them through animation montages
and you can make a upper body movement as well
for the animation montages, so you don't disrupt
your running animation while you do all of this. Okay, so that was it for now. Let's save everything and let
us move on to the next one.
123. 9.08 Setting up the Weapon Display Widget: Now it is time to create the weapon display widget.
So let's go ahead. In the UI over here, just like before we created
the team selection I, let's now right click and go to User Interface and create
another widget, blueprint. Now for this one,
again, user widget is the one we're
going to select. And let us call it B. I'm
going to call it main. This will be the main
UI that we have. We haven't created a
main NuwI for the game. In the main Nei you can
see your weapons as well. Let's open this one up. Remember, whenever you start on a widget blueprint,
you have to use canvas first, adding
a canvas to it. And right now we are
ready to design it here. However, we still have
not imported the icons. So let me just save everything.
Let's close this down. And I want you to go into the course materials
that I've given you, going to the UI icons, and I've given
these icons to you. So go ahead and select all
of the gun icons again. You might see different
items inside of this course materials depending on when you download this. Because right now
I'm just adding more stuff as I go
with this course. There might be more icons than what you can
see here right now. Have these three icons. For now, let's go to icons folder. Let me just click and
drag them into here. Again, just like what we
did with the other ones, remember we changed the
texture group to UI and the compression settings to user interface two D. Let's do that with
these three as well. Now you can click on them
and set them individually. However, you can just click on one or hold control
select all three. Right click, go to Asset. Action, Bulk Edit
via Property Matrix. Remember this is how you
edit all of them at once. This is something
we've done before. We go ahead and click on it. In the compression, I
believe it since out of here the compression settings
here, it is going to two user interface, two D, and the level of detail, you can set it from world to UI. So now we can close it down
and we can save everything. All right, so now when we go into UI and inside
of the main UI, and if we, for example, add an image to the screen, you click on it up here for
the image to find the image, let's find the icons
we have added. And here you can see
the icons that we have. All right, so let's jump over to the next lesson where we
design this widget blueprint. For now, let's just
delete this one. Let's keep this canvas
because we need it. And compile, save everything,
and let us move on.
124. 9.09 Designing the Weapon Display UI: Okay, so the thing we
want to do right now with the weapon display is just
like in Counterstrike, where you can see here at the side you have the
weapon and then you have the key on the
keyboard that you need to press to view that weapon. So just like that, so we're
going to do the same thing, and the UI will be more visible whenever you have
this weapon selected compared to the other
ones and so on, so just a small effect. Okay, for now, let me
close this and we are going to create this very
simple weapon display UI. Now when you design
something like this, you have to think of which
boxes do you want to add. So we have the horizontal box and we have the vertical box. First, we need a
vertical box because the weapons are on
top of each other. Let's choose a vertical box. Place it in here. Let's just resize this somehow so
I can drag it around. And I'm going to drag
it down here somewhere. Again, remember to
change the anchor point, else it will be wrong
on the screen here. Clicking on the anchor point, setting it down to
the bottom right. And also for the
position I'm going to write 00 to see where
it is on the screen. And you can see it is
outside of the screen. Remember, you can adjust
this in the alignment. If I write 0.5 here, you can see it now snaps
to the middle of it. And if I write one, it
snaps to the other side, as well as for Y, If t 0.5 it snaps to
the middle of it. And if I write one, it
snaps to the other corner. Now even at position 00, it is inside of our canvas, and this is what we want
for the position x and y. I can give it something
like -30 here and -30 here, just to push it away
from the edges. It isn't on top of the screen. Here's the screen edge. Okay, let's compile. Now
what we need to do is we have a weapon and we
have the keyboard key. Beside it, we actually
need a horizontal box. Now a horizontal box inside
of the vertical box. And now we can add the image of the weapon as well as the
text for the keyboard key. Add those into here. Let me just click on the text, and let's write one for now. This is the keyboard key. And then you can
click on the image. Let me just select the image. If I search for icon
AK 47 for example, and I wanted to be
in a larger size, instead of 32 by 32, maybe we can write
something like 130 by 130. Remember, before you fully
design this correctly, remember to click
on the screen size. Go to laptops, for example, and select the generic
14 to 15 notebook. This is just like
what I showed you before with the team
selection widget. This is to scale this UI
correctly on all devices. Whenever I am at the
zoom one by one, this is what it's
going to look like on the laptop, this is
what it looks like. Now you can see if you
click on this button here, I remove the dash lines. I usually do that to see what it looks like without
all of these lines. I think this is large
enough for a laptop. Let's compile. Remember,
we scaled it to my screen. For example, I have
a four K monitor, and we scaled it by clicking
on this small icon. And then we selected here
how much we wanted to scale. I think previously it was eight. So it's scaled very quickly. I put it to 2.5 Yeah. Now let's click on this number. I'm going to align it to
the middle vertically. I think this is now clicking
on this horizontal box. Actually what I'm going to do is click on the vertical box. And clicking on Size To Content, the vertical box
is simply going to size compared to whatever
content it has in it. What we can do is, for example, for the horizontal
box, I can control D, and this will copy it
past this up here. If you just control D to
copy or duplicate it, you can see it pastes the weapons up here and
that is looking correct. I just need two of them.
I don't need that many. I'm going to click
on the number first. Actually, I'm going
to delete this one. I'm just going to stylize one of them and I
can copy paste. I'm going to click
on this number. I'm going to change
the fund to something. We have imported ruby. I think Simy Bold will
be fine for this one. We can always test
it out for the size. I think 22 might
be a bit better. 22, we need a space
between these two. Go up here, search for spacer and place them between
the image and the text. And then you can put
some space between them. For example, if I make it
20, something like that. Or you can make it even
more if it is too little. I think it's fine for now. Now what you can do is click on this horizontal box
control D to duplicate. And now you have
it, for example, for this one you can
change it into a pistol. Now, it doesn't really
matter right now because we are going to change it
dynamically in the game. This AK will be one weapon. If I go to the
blueprint weapons, if I can find it here, the weapon here, 44. This will be the
icon, or this one. If you have picked up
44 instead of an AK, these images will change
dynamically in the game. It doesn't really matter,
but for these numbers, this is one, this is two. And this is what I press
on the keyboard to get these weapons to be
equipped for me. All right, so that was
it for stylizing it. You can see it's
very, very simple. It's a very simple UI, but it's going to look
nice in the game. So that was it for now. Go ahead and compile
and save everything, and let us move on
to the next one.
125. 9.10 Displaying the Weapon Display UI: Now we are going to display
this UI to the screen. Now you can do it yourself
if you want some training, because we have
done this before. Try to figure out how you can
display this to the screen. After the team selection widget. Whenever we select the team, I want to display this main UI. Try to figure it out yourself. It's good training if you don't remember
or if you want help. Let's do this together.
Let me close this down. First, what I need to
do is I need to go to the blueprints. Go
to the player control. Remember in the player control we have all of the UI where we made this show
hide widget event. In here, I want to
show my main widgit. Now we use this enumeration, I need to add it to
the enumeration. If I go to Enums, I click on the game widgets. Inside of here I'm adding
a new enumerator and I'm writing name or not name. I'm going to move it
up here to the top just to stay more clean.
Doesn't really matter. Then I'm going to go to the Player controller
here, just like before. Right click, create widgets. Then we can create
the main widgit. We can search for it here. I'm going to right click
and promote this to a variable and call it WB main. Now we are going to
drag from here and add to Viewport, just like this. Now just like before, I'm
going to drag this main out, right, convert into
a validated get. Then when it is not valid, I want to create the widget. However, if we have
created it before, I'm going to go ahead
and just add it to the viewport directly,
just like before. Try to organize this. When you are finished
just like this, then you can go
ahead and compile. And remember also to go to the hide widget inside of here. Just like before,
let's take W into a validated get and drag from
here and say remove from. Remember also to do
this whenever you want to, maybe some now. It doesn't really happen
too much with the menuI. You don't remove it too much. However, if one
case, for example, if you have a cinematic
or something like that, you don't want to
display the menuI. This is also how you remove it. Let's go back to the
event graph now. After the team selection, remember here in the player
controller at the bottom, we made this CL spawn player. We spawn the player, we
hide the team selection. Now here is a good
place to show the Maui. Remember UI is client sided. Whenever you work with UI, you have to run them
on the client here. What I usually do
is I'm looking for a client event that we already have made
which we can use. This CL spawn player is
running on the client, so this is a really good
place to show the Maui. I'm going to drive
here and say Show Hide widget, like we called it. And I'm going to
select the menuI. I'm going to click on
Show and connect it. Now just a reminder,
if you forgot, it's going to select the
Maui and it's going to select Show up here in the show. Hide widget. It knows
it's the menuI. It knows that this
bulletin is true. So it's going to go here. It knows it's true. So it's
going to show the widget. Now it knows which widget it is, because we have selected
the main widget, going to go inside of here. And it's going to run this
code from the main widget. And it's going to
ignore this one. It's only running
this one up here. And we're going to add the
main widget to the viewport. So I don't think we
are missing anything. So let us go ahead
and play and select, for example, counter terrorist. And then you can see
I have my main UI. If I maximize my screen, I have the main UI here and
I can see it on my screen.
126. 9.11 Coding the Weapon Display Functionality: Let's now code the functionality
for the display UI. Let's go to the UI
and let's open it up. Essentially, before
you start coding UI, you just have to think, what is it you're trying to do? The thing I'm trying
to do is I want to change this image to
whatever I am holding. I want to display and remove it, depending on if I have
looted the weapon or not. So let's start with
the first one. The first one, I'm
just going to change the image name so
it's not confusing. I'm going to call it IMG rifle. The next one I'm going
to call IMG pistol. Now to use them
here in the graph, you can see we don't
have any variables. We have to click on both of
them. Select both of them. Two is variable, so you have
to take that and compile. And now we can see we can use them as variables
inside of here. I'm going to delete
all of these and let us create a custom event. Let's just call it
update inventory. I update inventory
I inside of here. Basically what we are trying
to do is we're trying to take this image pistol for
example and image rifle and we're trying to say
set brush from texture. This one set brush from texture, this is simply just when you
are changing this image. We want to change this image depending on if
we're holding the K, the info or something else. Set brush from texture and here is the
image we can change. The other thing is we're
trying to either show or hide this icon depending on if we have looted
the weapon or not. Again, dragon from this set visibility
and select this one. I'm going to copy paste
this one down here, Coppa this and connect
the image rifle as well. This is what you're
trying to do. I'm copy pasting this
as well just like this. These are the functions
we're simply going to use. This is always nice to do whenever you are going
to start on something. Try to think what is the main
thing you're trying to do. You're trying to
change the image depending on which
weapon you have looted and you're trying to set the visibility to
hidden or not hidden, depending on if you have
looted that weapon or not. Okay, with that one. Now, it depends on which
weapon we are looting. Is it a pistol or is it a rifle? Remember, we already
have a variable for that and this is the E weapon type. We're
using that a lot and let us call this
one weapon type. Okay, so we have this one and
we can drag from here and say switch has authority. Actually switch on
enumeration this one. Now, depending on
if it is a pistol, we're going to run this code. Depending on if it is a rifle, we're going to run this code. And I'm just going to connect all of this here,
just like this. Okay, now for the images,
for the textures. Instead of setting
them over here, I'm just going to click and
drag them into this event. And I'm going to
call it dumb nail. We can drag this
into here as well. Okay, let us compile now.
Let us save everything. All right, so the only
thing we're missing right now is the weapon thumbnail. Because remember,
we haven't added a weapon thumbnail to the
weapon infrastructure. So we need to do that
in the next lesson. However, before we end this, we also need to set
this visible or not. So now the weapon visibility is going to be visible whenever you have
loaded the weapon. However, if you have
not loaded it yet, it will be hidden. So to do this, what we can
do is we can just check if this image thumbnail or weapon
thumbnail is valid or not. Because just like before, if I go back to the
player and player base, remember just like
how we could delete variables like this
by not setting them to anything and they
will be not valid. We can do the same thing here
for the image thumbnail. We can set it to nothing
and it will be not valid, and that means we have
dropped the weapon. What we can do is we can
drag from here and say is valid and we can
choose, this one is valid. Just like before we have,
or we have worked with the select notes we
can drag from this and say select and choose this one. Now I can connect this
bullion to this one here. Okay? If the weapon
thumbnail is not valid, is valid is false, that means we want
this to be hidden. Now for this other one, if it is true, it is valid. We want it to be
non hit testable. Remember, non hit
testable means that your mouse cursor can't
interact with this image. We don't really need to do that. What we need to do
is we need to click on it here and hold control. Click on the second
one and also set the visibility to
non hit testable. Visible means your mouse
can actually click on it and it will block
anything behind this. But we don't really
need to click on those. I need to set them
to non hit testable. And do the same thing
here for the text. Set them to non hit testable. Down here in the visibility also by default I'm going
to select these two and the visibility to hidden, We don't really need to see
them when we start the game, we don't have any weapons. We're going to set it to non hit testable whenever we actually
loot the weapon here. Do the same thing here. We're
asking if this is valid. We can actually just
copy paste this one. Copy paste it, plug it in, and also plug it up here. Okay, so here I have created some route notes and
organized the code a bit. Here we have the
code, and this is the main code for
our inventory, UI. Now let's go over to
the next lesson and create this weapon thumbnail
inside of our structure.
127. 9.12 Adding Weapon Thumbnail to Structure: Let's now add the weapon
thumbnail to the structure. Let's go back to our structures and open up the weapon info. And let us add a new
variable and call it a thumbnail here. For the thumbnail, the type
it is is just an image, so it's a texture two D. This is what they are
called. Go out and save. Now let's close down
this structure. Let us also add it
to the data table. If you open up the data table
from Google sheets that we created earlier and you open up the data table inside of here, let us add the variable inside of the structure.
I'm going to just push it up to here
after the type, Maybe over here just
to make it more clean. It doesn't really matter
where you move it, but now I need to add it here. After the type, I need
to add the thumbnail. If I look here after the type, I need to add the
thumbnail here. I'm going to right click and
add a column to the right. Then I'm going to call
this one thumbnail. Remember to call
it the same name as what you called it here. Now we need the
references to them. If I close this down,
I go to the UI. I open up the icons, now I can write, click on
this AK and copy reference. I can go back to my data table and paste it here for the AK. Do the same thing
here for the info, right click copy reference. Paste it here, right click
copy reference for the pistol. And paste it here as well. Now have you go
ahead and download it as a CSV file over here
in the downloads folder. I'm going to rename Weapon Info. I'm going to copy
this, the old one. I'm going to delete it. I'm going to paste the
name here, DT Weapon info. Remember this is
the same name as what we called it here
inside of our data tables. And now we can click
and drag it into here, and it says successfully
reimport it. If you open it up, you
can see it actually has icons attached to it now. Okay, now we can close it down. And now let's go over to the player and open
up the player base. Inside of the player base, we want to update the UI when we loot the weapon here
in the lot weapon. Let's go down here in
the Servalote weapon. We need to call this UI update
event inside of a client. Remember, UI is
client sited and we don't really have any
client events right now. What I'm going to do is I'm
going to right click over here and make a
new custom event. Call it CL for client, let me just call it Update
inventory, UI for example. And run it on the owning
client and is reliable. The thing we want
to do here is we want to call our B main. Remember it is inside of
the player controller, we have this WB main. And inside of the B main, we can find our event
that we created earlier. We need to access this WB main, which is inside of the
player controller. Try to see if you can do it yourself and call
this event here. This is good practice
to communicate between blueprints.
Let's do it together. Now Let me just
right click and say get controller to get the
controller for this specific. Then I can drag
from here and say get player controller reference, we made that from our
blueprint interface. And then I can call
my WB main variable. Then I can drag and
update inventory. I event update inventory. I go ahead and connect
it for the weapon type. I'm just going to
drag it into here, as well as the weapon thumbnail. I'm just dragging
it into the event. It creates a variable automatically and I'm going
to create some route nodes. Now when that is done,
let's go ahead and compile and save
everything over here. Whenever we loot a weapon, I'm going to call it, after I equip this, after I change
the equipment type here, I'm going to push this away. I'm going to push
this away as well. I'm going to push this away. Then I'm going to call the CL, update weapon or Inventory UI. Now instead of setting
the weapon type, let's just drag it from
this looted weapon. I'm going to click and
drag it into here. Make a reroute note as well. Also for the weapon thumbnail. Now now we have it inside
of our data table. When you get the weapon info, you also get the information for the thumbnail,
which you can see here. If you don't see it,
remember to tick this here. Remember we click Hide unconnected pins, and
we only see this. Now you can also click
on the Spin to show the thumbnail and we
can plug it into here. All right, so now
we have it here. We have it plugged in now. It should work whenever
we loot a weapon. Let's just try it out.
Before we continue, let's click on play. And when we click Play
as the terrorist. I allude to this
pistol for example. And you can see the pistol is now showing down
here in the My UI. When I allude the for, it is not showing the P.
We need to fix this one. It is not showing the for now. It is weird because it should
be the same code here. Whenever it is, the infor, we are not unarmed anymore. So here in the weapon loot
right now or lot weapon, so we are not unarmed. So it's actually going
through this part of the code up here and it's
skipping all of this. We need to actually reconnect
this to a correct one. I'm going to hold control
and Alt to disconnect this. Alt. Click, sorry. Alt and click to
disconnect this. Then I'm going to move
this here from the false. I think it's better if
we connect it to here. Instead, let us
connect it to here, This is more correct and let us compile now
and try to play it out. So if I play select terrorists, now I pick up a form
and then I pick up the pistol and you can see
both of them is now working. We need to fix the thing where we now drop a weapon and now it should
remove from our UI. Let's copy this here, and let's find the drop weapon. Now over here for the drops weapon code
and the drop weapon, I'm going to go inside of here. And now we're setting
the dropped weapon and we're removing it
from the inventory. You can either do it here or
here. Doesn't really matter. I'm just going to do
it inside of here. I'm going to paste it. And we need to have
the weapon thumbnail. So this is the weapon to drop. What I can do, I can
just take it from here, weapon to drop, and I
can connect this here, so it looks more clean. I can take this as well. I can say again, we're
actually doing it all here. Instead of copy pasting it, let's just use this one.
Let me move it back. And then I can use
the weapon type and I can use the thumbnail. And let us just
structure it better for this one. Let's
reconnect it. Let's move it back. Just like before, we can
always create a rear. Actually, we don't need to
create a rear out node. We can just place it like this here for the weapon thumbnail. Actually, before
we click on play, it's actually not like this. Remember, when you
drop a weapon, you don't want to
set a thumbnail, we want to set it to nothing. Here in the UI, it says it is not valid, and when it is not valid it's
going to hide this icon. We click ahead on play and we go ahead
and loot the pistol. Loot the rifle. And if we drop the rifle, for example, you can see
it is removed from the UI. If I drop the pistol,
now it is removed. If I pick up the AK, you can see it's now showing the AK icon. If I pick up the pistol, if I drop the AK and
pick up the info, you can see it's now
showing the info icon. So everything is working
as it's supposed to. And that was it for now. So in the next one
we can try to. So whenever you have
a weapon selected. So right now if I have
the pistol selected, the pistol should
be fully visible. However, the info icon
should be barely visible. So you know what you have
selected from your inventory.
128. 9.13 Unequipped Weapon UI Opacity: All right, so let us
continue the code here. What we need to do
right now is we need to change the opacity for the
images in the designer. If you click on one of them, for example the AK, if
you click on the tint, if you click on the
arrow and see you can change the alpha so you can make it visible and not visible. So this is what we want to show whenever we have
selected the pistol. For example, I'm going
to make it one again. And let's go to the graph. We can take the image pistol
and we can say opacity. If you don't know
what it is called, just search for
the word and then you can see which
one is best to use. This is sometimes
something I use. If I'm creating a new mechanic, I can just write the word and then try to select
whatever makes sense. We want to set the opacity
for this image set opacity. Now it depends on what
our equipped weapon is. Equipped weapon is
inside of our player, this one equipped weapon type. Because this one right
now, we can't use. This is just the weapon we have picked up
from the ground. This is necessarily not the weapon that we are
equipping right now. We need to get this variable. And the way we do this, again we need to communicate
with the player. Inside of UI, we have
something called get owning, get owning player. If
you want a reference to the player controller,
Get owning player. If you want a reference to
the player pan for the I, we want a reference
to the player Paw. I'm going to say get
owning player pawn. Then we can drag from here
and say get player reference. Because we already
have made this inside of a blueprint interface. Let us just connect
it after those here. It doesn't matter which
one of them it is, it runs the code and then it
continues running from here. We want to get the equipped, this one get equipped
weapon type. Again, just like before. I'm going to move this and say switch on enumeration connect. Now let us take this. If it is a pistol, we want to set the opacity
to one fully visible. If it is a rifle, let's copy this actually
without this one. Let's say set opacity
if it is a rifle. From the pistol. Right now
we have equipped the pistol, the rifle would be
at 0.25 visibility. For example, the opacity. Now we can copy paste this here and we can connect
it to the rifle. The pistol now is 0.25
and the rifle is one. Now that we have this finished, we can go ahead and
compile and save everything. Now it should work. We have to call this one. Remember this update
inventory UI? We're actually not calling it within our event where we actually select
weapons down here. When we select the primary and secondary weapon over here. We're not calling the event where we update
the inventory UI, we have to call
this one as well. Whenever we equip weapons, this one here updates. We have to do that. Let's
go to the player base. And let me just move this away. Remember we are in the
Serva equip weapon. Whenever we switch
to the primary and secondary inside of here. After this one again
I'm going to call CL, update weapon I, I'm going to check here
the weapon type we are equipping it is this one weapon type two
equip we are using. I can just connect this here and make a re route
node for the next one. The weapon thumbnail
is we can actually get it from this
weapon variable, we can drag it here, get the name, search
for name variable, collect it just like before, get weapon info, and then we can drag
from here and break it. Then we can get the
information here. We have the weapon type
and we have the thumbnail. Technically, you can just
plug this in here as well. Doesn't really matter.
I'm just going to plug in the thumbnail.
That is fine. And I'm going to
click on this one and hide unconnected pins. And now we have this finished. I'm going to just take this closer and
everything looks good. Let's compile, save everything
and let's test it out. Flic complain now
select terrorists and I can pick up the pistol and
I can pick up the four. You can see the M four is not as visible as the
pistol right now. If I select the M four, it becomes more visible. So now I can see I can
switch weapons like this. If I drop it and I select
the AK or pick up the AK, I can drop the pistol. And now the AK is not visible because I
have not equipped it. But if I equip it,
it's going to show. Now you can see how this works. It is a lot better than before. Now we can actually see
what we have equipped. It's just a nice game design, so we can actually, we
have some visual changes. Okay, now this is finished. Let us do some sound effects. The sound effects for when we actually switch the
weapon and reload them like this and whenever we are dropping the
weapon to the ground.
129. 9.14 Adding Equip Sound Effects: Let's now go ahead and add
the equipped sound effects. First, let's go ahead and
import the sound effects. If we go to the audio folder and sound effects inside of here, I have given to you in the
cost materials in here. If you go to audio and if
you go down here and find the rifle reload and
rifle rifle clip in, pistol reload and pistol clip, these five sound effects, go ahead and click
and drag them into the content browser
inside of here. Okay, so when you
have dragged them in, let's select all of
them by holding, clicking on one of
them, holding shift, and clicking on the
last right click, and create multiple cues. It's going to create all of
these sound cues for you. Now, I'd like to rename
them to whatever we did before here with
the S, the prefix. Let's go ahead and
click on the first one. I'm going to delete
from the end. I'm going to add sound
Q instead of effects. I'm going to do that
with the rest of them. And I'll just skip ahead a little bit and just
rename them here. Now I have renamed all of them. Before I continue, I'm
just going to reduce the volume for each one
because they're really loud. And for this course,
I don't want them to be very loud because it
will be annoying for you. This is the sound here, and
if I click on the next one, maybe reduce it to something
like 0.30 0.3 By the way, you can have Luda volumes. It will sound a lot
better in the game, but I'm just doing
this for my core, so you don't have to listen
to these loud noises. So this is the reloads and
this is what it sounds like. Okay, awesome. Now let me
close it, save everything. Now let's go to the assets and animations
and find these animations. Remember, it's not
these old animations, it's our own animations here. If I search for
any montages now, we can go ahead and
open up both of them. The rifle animation montage and the pistol animation
montage that we created earlier. Okay, cool. Inside of the animation
montage here, what you can do, you can add sound effects so you don't have to do
that inside of the code. Here in the node to F, we
have this bar here, this one. You can go ahead and rename it if you want to
by clicking on it. Click on two on the keyboard. Or just click on
it and maybe call it sound effects or
something like that. Doesn't really
matter. And in here, let's right click and add a
notify and then play Sound. Now let's click on it and we can now choose which
sound we want to play. What we want to play
for the first one is called pistol clip. We want to choose
this one pistol clip because you can see here, we want to place the sound
whenever he reloads here, whenever he takes out the
clip from the pistol. Now what I have
found out is it's a lot better to add the sound before he does the thing
because it sounds delayed. If you actually put the
sound here where he takes out the clip and you
can try to listen to it, sounds a bit delayed. What I like to do
is I'd like to add it before he actually does it. Maybe something like
over here. Okay. Sounds good. Now,
the next one is I don't have to sound effects
for the pistol clip, we actually have to
add the same one. You can click here, control C and then
control V over here. Let's see when we
want to play it. Maybe something like here. Then the last one is
the pistol reload. And I think I'll add it
to somewhere around here. Right click, Add, notify play. Sound Click on it and
find the pistol reload. I think if you search so reload you will find
the one I gave to you. Pistol reload. And by the way, you can see a lot of
sound effects here. And this is because you already imported sound effects
from the marketplace. When you imported all
of these weapons, there are actually sound effects inside of these weapon folders. You can try to use some
of those if you wish to. You don't have to use
the one I gave you. You can search for
pistol reload. That's the one I gave you. That is the sound. You can click on space to listen to it. Okay. To make it sound
a bit more interesting, you can hear the clip
in and clip out. Or clip out and clip in.
They sound the same. Okay? It's not
really interesting. Let's go ahead and change it and make it more interesting. If you go to the audio
and sound effects and click, click on it. But let's click on
the pistol clip and let us duplicate it. If I can find the
button here, duplicate. Let us call it Pistol Clip In. Let's rename this one
to Pistol Clip Out. Let's click on the
pistol clip in in here to make it sound different. I think we have used it before inside of
the course earlier. But you can use this
one called a modulator. And with a modulator you can change the
pitch of the sound. And this way you can
make it sound different. Let's connect it here.
Let's put them together. Now click on the modulator. I'm going to change this
one to 1.3 in the pitch. It's going to sound higher
than the other one. If you try to go ahead and play it, this is what it sounds like. If you open up the other one, the clip out now you can
hear the difference. Okay, we can click on space
here to listen to it. Actually, I think, yeah, we need to switch them out
here instead of clip out. I'm going to change it to
clip in and let's try again. Okay, sounds a lot
better than before, so let's go ahead and save it. And we have to do the same
thing for the other one. If I open up the other
animation montage, and you can do it, by the way here from
the assets browser, you can see the other
animation montage. Go ahead and open it
up just like before. Let's rename this one
to sound effects. Let's right click somewhere
random here and add a notify. Play. Sound Click on the sound. Go ahead and search
for rifle Lip, I believe it's called
Rifle Clip out. The first one is clip out again. I'm going to put it delayed, maybe I'm putting it here. Then the clip in, I'm going to add
somewhere around here, Maybe the right click
and click on it, changes to rifle In the reload, maybe I'll play the
reload somewhere here. Right click, Play. Sound Click on it and
search for rifle reload. Go ahead and select
it and let's try to see what it sounds
like. Click here. Maybe this one should come
early because it sounds delayed. It sounds good. I like it now. And
let's save everything. And that was it for this one. So it should work already. Because these are now
applied to the animations, so we don't need to add
anything to the code. So if we go over here
and select terrorists. And if I just pick up a
pistol for now. Sounds nice. If I pick up the inform
and select it sounds nice. Okay. Awesome. Now
they sound good. Of course we are going to make it look a lot better with the reloading and with
the clip and so on, but for now it was
just the sound effects and everything is sounding
great, by the way. Again, you can use other
sound effects which come with the other weapons that you have downloaded
from the marketplace. And that was it for now. So let's save everything and let us move on to the next one.
130. 10.01 Creating the Crosshair UI: Okay, so let's go ahead
and add the cross. Let's go to the UI folder. And let's open up the icons folder instead
of here, just like before, go to your cost materials
and I have included for you, instead of icons, I've
included this cross for you. Click and drag this into
the content browser. Before we forget,
let's open it up and let us go here in
the texture group. Change it to UI, just like before for the
compression settings, let's change it to a
user interface two D, Let's save it, let's
close it down. Now what we want to do,
let's go to the UI. Let's right click here
and go to user interface, Select Wigid, Blueprint.
And choose the user. Widgid. All of this we've
already done before. Let's call it WB. Rosa. Let's open it
up instead of here. What is the first
thing we need to add? Remember it is the canvas. Let's search for
canvas. Let's add it. And inside of here, very simple. For the Crossa, we
just need an image. We just need the Crossa. Let's go ahead and change
the image to the cross. Select the Crossa, we want
it to be in the middle. Try to do this yourself. We have done this before. Try to make this crossia in
the middle at position 00. Try to do that. Let's continue together what you
want to do here. First, you want to change the anchor point
to to the middle. Then if you write
00 the position, you can see it anchors here. This is because
for the alignment, you have to set it to
0.5 for the Y as well. 0.5 just like this to make it size correctly. Instead of changing the size here or the size here, I mean, you can have this
size to content, it's going to size to whatever image size you have instead of
changing it up here. Let's compile now. Now this is what it looks like. Remember, you also want to
click on screen here and for the laptops and change it to generic, this notebook here. Since this is just a crosser, we don't really need all
of this canvas here. This is just something that is in the middle of the screen. Because of this, we
can actually click on Fill Screen and select Desired. This will just make it
to this small thing here because we just want to
place it to the screen. We don't want all of
the space around it. Selecting desired here
would be correct. Now if you zoom one by one, you can see how small this is. We need to increase the
image and maybe something like 80 by 80,
just a lot larger. We can test it in game later to see if that is large or small. So now we can save
everything for this one. I'm going to click on it again. Go to Visibility, change
it to non hit Testable. And this is because we don't want the mouse to
interact with it. That was it for everything. Let's save this.
Let's close it down, and let's move on
to the next one.
131. 10.02 Displaying the Crosshair: Now let's add the
cross to the screen. And you can also try
to do this yourself. We have done this before. If you don't remember, let's
do this together again. Let's go to the blueprints. Now let's go to the
player controller. This is where we have all of
our UI in the event graph. You can go to your
widgets inside of here. You have to create the
enumeration value for it. If you just open up
the blueprints folder, en folder, and the game widgets inside of here,
just like before. Let's add a new enumerator. Let's call this one cross. Go ahead and save.
Let's go back to the play controller here. Let's right click
Create Widgets here, select Create Widgets,
and select Cross. Right click on it,
promote it to a variable, and call it B cross. Go ahead and add it
to the viewport. Add two viewports,
just like that. Okay, just like before, let's take out this
B cross variable. Let's right click and convert
it to a validated get. Let's connect it here. If it is valid, we can just
go ahead and add it to the viewport directly.
If it is not valid. Let's go ahead and
create it first before we add it
to the viewport. Remember also to add it to, let's see here, the Hyde Widget. If you click on Hyde Widgets and you can also find it here. If you don't have it
open, you can take this cross and rightly
convert into a validated get. If it is on the screen
and we want to remove it, we can drag and say
remove from parents. Go ahead and just organize it a little bit more
just like this. Okay, let's save everything and now let's add
it to the screen. Let's go to the van graph. And I think the
best place to add this is maybe after
you spawn the player, you hide the team selection and you also show
the main widget. Let's go ahead and show
the cross as well. Let's strike from
here and say show hide widget and call
this event we made. Go ahead and select the
cross and select Show. This should work now
compile, let's play. Now let's play as the
client for example, and go ahead and
select Terrorist. You can now see I have the Crossa to the middle
of my screen now. You can choose to adjust the
size of it if you wish to. If you just go to
the UI and go to the Crosier and you can click on it and maybe change the
size to something like 60, 60 if you think
this is too large. And you can try to play it again and see what
it looks like. Maybe something like this is
a lot better than before. Okay, so this is how you add
a crosier to the screen, and let's move on
to the next one.
132. 10.03 Adding Weapon Properties to Structure: Before we continue,
we need to add some properties
to the structure. Let's go now to the
structure here, and let's open it up. The first thing
we want to add to the weapon info is
the shooting speed. We need that. The
next thing we need to add is the muzzle flash. This is the visual effect we want to play whenever
we shoot the weapon. The last one is
the sound effect, okay for the shooting speed. Let's change it to a float. This is just a numeric
value for the muzzle flash. This is a particle
system. Particle system, The visual effect. And
go ahead and choose the object reference for
the shooting effect. Let's just use the sound cue. We are using sound cues here
for the shooting speed, muzzle fly, sound effect. Everything looks good.
Let's go ahead and save it. These variables that
we have created here, we are going to add them
later to the data table, but for now we are finished. We have added those. Now
let's close it down, save everything, and
let's go to the next one.
133. 10.04 Shoot Weapon Input Action & Structure: Now let's go ahead and create an input action
called Shot Weapon. And you can do that
again yourself. Try to do that as practice. Let's go to the player and
open up the input folder. Let's right click, go to inputs
and add an input action. Let's call it a shot weapon. We don't really need to do
anything inside of here. Let's open up the
input mapping context. Let's add another mapping. It should be here at the bottom. And let's select it and
search for shot weapon. Go ahead and select
it. And for the key, we're just going to use
the left mouse button. We don't really need
anything down here. Let us now close it down. Let's open up the player
base and inside of here. So here I can right
look now and search for a shot weapon. And go ahead and select it. Now also before I finish, I see here for the equip weapon.
Let's actually fix this. Now that I realize here for the equip weapon we have
this reload animation. Let's actually just add that
inside of our structure. If you just go to the structure
and open it up and you search or just to make a new variable and
you call it equip, something like that
or equip animation. You can also write the whole
thing, something like this. Equip animation For this one, let's open it up and let
us search for any montage. We are going to use an animation
montage object reference for the equip animation. I'm just going to let it be down here. Let's save everything. Let's now go over here
inside of the code. Instead of doing it like this, what we can do now is
we can remove this, we can actually delete this one. And we can take this montage
to play directly into here. And we can remove
this one as well. This one we can change to equip something like
this or equip animation. And let's just drag it closer. Now what we can do is over here, wherever we have used it, if you don't know where
you have used, by the way, we have used it here, but
if you want all references, you can write click
here and you can search for find references and you can actually see
where we used it. Let's click on the first one. It's just this one. Let's
click on the next one. It's over here. We can go ahead and click on Alt and click
here to disconnect it. I'm also going to
delete this road node. Instead of using
the weapon type, it is this one,
the equip weapon. And we already have the
structure broken down, so we can actually
just click on it. Hide everything here.
Hide unconnected pins. And I can just click on
this equip animation. And I can take and
drag this into here. So now you can see we have a custom animation for
all of the weapons. So depending on what we have
plugged in for each weapon, it's going to take that
animation and play it. So let's compile and
save everything. We have to change
it up here as well. So if I just disconnect this, I delete this road node. And with this structure, again, hide unconnected pins. I'm going to show
the equip animation. And I'm going to add
it over here as well. All right, so now we
have this fixed and reorganized now for
the equip animation. What we can do, we can just add that information inside
of our data table. Let's go ahead and open
up the data table here. I'm going to open
up the data table. I'm also going to open
up the structure so I can see which variables
I have added here. For the variables, let me
just make it a bit larger and go to this place
after the class. Here we added the
shooting speed, we also added the muzzle flash, and we also added a
shooting sound effect. And we added the
equip animation. Again, remember to write them exactly as the name
you have written here. Now for the quip animation,
let's save everything. Let's go to the browser here
and open up the assets. Animation. Search for animation montage
here for the pistol. Let's right click and
copy you reference. Go ahead inside of the
data table for the pistol, which is the last one here. Let's go to the side
for the quip animation. I'm just going to
paste this reference. I'm going to right click
for the rifle reference. I'm going to paste it in for
both the AK and the four. By the way, you can do
the same thing here. And let us just do that for the AK for the shooting speed. Now we have to test this in
the game, I have no idea. Let us just write 0.1
for the next 10.1, for the third 10.1, I don't know, we have to
try this in the game. We have no idea right now. As for the muzzle
flash, what you can do. I think we have some
muzzle flashes inside of this folder where we import all of the weapons
from the marketplace. If you just search for muzzle, you can see these
muzzle flashes. I'm going to use one of them, for example. You can use the. Assault rifle muzzle flash. I'm going to right click it up. Your reference for
the rifle for the AK. I can paste one for the M four. I can paste the same one. Now you can see for
each single weapon, you can actually have a muzzle
flash for each of them. They can actually be unique. They can all have
unique sound effects, They can all have
unique animations, unique shooting
speeds, and so on. So you can see how
nice this method is. It's really dynamic and
it's very easy to change. If you one day wish to
have another sound effect, you can just come in here
and add another reference. Okay, for the pistol one, we have the pistol muzzle flash here and we can right
click this one. We can copy the reference again. And we can paste it here. Now for the shooting
sound effects, we have not imported it yet, so let's actually do that
while we are doing it here. Let's open up the cost
materials folder. Let's go back to the
cost material here. What I want you to import
is the AK 47 gunshot. I also want you to
import the 41 gunshots and also the pistol gunshot. This one pistol gunshot. Let's go to the audio
folder as effects. Let me remove the
search word and you can click and
drag them into here. And just like before, you
can click on all of them. Right click, create
multiple cues. I'm going to open
all of them up here. Reduce the sound here to
0.3 I think I want to reduce them even further
because they are really loud and I don't want them to be allowed inside
of this course. 0.1 for all of them. And let's just try to
play it. Okay. Awesome. Everything sounds good.
Let's close all of them. Now, before we copy
the references, let's go ahead and rename them. I'm going to rename this one to SC and remove the
Q here at the end. I'm also going to change
that for the pistol. Let's remove the Q and let's
write C at the beginning. The last one for the AK. Again, remove Q and A. C to the beginning. Now for the references, let's copy first the AK 47. I'm going to copy the reference. And then here in
the data table for the AK 47 which
is the first one, I can paste it here
for the M four. If we can find it here. This is the four
here. Let's right click copy, reference, paste it. And the last one is
the pistol gunshot. Copy the reference and
paste it here as well. Now let's go ahead and
it's actually auto saving, so let's go ahead and
download it here and the CSV. Now over here I'm
going to rename it. Copying the same name here for the weapon info,
deleting the old one. I'm renaming the new one and
then I'm going to go back to my blueprints data tables and now just take this new data
table and plug it into here. Okay? Now all of this
information is inside of here. You can go ahead and
check to make sure everything looks correct
and everything is good. We can go ahead and
save all of it. Now it should play
it automatically, because here in the player base. Now here in the player
base for the equip weapon, we have now this
equip animation. And it is now playing
it automatically. Because we have defined it in the structure what it is if we just play it now and
see what happens if we select terrorist and
I go out and pick it up, you should see that it
is actually playing it. And for the pistol as well. Now instead of taking it
from the weapon type, all of the information
that we can make unique, we can add to this
weapon structure.
134. 10.05 Creating the Weapon Shot Timer: Okay, so now let's go ahead
and open up the player base. And inside of here let's go down to the event we made
the chute weapon. To start off with that,
let's create the server one right click and
do custom event. And let's create the server
shot weapon inside of here. We're going to create
a timer first, put it on replicates on server
and reliable for shooting. We are going to create a timer just like the other
timer we created here for the footsteps where we created the set timer by event. It is the same method we are
going to use for shooting. If we go down here and we
drag from here and say timer by event and go
ahead and select it. Then from here we can drag
and make a new custom event. We can call it Shot Weapon Loop. Okay, the shoot weapon
logic will be down here. Remember to set timer to be looping and then we
have to set a time. Now the time you set here depends on how fast your
weapon is shooting. For AK 47, for example, let's say it is
0.1 for a pistol. It's going to maybe for pistols, if you don't want to make
them shoot automatically, we don't really need this timer. But for automatic weapons, AK 47 and the info they need to be shooting
through a timer. Because it's going
to loop the code at this speed since this one
is the speed of the weapon. Remember in the structure, if I go back and open
up the structure, we have added this
shooting speed variable. We can actually use
that to plug into here. Depending on how fast
your weapon is shooting, this timer will change the time. Depending on that we need a reference to the
weapon, so let's do that. Let's click here and
make a new variable. And choose weapon base here, from the variable types. Go ahead and select that.
Let's call this one weapon. We have to call
this one up here. Call it server shoot weapon. I can spell that like this. Server chote weapon. Now we have to
define the weapon. Now if you compile, you
can see you'll get an era. And it says new parameter. Even though it says
weapon up here, sometimes this happens and you just have to delete
it and make it again. Or you can click on file
and refresh all notes. And that will actually
fix that as well. Okay, we need a definition
to the weapon right now. We actually, we don't
have a variable or the weapon because the
only thing we have is we have the equipped weapon, but we also delete
that later on we have unequipped weapon and we
have lot weapon as well. Up here we have
the looted weapon. However, we are also leading this looted weapon
variable over here. We really don't
have any variable for the weapon that
stays consistent. Let us actually just create one. Let's go to the
equipped weapon here. When we equip this weapon, I'm going to just right click the same variable and
promote this to a variable. Let's call this one
equipped weapon. This one is equipped weapon. We are equipping the weapon. And this one is the
equipped weapon. And we can use this variable. We don't delete this. This will change every
time this is being set. Remember to click
on this variable and set it to replicated. We don't really need to
notify anything replicate. It just means that
we're just sending this information to the client. The client also knows
what this variable is. I'm going to just select all
of it here and move it away. And moving this
variable into here. Now we have that variable
we can work from. Okay, we can go down here now. And we can take this
equipped weapon and plug it into here.
Now we have that. Let's compile now from this one. We can drag and say we can get the name variable
and then we can get weapon info, get it here. And then let's move
this away and break. And now we can use the shooting speed from
here and plug it into here. Okay? So click on it and
hide all unconnected pins. Okay, so whenever we press
our mouse one button, it's going to shoot
and shoot this timer. Now we also have to stop this timer as well
at some point. So let's right click
this handle promoted to a variables and call it
a Shot weapon handle. And we can use this
handle to stop the timer, so we have to know when are we shooting and when
are we not shooting. When we let go of the
mouse one button, then this complete
trigger will be played and we are not
shooting the weapon anymore. Let's actually add a bullet
in here. Let's add one. And let us call it shot weapon. And I'm just going to add a B in front of it to stay consistent
since it's a bullion. And change it into a
bullion like this. Okay. Now you can drag
from here and say branch and connect
it if it is true, If shot weapon is true, we want to go ahead
and shoot the weapon. However, if we don't want to
shoot the weapon anymore, let's take this handle
and say is valid. If this handle is valid, just making sure
we're not getting any box, making sure it's valid. And let's make another branch. If it is valid, go ahead
and take this timer and say clear and
invalidate timer by handle. We are going to stop this
timer up here in this code. We can now copy paste this. And for the complete, when we let go of the
mouse one button, it's going to set
shoot weapon to false. When we shoot the weapon, it needs to be true
when it is false, when we stop shooting, it's going to ask,
is this timer valid? If it is, go ahead
and stop the timer. I'm just going to reorganize
things a little bit here. Right now we have this done, let's go ahead and test it out and see if everything
is working. And let's go ahead and click on play here for the
client for example, I'm going to select terrorists. Let's go ahead and
pick something up. Let's pick up the
info right now. Let's try to shot. Right now, I'm
trying to shoot with my mouse one and
nothing is happening. Nothing is printing to
the screen up here. Let me just cancel it
here we get an era. This era is saying access. Access none just means that it's trying to read something
from this weapon variable, this weapon variable here. However, access non means
that this variable is empty, it doesn't have
anything to read from. This is actually true
because we have only set the equipped
weapon inside of the equip weapon event. And this one is only set
whenever we switch weapons. If I go to terrorists
and I pick something up, I have to switch to
another weapon and then switch back before this
variable is set right now, let me just shoot
now and see what happens and nothing
is happening. This is actually because we're running this
multiple times. If I disconnect this false, you can see here if I
don't stop the timer, you can see it more clearly if I just pick up
something else again. Now, if I shoot the weapon,
I'm shooting right now. And if I let go of
my mouse onene, whenever I let go
of my mouse one, it's actually printing. This is what we want. We want to make it print whenever we
press the mouse one, not when we let it go. This is because the timer here is running very
quickly in the code. Whenever I'm holding my
mouse one button and it never gets the chance to
actually play this code. This part here, we actually
need to do just one time. Let me just reconnect
this here from the true. I'm going to do a one node. Whenever I hold down
my mouse one button, it's going to do this code once and then we can reset
this code whenever we want. I'm just going to move
all of this away. And this one I'm going to
make a new custom event. And let's call this
one and shoot again. When can we shoot again?
We can shoot again. Whenever we stop
shooting up here, I'm going to call
this, can shoot again. And just like that, that is the only
thing we had to do. Now let's give it a try again. Let's compile and
let's test it out. Let me select terrorists. Let me just pick up the weapons. Now we are going
to fix this issue. This is again, a problem with
the looted weapons up here. So I'm actually going to
do a hard fix in a bit. I just want to see if this down here works and we can
go ahead and fix this. So if I pick up the weapon and if I hold
down the mouse one button, you can now see it prints
to the screen correctly. And if I let go of the mouse
one, it stops printing. And let's actually do that
as well with the rifle. So if I just like terrorist
pick up the rifle, pick up the pistol and if I switch back and forth to
get the variable to set, right now I can hold the mouse one button
and it's shooting, and if I let go, it is
not shooting anymore. Okay, so this code down here
is actually working fully. Now we're finished
with this one, and I'm also going to
delete this print string. Let's go up here and fix this. Before we finish, let me
just remove it from here. We're just going to do a
very nice fix for this one. It never box again Down here
in the overlap weapons, this is what you're
trying to get. Let's just take
this one and say, is this equal to the
looted weapon variable? We're trying to check if the, the one we're currently
looting is set to the same variable as
the one we said earlier. If it, if it is true, we want to delete
the old variable. Let me just move this over here. We want to delete the
old looted variable. Then after that we want
to run the new variable. With this locked in, we're basically just
checking if the thing we're looting right now is the same
as what we said it earlier. If it is, we're going to delete this variable before
we set the new one. This, make sure that we don't
set the same one twice. If it is not the same thing, if it is not the same
item, we're looting. Just go ahead and run the
code without deleting this. Okay, I'm going to
organize this later on, but let's see if it works. Before I try it out, let's connect this
again. Here we are. Removing the item
from the inventory. I'm just going to click
and drag it back to here. Go ahead and compile
now let's try to click on Play and select Terrorist
and see if it works. If I walk into here, you can see it actually works. Okay, This is how I think that's actually a
better method to do it. As you see, it's not
bugging out anymore. The next thing is, I'm actually noticing
the icons are wrong. Let's just debug this. Let's go back to main widgit, Let's open it up and
let's go to the graph. I'm just seeing what's up
here, why it's doing this. For the rifle, we have the
image rifle, image rifle. That is correct here. For the equipped weapon. For the pistol, we're showing the pistol
and hiding the rifle. And for the rifle, we're showing the rifle and we're hiding
the pistol, the opacity. This seems correct. There's something wrong with setting the equipped
weapon type. Let's go back to the player. There must be something that goes wrong with the
equipped weapon. For the equipped
weapon. Let's see here, this is the update inventory UI. We're setting the weapon type to the weapon type to equip
the weapon type to equip. We defined it here when
we press on the button. When we press on Primary, we're setting to rifle, which is correct.
That is our rifle secondary, we're
setting it to pistol. That is also correct. Nothing is actually wrong here. Then something must be wrong when we allude
to the weapon, when we allude the weapon
over here, looting weapon, we're setting this as well, we're setting the
weapon type as well. To the one we just alluded, which is also correct. There's actually not a
mistake anywhere here. I suspect maybe there is a
mistake in the data table. If you open up the data table, let's take a look, the
data table type here. So we have to look for
the type of weapons. If we have written
something wrong, Rifle, rifle and pistol. They're actually all correct. They are set to the correct. Okay. Nothing is actually wrong. I can't see any mistake. Maybe right now, the issue is that we are setting the
equipped weapon type correctly. However, we're also
running this code. And this part of the code, it doesn't realize yet that it has been
set to this value. If we just make a delay and we give it a
chance to set this, just to take a look
and see if this works, because I don't really
like to have a delay here. But let's just take
a look and see if that actually
fixes the problem. If I loot the weapons,
I click on one. If I click on two, now that
works as well. So you can see it actually works.
Now if I click on 1.2 now the icons are working. The problem here we have is that this is being set
correctly, the weapon type. However, you're also running
this code really quickly. So you're running
this code before this has had a chance
to actually change. Okay, to fix this problem, we can try to add a delay. However, in this code, let's actually do that
inside of our WB main. Inside of the function here
that we created earlier. Here is when we set the
opacity for the rifle. Before we set the opacity, you can try to add a delay and the delay, please start
by making it very small, 0.01 and compile. And
let's click on play. And if that works then
it's actually really good. Now I can pick everything up and see the pistol is now picked up. And I'm just going to
maximize my viewpoint. The pistol is now picked up. I can click on 14. Click on two for the pistol, you see sometimes we get a buck. I switch to my rifle, let's set it to 0.03
Instead, compile. Click on play. Let's try again. Let's pick up everything.
Click on rifle, pistol. Rifle, pistol. Now everything seems
to be working as well. Okay, so that works. So 0.03 fixes the
problem as usual. And that would be a really, really nice, easy fix. Okay, so I know it has been
really confusing here, but we really had to do this because this was bucking
out all the time. So if the equipped weapon
ever bucks out down here, it's not really
bugging out right now. So I'm just going to let it be. However, if it ever
bucks out, like up here, you can do the same method by checking if the
equipped weapon here. You can always
check if it is the same as the previous
one that we have set. Then you can remove the variable and then you can
set the new one. So instead of doing it in
the old method, however, I don't think this will bug out because up here
we're checking if we already are
wearing a rifle, but in the future
we might get a bug. I have no idea right now. We have to develop and see. But that's how it is
in game development. You get bugs during the programming and
you have to fix those. The good thing for
a programmer is just to know how to
fix those problems. And here you see we
just added a bully and just checking if this
was the same or not, and we fix that
problem this way. You always will see
when you develop games, even in large studios. But you just have to know how to fix them and how to
overcome the problem. Let's now try it out. Let's click on play
just before we end this to see if
everything is working. And if I select the terrorist, I pick up everything here and
I can switch between them. If I drop the four, I'm just trying the
dropping right now, the dropping, you can see
it is bugging out as well. So we have to add
a small delay here because it is not realizing
that we have deleted this. If I said the delay to
0.05 And I click on play. And click on play here. And let's pick up a weapon. Let's drop it. Let's pick it up, drop it up, drop it, drop it. See, now it is working perfectly and I can
switch between those. I'm just trying to test out the game to see if it bugs out. Now it seems to work fine. We had to have this
small unnoticeable delay because else the program didn't know what we
were doing here. That's nice to know
having that here as well. That fixes all of
the issues we had with this variable being
deleted without us wanting it to delete it
before it ran the code. So everything is working now. I'm going to reorganize this. I'm going to put
it inside of here and let us move on
to the next one.
135. 10.06 Line Trace By Channel: In this lesson, we
are going to create a line by channel function. This way we are going to shoot the bullet
from the weapon. Let's go ahead and
click on the player and open up the player
base inside of here. Let's go down to the
code we wrote before. At weapon, here is where we want to add the
line trace by channel. But before that we
have a small buck with the equipped weapon when
whenever I loot a weapon, if I click terrorist, I lot something. If
I shot right now, it doesn't give me a buck
because I switch the weapon. However, if I don't
switch the weapon, so if I directly just pick this one up and
I start shooting, going to give me an error here, because we're only setting
the equipped weapon whenever, we're actually switching
with our keyboard keys. Let's copy this equipped weapon. And let's go up wherever we load the weapon over here
in the looted weapon. And we're going to set
the equipped weapon whenever we go through
this code here, whenever we are unarmed, we are going to set the
equipped weapon here. After this delay here. Let's go ahead and paste it. And let's connect it. And I'm also going to move all of this away
so I can see here. And I'm going to
connect it here. And then drag from the
looted weapon to this one. Again, you can rear
out notes here, make some, and
make it organized. So that should be
working well now. Now we're also setting the equipped weapon whenever
we are looting here. Okay. So I'm going to
move this away as well. Increase the size of the
comment, something like this. Okay, so that now is fixed. The next thing I want to
do is here in the weapons. So let's go to the weapons
and open up the weapon base. Let's now hide these spheres. We don't really
need them anymore. I'm going to click on
the collision sphere and select it again.
Here, hidden in game. And I'm going to do that
in the weapon base. So it does that for all of them. If I save now, and then I try to play the game just to check
if that is fixed. And you can see here
that is fixed now. Okay? So we don't really need
this spheres anymore, Okay? So let's go ahead and make
the line trace by channel. So let's go down to the code
we wrote before down here. Let's start doing it from here. Whenever we loop the code, let's drag from here and
write line trace by channel. Let's select this function. Now, it looks complex, but it's actually really, really easy to understand the line trace by channel. It needs a start location and
it needs an end location. The start location is
wherever you are right now, and the end location is
wherever I am aiming right now. With micros, this is
what we have to tell it. The way we get this
information is if you write click and first we have to
access the player controller. Now try to do it yourself. If you remember how to access the player controller,
we can do it together. Now you can write
get controller, you can get the
controller of this play upon just like before, we have this get player
controller reference from the face. You can now
drag from this, if you just write camera, we want to get something
called a camera manager. If you just scroll
through all of this, try to read what we have. This one, get player
camera manager. With this one, we
are able to get precisely where we are aiming
at with our cross sale. Getting this camera manager, we're going to
drag from this and say get camera location. This is our start position. The start position right now
is wherever I am right now, here, standing
here as the player in the middle of my screen. Now we have to tell
it the end location is wherever I am aiming
at with microsa. The way to do this first
is let's drag from this and say get
at forward vector. So we're getting the
forward direction for this camera manager. Then we are taking this
and multiplying it. The reason why we
are multiplying, let's just right first here
and let's change this pin. We don't need it to be a vector. Let's change it into a float. Let's multiply it with
something really big. For example, 20,000
something like that. The reason why we do this is we're getting the
forward vector, so the forward direction
of this camera. And then we're
multiplying this by a lot because we want it to reach the distance over
there at the wall. We're multiplying it. Then we have to say plus. Here we're adding
the start location. We're adding the start location together with this line
for the end location. That way we get
the end location. You can imagine here
I'm standing as a player and we're getting
the start location. This is where I'm
standing right now. And we're basically just creating a line and we're
adding it with the start. And that will make it be there at the end where I am
aiming at right now. Now it's very confusing to understand as a beginner or the first time
you ever do this. But try to think about
how this makes sense. Now, when we add this together, let's add it here to the end. And that should do
it. So remember also to connect
this execution pin. And go ahead and
make reroute notes. Okay, now this should
work over here. Now we have something
called out hits, and you can see it's a blue pin. And if you have noticed before, we have used blue
pins before because our weapon info is actually
a blue pin as well. A blue pin means that this is a structure with
structures like before, we can drag and say break, we can break structures, you have all of this
information that you can use. You can take this line
trace by channel. So you can take the line
you have made here and you can get the location at where
you actually hit this line. You can get the actor that you hit with this line
trace by channel. You can get the
time, the distance, And a lot of things here, we don't really need
a lot right now. The only thing before we
do this is we want to drag from this bullion
and do a branch. Because we don't
want to continue our code if this is not valid. Whenever we actually
hit something, we want to go ahead
and continue the code. Always nice to have this else you will
sometimes get an era. The next thing we have
this blocking hit. Whenever we actually hit
something with this line, we want to continue
the code as well, make a branch here as well. Also, we want to
make sure that it is the player we are hitting
to make some damage. Because we don't want
to hit any random actor with hit act just like before.
We have done this before. Say actor has tag then
you can write player. Remember we added
the tag player. If you don't remember,
you can click on, I believe it's the
class defaults. And if you search for tag, remember we added the
tag player to the actor. The actor has tag player. We have that for all of the players because we have
added it to the player base. Now we can drag
from this and say pull if we are
hitting something. So we have a blocking hit, the actor we hit is a player. Then we want to go ahead and apply some damage.
Okay, with this one. First we can just write
a print string to see if it is actually
working over here. For the debug, you can actually change
this to persistent, because then you can see
the line you are shooting. And you can see
if it is actually doing something wrong
or something correct. Also for the actors to ignore. You don't want to
shoot yourself here. Ignore self is already on, but I have some like sometimes when I
develop in my own time, I like to drag from
this and say make. Now you can make an array and then you can drag
from here and say self. Now it's actually going to
ignore this player here, actors to ignore self. And it's already
doing that here. Maybe this is unnecessary, but I just like to have it here. Safety. If you want to
block other actors. So you don't ignore
other actors. So you can't hit them.
You can always click on the plus and add
another actor here. But for now, let me
right click here and remove this array element. Okay, that was it for the line
trace. And let's compile. And let me just click on
play and see what happens if I play as the server
and select terrorists. And I select, for example, a weapon here and I shoot. And nothing is
happening right now. Let me just quit here and let me take a look at why
this is not playing. It is actually playing,
but it's playing. A bit delayed. If I just try again and I just hold my mouse,
it's actually playing. You can see it's now
creating the lines. Wherever I shoot, it's actually shooting to that
distance over there. Whatever I am aiming, but it's shooting
at a late response. And the reason why it does this is we need an initial shot here. Because whenever
we are shooting, remember the time you
set here for a timer, it's actually going to take
that time before it plays it. For example, if, let's say
I wrote three here for my timer and I compile
and I click on play, there goes 3 seconds
before it actually shoots. Now I'm holding my
mouse and you can see after 3 seconds it's going
to shoot the shot here, the time you have
set to it here. It's actually going to wait that time before
it begins looping. To fix this, we need an initial, like shooting event
that will run this code once before
we run the code here. And that's how we
fix this issue. Let us do something called
an initial weapon shot. Let me just drag from this
and make a custom event. I probably need to move all
of this away so we have some space to work
with this event here. I'm just going to call
it initial weapon shots. This one is just running one time to make sure
that this is running before this timer by event is running here after the once. This is only going
to be run once. So we can say
initial weapon shot. So it's going to
shoot just one time before we actually
start shooting. So we don't have any
delay in the shooting. Let's click on play now. And if I pick something
up and I shoot, you can see it shoots. It shoots immediately. We don't have to wait
for anything now. It is working. And
let's close this down. I believe we get an
error right now. If I don't have anything
and I try to shoot, you can see I can shoot something and I
also get an error. If I click on it, it says
there's an arrow with this one. For this, we can
do something here. Whenever we shoot the weapon, we can make sure that we
actually have a weapon. The way we do this, we can either right click
here and convert this to a validated get and go ahead and do
something like this. We can also do something else. Let's keep this and let's take this equipped weapon
type and right from this and say if this is not
equal to the unarmed state, we can go ahead
and shoot because it doesn't really make sense to shoot whenever we are unarmed because we
don't have a weapon. Let us connect this. Later on we will probably
if we don't have MO. When we add MO, if
we don't have MO, we don't want to shoot either. We are going to add that later whenever we add the
MO to the game. All right, right now we
are shooting the weapon. However, we are not
hitting the player. If you see here, if
I click on play, I take the terrorist here, I take my other client and I select terrorists like
take a weapon here, let me just take
it as the server. If I shoot as the
server on the player, it is hitting the player. However, nothing is happening. You can see whatever
I hit something, the line behind
it becomes green. And that means it knows
that it hits something. However, we told it that we only want to react whenever it is
the player we are hitting. Whenever it's not
the player, it's not really going to do anything, but it knows that
it hits something. However, for the player, it's not really hitting anything. Let's go ahead and adjust the collision settings for the
player in the next lesson.
136. 10.07 Adjusting the Player Collision Settings: All right, welcome back.
Let's go ahead and adjust the player settings
here. Collision settings. So let me click on the Mesh. And let me go down for
the collision settings. Whenever we are
hitting something, we need to generate a hit event. I'm going to enable the
generates hit event because we need that also when we do damage and health
and stuff like that, we need to generate a hit event. And for the collision here, if you take a look
at the line trace, we are using the
visibility channel. Now for line traces, you can change this. If you go to the project
settings right now, we're not going to change it because we don't really have
any problems with this. But in the future if we have a problem and we
need to change it, we are going to change it. But for now, let's keep
it like visibility. But I'm just going to show
you where you can change it just in case in
the project settings. If you find a collision, if I just scroll through and we have
something called collision, we have something
called trace channels. This is a line trace. You can actually add a
new channel to line trace and then you can select that
channel that you have made. You can actually use a custom
channel for this as well, But for now let's use
the visibility channel. And if you click on the mesh here for the collision presets, I'm going to change
it to custom. Then we are going to,
for the visibility, we are going to
say block because we are using the
visibility channel. Now let's keep it like that. If we have a problem later
on we can change it. Let us compile everything. Right now, we're
actually using like a precise collision because
we're not using this collision component
capsule component, we're actually using this
mesh to make the hit events. Let us now click
on play and see if it says hello when
I shoot the player. If I take this weapon
here as the other one, I'm going to select terrorists. I'm going to pick this one
up. Now this is the client. I'm going to shoot
on the player. Right now, nothing is happening. Let me try to do that
on the, on the server. If I hit on the server, you can see it says hello. However, on the
client right now, it's not saying
anything to fix this. Since this is multiplayer, the client doesn't really know what the start location
and end location is. Because you can see here,
the server knows what it is. However, for the
client over here, if I just try to play again and show you
before we fix it, if I pick something up and for the terrorist client
as the client, if I just, so let's say I
shoot here on this wall. The line race is by automatic. It's not really going to show on the client because remember the line race you are doing
is playing on the server. The line persistent here, the debug line will never
show on the client. Which is normal because you're running this
on the server. When we take a look
at the server as well here you can see I
shot at this wall. However, for the client, it actually looks like
you shot over there. It doesn't really
make any sense, however, from the server. And I shoot over here,
I should correctly. You can see here, I hit here. However, for the client, it's not even over there.
The way to fix this. Now this is multiplayer, so it doesn't really know this. We have to actually drag
this further into the event. Let's strike this start. Let's strike the
end here as well. We need to move this code. I'm going to disconnect
this code here. And let's move this away. We have to move this back
to the beginning here. The reason why we
do this is when we run this code on
the client as well. Because we're not really
setting anything. That is fine. If we're not setting anything, it is fine to play
it on the client. We're running it on the
client also knows what the start and end location is and that's how
you fix this code. Let's go ahead and
plug those in here. Now, let me just move this away. Let me organize this. Let me move all of this
closer to this one. Now it's just this code here. Let me create some reroute
nodes for these vectors. Okay? Something like this. Now that is taking
care of, let me away, let me take this
code and move it down. We have some space up there. Now for this code, after this is valid, we have found out that this
equipped weapon is valid. We can then go ahead
and plug in this code. Let's go ahead and plug it in. And let's move this away again. Let's plug the start to this
and the end to this one. You can also just move this down so you can see
what is going on. And you can go ahead and
connect this if you want. You can just take all of this. You can right click and
collapse this to a function. And you can call this function, or you can just make
it more descriptive. Get a bullet bullet line trace locations,
something like this. Since you're getting information and not setting anything, you can go ahead
and click on Pure because you don't really
need to run it through this. And you can double click on it. Go ahead and just organize
this function as well. Make sure everything
is logged in. And that should be good to
go something like this. You already have this done. Now let's go back to the graph and let me move
everything a bit closer. You can see it's a lot cleaner to just make
it into a function. And let's rename those
two bullets start location and this one
bullet end location. Now we have this done, we can compile for this one. We don't really need
to do anything because we're stopping this shooting.
We don't really need this. This is the important
thing here. Okay, we have this plugged in, and I think this will work. Now let me just
move up this here. And let's click on Play. Let's try it out. Now let's
try it as the client. And let me pick something up. Let me try it as
the server as well. Picking up the, as the server. Now I can shoot this player. And it says hello as
well as the client. It should say hello if
I shoot the player and if I shoot the player, it's
actually saying hello. You can also see on the server, the line is actually
drawing correctly. It actually shut on me as well. Let's say on the server, I'm shooting here as
the client as well. I'm shooting here. You see it is actually
shooting precisely. Now this is fixed. It now knows where I'm
actually shooting. Now if I hit the player,
you can see it says hello. As you can see how
precise it is, if I hit the player here, it says nothing because I'm
not hitting the player mesh. If I hit the player, he example,
let me shoot the player. You can see it says hello. Let me shoot the
player. For example, over here it says hello. If I shoot the player
here, it says hello. I shoot the player up here. It doesn't say anything. It's also really good. This one is hitting the
player up here because the mesh itself is
actually not really good. It bows down, but you
can see for example, if I play as the
counter terrorist, that is like how the
meshes are right now. If I just play as the counter terrorist
and I maximize this, it should say hello
as the server. If I shoot here,
you can see hello. The line trace is not showing because we
are on the client. Remember, if I just
shoot up here, for example, you can
see saying hello. If I shoot over
here, it says hello. You can see this one
is more accurate, this mesh here, compared
to the other one. It's also how you make the mesh and how precise
it is and so on. So you can see the difference. I can shoot here and it says hello, because
I'm shooting him. However, if I shoot up here,
it's not saying hello. It's very precise with
this collision as well.
137. 10.08 Creating the Muzzle Flash Sockets: Before we can add
the visual effect and sound effects
for the shooting, we need to add a socket for the muzzle visual effect.
Let's go ahead and do that. Let's go to the
weapon we are using. I need to find the
skeleton for the weapon. The easiest way to find it, instead of just looking at
the marketplace folders. You can open up the weapons, open up the K for the AK. Click on the weapon and
click on this small icon. This will automatically take you in the content
browser to that weapon. Now go ahead and open the
skeleton for the weapon. And inside of here,
just like before, we need to add a socket. Already see that there
is a socket here. Let me just actually rename it. I'm going to rename it
and call it as a prefix. And muzzle, we can just call
it muzzle. That is fine. Or we can call it, just call it muzzle. And let's go to the other
ones and do that as well. Let me go to the weapon
again, Open up the four, open up the pistol, click
on the click on the weapon, click on this small icon,
it will take you there. And then open up the skeleton. And for the skeleton here, for the muzzle flash, we can now right click and say add sock it for this one
again, call it muzzle. Just call it the
same on all of them. Muzzle for this one as well. I'm not sure if we
need to rotate it. This one you can see X is the
forward axis for this one. I think it needs to
be rotated this way. Let's just try to do that. Let me click on it again. And I'm going to snap
here for the rotation. And I'm going to
rotate 90 degrees. This way the X is actually
pointing forward. Okay, let's save this and
let's go over to the pistol. Now let's open up the
full blueprint editor. Go to weapon and click on this
small icon for the pistol. Now for the pistol, open up the skeleton here for
the muzzle flash. It actually has
one here as well. Mo eject, it has
the muzzle flash. This pack here is more
advanced than before, but for this one, let me
just rename it again. Let me call it muzzle. Now we have a socket
for all of them, and we are going to
use it inside of our character to attach
visual effects to the weapon.
138. 10.09 Shooting VFX & SFX: All right, let's go
back to the player and open up the player
base once again. And now we are ready to add the visual effects and the
sound effects inside of here. Inside of here,
what we need to do, we need to run
through a multicast. Again, because we need to show the visual effects to everyone as well as the sound effects, we need to run
through a multicast. First, let's just
create the multicast. Let's right click and
say Custom Event. For this custom event, let's
call it multicast weapon. Now for this one,
let's put it on. Not run on server, but
multicast and reliable. For this, the simple
thing we want to do is spawn emitter at location. Or actually let's
do spawn emitter attached because we're going
to attach it to the socket. Go ahead and saw emitter
attached and then we have to select what emitter are we talking about? That one. If we go to the structure and open up the
weapon structure, we have this muzzle
flash particle system that we added earlier
to our data table. We can go ahead and just plug this in. We are
going to use that. I'm going to rename this to Shooting Visual
Effects or just VFX. I'm just going to call it VFX. And the attach to component, I'm going to actually just
plug it in here as well. I'm going to move this
one up to the top. And we need to attach
it to the weapon. I'm going to call it weapon now, this one is the bone we
need to attach it to. The bone we called muzzle. Just write the
name here, Muzzle. The name of the
socket you created. Then the location of this effect that we need to
play now for this emitter. If we used the spawn
emitter at location, then we actually needed
the location for this. However, this is just the
location within the socket, and that should just be 000. That is fine. Now we also
need to play a sound effect, Drag from here and say
play sound at location. Now for this sound effect, remember also in the structure we made this shooting
sound effect. We just need to plug it into here and we will add it later. Let's call this
one sound effect, the location of the sound
effect, that one we need. Let's drag this into here. We can just say
location. That is fine. Let's compile and
let's save everything. Let's try to play this up here. Before we do the line race, let's try to play the effect. If I drag this away, I call this multicast
chute weapon over here. Mc chute weapon. This needs to be plugged
into it as well as this one. So both of those events. Now we need to plug in
all of this information. The weapon we are using
is this weapon over here. If I drag from this
and I actually need to get the weapon variable, if I just search for
weapon variable and get that static mesh
or skeletal mesh rather that we are using here, we can click and
drag this into here. And now that is plugged in. Now the visual effect depends on what we have inside
of this structure. You can just use it here we
already called the structure. You can click on it and click on the pin for
the muzzle flash. And you can plug it
in and also click on the pin for the
shooting sound effect. And you can plug
that in as well. Now for the location, we just need to get the socket location for
the muzzle flash, that is where we want to
play the sound effect. You can also just get the character location
or act a location. No one will notice like
you can just say get actor location and
just use that. And it will play wherever
your actor is or character and no one will really notice that it's not
coming from the gun. However, if you want it to
come precisely from the gun, you can just take this and
say get socket location. You can do that
and you can write the socket muzzle and you can take that and
plug it into here. That is also more
precise for this one. All right, so I created
Smyroute nodes, so this is a bit
more organized now. If I compile and save everything, that
should make it work. Now this start and end, we can also change the name for it. So instead of doing that from the previous lesson,
bullet location, I'm just going to call it
Bullet start location. And bullet the location, it's more like it's looking better and we can
understand it easier. Let us now click
on play and see if this is going to work. Remember if you haven't set your data table information yet, we did that in the
previous lessons. If you haven't set
it, you have to set the muzzle here in, out of the data table. It knows what sound
effect to play and also what F to play as well. Okay, let's save everything
and let's close it down. And let's go ahead and click
on play here as the server, I'm going to select Terrorist. Select the weapon. Now you
can go ahead and shoot. You should hear
the sound effect. You can also see the muzzle
flash is playing as well. Okay. Awesome as the client. Let's try that as well. Let me just go ahead
and pick something up. Let's pick up the K. If
I go ahead and shoot, that is working as well. Both of them is working. Both
the client and the server. If I just go in front
of him, you play it. I can see the muzzle
flash on both of them. If I do that as the client, just to make sure that
it is working as well, I go in front of
here and I shoot it, and that is working as well. Okay, awesome. So
both of that works, and now we are finished
with the code. So if you go back
to the player base, we simply created this multicast and we added that to the server. Remember, a multicast can only run through a server event. We run it through
the server event. We plugged in all of this information and
now we have it working. So go ahead and save
everything, and let us move on.
139. 10.10 Preventing Shooting During Equip Anim: The problem right
now we have is that the player can shoot while
equipping the weapon. If I equip this weapon, you can see I can shoot while
I am equipping the weapon. By the way, for this
course, I'm just going to disable the sound for the weapon so you
can hear me when I'm shooting and it's
not distracting. I'm just going to
disable it on my end. When you equip the weapon, we want to disable the shooting. Let's go ahead and do that. Let's first add a bullion. Let's call this one
is equipping weapon. Let us compile now. We have to set this
through an event. Let's just make a new
custom event. Custom event. And let's call this one
set is equipping weapon. Let's go ahead and
copy that name because I'm going to create
another custom event. We have to run this
through the server. I'm going to call it
server at the beginning. And run this one on the server and being
reliable as well. Okay, you can run
the server one on the normal event server set. This one set is
equipping weapon, just like this over here. What we simply want to
set this variable to be, to be true or false depending
on what we set this to. Let's just drag this into here. And let's drag this into here
as well. Okay, this one. Remember to set it
to replicate it so the client also knows
what this variable is. For this one, we have to
call it through the code somewhere for it to
be true or false. Let's start from over here. We have this play montage
whenever we equip the weapon. Let me just drag
this one down here. Whenever we set the weapon, whenever this is true, I'm making a branch
whenever this is true. Let's call this equip
weapon MC equip. And then we can go ahead and set this equip
animation as well. So what we did here,
we run through the multicast and we actually call this one on the server. So what we can do is we
can copy paste this. I'm just thinking if
we should drag this into here and then
drag this into here, so we can just call it up here. And I believe we don't
really need to do that, Let's just copy this up here. And let me just move this down. Let's paste this one down here. And let's paste in the equip
animation just like before. And let's hide the
unconnected pins. So now whenever we
equip the weapon, we are going to play
this multicast. Okay, so now we have this, let's compile Now what we can do is we can use this set equipped weapon
instead of this one. Whenever we equip a weapon, it's going to set this to true. Let me delete this for now
and hide unconnected pins. Let me call the set is equipping weapon and
let's connect it. And it's going to run through
the server and then call the multicast whenever
this one is true. Here we want to
equip the weapon. You have to set it to
false at some point, else it will be true all the time and you can't
shoot your weapon. Whenever we finish playing
this animation montage, let's call the set is
whipping weapon to be false. We remove it here. Okay? And then when we shoot the
weapon here, shoot weapon. We want to shoot whenever
we are not equipping. Let's take this here.
It's equipping weapon. And right, not bullion, then drag from here
and write bullion. Let's connect it over here. Okay, so we can't shoot
whenever we are unarmed and we can't shoot whenever we are still equipping the weapon here. All right, let us compile. And I'm going to go
up here as well. When we loot the weapon, we are also the equip weapon. Let's delete the
multicast from here. I'm going to do the same thing. You can just go down here.
If you wish to copy this, paste it up here,
Just like this. And that should play
the animation as well. That should fix the problem. And I can delete this here. I can hide the unconnected
pins instead of using the equipped
this one equip weapon. Because this equip
weapon is only being called down here in
the equip weapon. However, we don't really have the equipped weapon up here
when we lot to the weapon. Maybe it's better to use
this one equipped weapon. It's better to use this one. So let me see here.
Equipped weapons. Yeah, we already
defined this before. We call this, maybe you
can just delete this, and let me see equipped weapon, using this one instead. That should work a lot better. Let's compile and save. Let's actually try to play and see if we
have any box here. Let me play here, the Terrist. And try to shoot whenever I
loot the weapon, I can't. And you can see I can
only shoot whenever I finish equipping the weapon. If I drop it again and try to
loot it and shoot, I can't. Now I can, whenever
it stops here. Okay, let's try to
play it as the client. Because it's also very important to see if it
works as the client. I'm just going to write one
player and play as client. I'm going to play
here and test it out. Taking this, and that
is the same thing. I can't really shoot whenever
I am equipping my weapon. This is how it works and
it's only going to play the animation whenever the
equip weapon is set to true. And it's going to set
it to fault whenever the animation
montage is complete.
140. 10.11 Creating the Ammo UI: Now it's time to design the MO UI so we can add
some MO to the game. And to do that, let's
go over to the UI. And let's design it
inside of our main UI. Because it's part of the
main UI inside of here. I want to design it right
under the weapon here. For example, let's take
this vertical box, let's just push it up in the Y. So I have some space
down here to do this. I want to design
something like this. I like showing you what I want to design and you
have to break it down. You have to take a look
at this and then try to break it down and see what
you need to add as the UI. For example, do you need
to add a horizontal box? A vertical box? And what
do you need to add here? First, we need an overlay, because I can see that
we have some text on top of an image
in the background. And therefore, we
need something called an overlay. Let's start here. Let's search for an overlay, and let's paste it here in the canvas panel, in
the vertical box. We are finished with this one. It's a overlay here by itself. And I'm going to place the
anchor to the button, right? And then if we write
00 as the position, we can see it aligns
here for the alignment. We have to write 11. Now at position 00, it is inside of the canvas. Okay, first we need an image. Let's search for an image and
paste it into the overlay. Click on the image,
and let's fill the whole overlay to
horizontal alignment fill. And vertical alignment
fill as well. Okay, Clicking on the image, let's select the image. I believe I called
it panel. Yeah. If you search for panel and
take this image panel member, if it is stretched like this, you can make it unstretched. If you hear in the doors, you change it to a box and
you change the margin to 0.5, Okay, Also remember to
zoom out to one by one. You can actually see the
actual size of this box. You can just resize it. Right now, not really
too important. What I want to do is click on the overlay and actually
click on Size To Content. It's actually going to size to whatever content is
inside of this overlay. When I click on the image
and I increase the size, now you can see I can
increase the size both ways. You can just
increase it for now. We need to design inside first before we actually
know the size of it. First we need a horizontal box
because we have some text, and beside it we have an image. Let's search for
a horizontal box, and let's place it
into the overlay. Let's take the horizontal
box and align it in the middle of the image
here of the overlay. Let's now search for a text. Take the text, place it
inside of the horizontal box. And also take an image and place it inside of
the horizontal box. Okay, now we can click on the text. Let's write something. For example, 30 by 90. You have 30 bullets
right now in the mag, and then you have
90 extra bullets. Now this is going to change
dynamically in the game, so it doesn't really
matter right now. I'm actually going to
write something like 100, 200, so I know it's a fake text, and we can set it
correctly later. Okay, for this one, this is the bullet image and
we haven't imported it yet. Let's go to the
Assets at Assets. Let's go to the UI and
icons inside of here. I have given you
inside of the case materials folder
in the UI icons, this bullet here, click
and drag it into here. And remember to open it up first and change the
texture group to UI. And change the
compression settings to user interface duty. Let's go ahead and save.
Let's go back to our Nui. Let's search for the bullet
and go ahead and select it. Okay. Now I can
click on my text. And let me just zoom in so
I can see what I'm doing. I'm going to change this
one to rubic, semi bold. As for the text now I'm going
to zoom out to one to one so I can actually see
the size of this text. And I'm just going to let it
be at 24 here as the size. Okay, I'm going to click
on the icon up here, so I remove the dash
lines for this bullet. I'm going to align
it in the middle, and I'm going to
make it smaller, maybe 30 by 30. Instead, this is
what it looks like. Okay, I need some space
between these two. And this can be done
by searching for a spacer and placing it between
the text and the image. Let's make the text, or the space here, ten pixels in the x. Okay, here we have it. You can compile now. And what you can do now is
you can click on the image and you can try to
resize it better. Now, now you have the
content inside of it and try to resize it as
like how you like it. Okay, When you're satisfied, I'm going to push this overlay a bit away from the screen, from the edges here
of the screen. Maybe -30 by -30 and
now it is perfect. So let us compile
and save everything. And I'm also going
to select the text, the image and the image
in the background. And setting the
visibility to a non hit testable so the miles cursor can't interact
with them either. Okay, let's compile
and save everything. And now that this is finished, let's click on the
vertical box up here. And now we can move it down. You can move this down, maybe something like this. And I am satisfied with this. We have the ammo and we
also have the guns up here. Okay, you can go
ahead and compile, save everything, and let us
move on to the next one.
141. 10.12 Setting the Initial Weapon Ammo Amount: Let us now go ahead and define how much MO you have
in each weapon. Again, we need to go
back to the structure. Let's go in the structure, weapon info that we have made. Let's make two new variables. The first one we need to know how much MO do you
have in a mag, that weapon max MO in. We need to know how much MO
do you have as extra bullets. So you can see here in
the UI if I open it up. How much MO do you
have here in the mag? And how much MO do you have? Leftovers that you can
reload from this one. I'll just call Max extra MO. What is the maximum that you can
have inside of that weapon? Since it's just a number, it's a whole number, it's not a decimal number. We need to select integer, just an ordinary number. Without decimals, we have
maximo in ma and max extra MO. I'm going to move them up
here and I think I'll move them above the shooting
speed, something like this. Now, it doesn't really
matter where you move them. I'd just like to stay
clean like this. Having those finished,
we can now close it and we have remember to update it inside
of the data table. If I open up the data table and inside of my
data table here, we have to write it the same as we did here in the structure. If I go back to the structure, I open up the structure here
inside of the structure. Now if I just compare
it to my data table, I need now this MO in me and Max extra MO after the class
variable. After this one. After the class
I'm going to write click and say Insert
column to the right. And I'm going to do
that one more time. Let me just maximize this so I can actually see what I'm doing. We can just make
this smaller like and we can write Max MO in Mag. You can even copy
this, paste it here. And copy this. And
paste it here. Okay, so we have that now. And then you have to define
how much MO you have. So for the AK 47 for example, I can have 30 in my Meg and I can have a
maximum of 90 extra bullets. My info could have
for example like 2060 and my pistol for example, 12 bullets and maximum of 24 bullets as extra MO,
something like that. Go ahead again and
click on file to download and download it as a CS file so we can
upload it to the engine. And again, just like
before, I'm going to delete the old one that we made. And I'm going to paste it here, rename it again as
DT Weapon Info. And then inside of the engine, let's go to data tables. And let me just click and drag this into here
so it updates. And if you open
it up once again, you can see that
all of the values here are updated. Okay, awesome. So now we have defined
the MO amount. However, now when
we play the game, the engine doesn't know the initial amount because we haven't really
used those numbers. It's fine. We have written them inside of the structure
and data table. However, we have not really set them to anything right now. Let's go to the weapons and let's do that inside
of the weapon base. The reason why I do it in the weapon base right
now and not the player, is because whenever
the weapon spawns, it's going to set
the amount of MO that it has in the
mag and the extra MO, it's going to do
that automatically. Inside of here, inside of here. Let's right click and
make a new custom event. Let's call this one server. So we're going to run
it through the server. And let's call it
Initialized weapon. It's just a beginner event that's going to run
here in the begin play. If you just call server
initialized weapon and you run this on the server, reliable, just like that, compile Now inside of here what we want to do
is we want to set the current extra MO and also MO in the
mag for the weapon. Let's create two new
variables and we're going to need them later as well.
Let's call this one. I need to change the
name here, MO in mag. Let's call the other one extra
M here in the structure. If I go back and open up the structure, inside
of the structure, this is the maximum M in, this is the maximum
that we can have. This is the current one. We could have shut
our weapon and used our MO when we drop the
weapon on the ground. It's not going to
have the maximum MO as the MO in the mag. It's going to have
this current MO because the player has
used some of the MO. Let's change this into
an interior as well. Let me drag them into
here so we can set them. And remember you
can hold Alts on your keyboard to set
them like this directly. Let's connect them
here, connect this one. And we need to now
set them first. We need to get the variable
here, the structure. And you probably already know
now what we need to do, because we have done
it 1,000 times. So you get the weapon name, you get weapon info, and then you break
this structure. And now you have the Max MO
and Meg and the Max Extra MO. The Max M and Mag, I'm going
to set to the current M and Meg and the extra M, setting it to the
current extra MO. And I'm going to click
on Hide unselected pins. And just like that what
is happening is whenever this weapon spawns this
begin, play is going to play. Whenever we spawn
this into the world, whenever we have placed
this into the world, we're going to click on play. And this begin play is
going to play right away. And whenever this place, it's going to automatically
set the current MO and Mac an extra Mo from what we have
defined indeed data table. All right, so that was it. This was very, very simple. And with these variables
you have to click on them and click on replicated. And also for this one,
click on replicated. Because remember we are
running on the server. And if we don't replicate them, the client has no idea
of how much MO you have. The client will see 00 MO if you have not
replicated them. So remember to
replicate them as well. Both of them. And let's
move on to the next one.
142. 10.13 Creating the Ammo UI Logic: Now let's go ahead in the UI and do the
logic inside of here. Inside of our B main, we created this UI
for the bullets. Now let's click on this text. And I'm going to rename
it to T bullets or MO. Let's call it MO.
And let's compile. Let's also set it to a variable. Because we need
to set this text, depending on how
much MO we have, we need to make it
into a variable. So we can modify it with
code inside of the graph. Inside of here. Let's make a new custom event.
Let's right click Custom Events. Let's call this
one update MOI with this. Initially what we just
want with this is set this text to how
much MO we have. Let's strike here
and say set text. It's always nice to think, what is it you actually want? What are you trying to do? This is what I usually ask myself when I try
to code something. For example, this one here, what are you trying to do? You're trying to
set this text to the amount of MO you have
right now in the Meg, you go to the graph and
you take this for example. You can write Set
text because we want to set the text ultimately. How do we set the text? We need two different variables. This is something
we already made. We need the current MO in Mac. We need to know that,
because we need to set it here and we also need the current extra
MO. Let's call it. Click on here and call
it Current extra MO. Let's change both of
them to an integer. These are the two
variables we need to know and we need to
set this text with. Now you can see we have
two things we need to set. We don't have just one
number, we have two things. Whenever you have multiple
things inside of a, a line of text that you
need to change separately, you are going to use something
called a format text. If you drag from here
and say format text, this is something that
you need to think about immediately when you have two things You want
to modify inside of a line of text,
two separate things. We want to modify this number and we want to
modify this number. Whenever we reload the weapon, we need to format the text. Because we need now to plug in these two variables
with format text. If you write a curly bracket to begin with, let's call this one. You can call it
whatever you want. I'm just going to call it the same name as
here. Current MO in mag. And then you have to
close the curly brackets. Remember it's a curly bracket. You have to format
it the same as here. Because I want the space
here and the and the space. I'm going to click here
and write space space. Because I just wanted
to look like this. You can choose
however you want to make it look like I
want to look like this. Then you have to open up
the curly brackets again, because now I have to define
my second variable here. This one is, for example, current extra MO,
just like this. Okay? Now we have
these two and now log these two variables in. It will automatically plug
them into here and here, which means it will update this and this separate
from each other. This is how you use a
format text format. If I just make it again, for example, another example, you can use it for example, in an RPG game, you could say, for
example, hello. And then you can
say player name. Because maybe it says hello
John, or something like that. I don't know. Whatever
your player name is, it says hello. And your player
name, how are you doing this time of the day, for example, of the
day, for example, Hello, for example, John, how are you doing this
for this evening? Maybe you have like a
day and night system. And in the game you
automatically know if it's evening or morning
or something like that, and you can plug
that into variables. This is how you
use a format text. You can make multiple variables, and it doesn't really
have to be integers. It can be a line of text, it can be something else, an enumeration, and so on. It's very, very useful
to use this format. Okay, now we have this finished, and we can actually use this
to plug in those variables. Let's compile and
save everything, and let us move on
to the next one.
143. 10.14 Update Ammo UI: Now it's time to
update the UI to the actual amount that we
have inside of the weapons. Let's go to the player base. Now, inside of here, let's create a new event. And let's right look here
and make a new custom event. Call it CL because we are working with UI and
UI, our client sided. Let's call this one update, MOU. What we need to do,
just like this one, we need to get the
controller and so on. So now you can see
we're trying to get this controller again and again. It's actually nice to create
it into a variable instead, instead of copy pasting
this all the time. Let's go up here to the game
play of the Player here, where we actually
got the controller. Let's right click and
promote this controller to a variable and call
it player controller. I'm going to move this a bit away here and then I'm
going to place it here. Whenever this player
controller is valid, we are going to set
it as a variable. Yeah, this is fine. And you can even
double click here to make reroute notes
just like this. Okay, go ahead and compile. Now what we can do down here, we can actually remove this, get controller, play controller, because we already have
it as a variable now. Now it gets a lot easier to do. We can even move this
closer, something like this. Now you can actually
do the same over here. We can take the controller. Let's run this on the client before we forget
run owning client, Take display controller,
get WB main. Then you can call the one
we called update MO Ui. Okay, we need two
variables here. We can just plug them inside of this client. In client one. Let me just move this down
a bit, just like that. Okay, and now we
have this one here. So let's compile and
save everything. And this one we need to call
whenever we loot the weapon. So let me just go up here. Whenever we loot the weapon which is over here, loot weapon. And if we go to the side, we need to update the bullets
only if we are unarmed. Because if I have an AK, it's going to run through
this code up here. I only want to update
whenever I actually loot the weapon the first time. Because we don't need to change the amount of MO for
the other weapon. That's going to go on
my back because I have not equipped it
when I'm unarmed. I want to update
my MO over here. We need to extend
the code again. Actually, I'm going to
move this away quite a bit because we keep
extending this code. I have some space to work with. I can move all of this here
away with me. Just like that. We can call update MY this
client one we just made. Then you have to define what is your current and extra MO here. We already made this
variable equipped weapon. This one I'm just
going to click on it and hide unconnected pins. Click on this. So you have
this equipped weapon, we can use that. The
equipped weapon. Remember it's not equipped
weapon, it's the equipped one. Maybe you can change the name
of those so you don't get too confused equipped weapon. And we can get the
current MO in mag. We can also get the
current extra MO. And we can plug those in here. I can actually copy all
of this because we can copy paste this all around. We can copy paste this. Let's compile, let's paste it. Whenever we switch the weapons. Whenever I switch the weapons here in the equip weapon logic, again, we are updating the UI. Then I'm going to
move this away, and I'm just going
to paste it here. Paste it after this logic. And let us go ahead and
connect it. Just like that. Okay, let us compile
everything now. Let's try to see what happens
if we click on play now. And now plays the client. I select Terrorist and
let me pick up something. Then you can see my MO is
actually updating now it says 20.60 If I pick up the pistol, it doesn't say anything unless
I switch to the pistol. Then it updates the MO as well. If I drop this now, now we need to hide
the MO section because I don't
have any weapons. But we are going to do
that in the next lessons. Now we can see here
when I pick up the AK, it's going to update correctly. When I switch weapons, it's going to update
correctly as well. Okay, so everything is
updating correctly. And that was it for this lesson. Very simple. And let us save everything
and let's move on.
144. 10.15 Hide Ammo UI: Okay, welcome back.
So now we need to hide the M UI whenever
we don't need it. Let me just open
up the UI again. Open up the WB main
and go inside of the graph under here,
the update MOU. I'm going to make
another custom event, and I'm going to call this
one display just like that. For this one, what
we're trying to do, again, ask yourself, what
are you trying to do? I'm trying to hide
this whole section. Whenever I don't have a weapon, I click on this overlay. This overlays the
whole thing here. This is the parent
of all of them here. I'm going to rename this
one to V M or overlay. Let me just set it as a variable so I can edit this encode. Let me go to the graph, take this and then
say set visibility. I want to control the
visibility of this UI. We can drag from this and say select depending on if we
want to show or hide the UI. I need a bull in here. I need a bullion called display. If we want to display
or hide the UI, we can go ahead and
connect this to here. This bullying is false, meaning we don't want to display the UI. I want to hide it. Whenever this is true here, I want to display the UI. I'm going to set it
to not hit testable. Again, this means your
means it is visible, but your mouse cursor cannot
interact with this UI here. And we don't really
need to interact with it anyway. Let's compile. And now this here is finished. Now what we can do is let's
go back to the player. And instead of the
player base just like before here,
let's right click, make a new custom vent all
this one display again. Let's take this copy
paste and let's search for display MI.
Let's connect it. Remember to run this on the owning client and
reliable as well. Let me click and
drag this variable into here. Okay, that was it. Let's compile now. Let us choose when we want
to display and hide the UI. I want to display my UI whenever I equip the weapon
or loot it here. Display MOU. If I go over
to my lot weapon and I just go over here and I want to display it right
after I update my MO. I don't want to display before I update my MO because else
it's going to look buggy. I want to update the MO
before I display the UI. Again, let me drag
all of this away. Again, like this, we
keep dragging this away. We have a lot of things to
do inside of here here, we can write CL display
here and connect it. Again, I'm going to move
this a bit away like that. Something like this. Always
nice to say, organized. Okay, so let's
display the UI here. This one again, whenever
we are unarmed, because now we have a weapon. I want to display my UI. Remember to tick this here. Let's compile again. We need this as well whenever
we equip the weapon. If I go to my equip weapon, if I can find it here,
equip weapon here. Again, whenever I update my MO, I want to display my UI
or my MO just like that. Okay, remember also to have
it ticked here as well. Now we need to hide the
UI whenever we drop the weapon over here in
my drop logic weapon. Let's remember we made this function
previously, drop weapon. Let's go into here. Let's hide the UI
just before this one. If I drag this away,
I can paste this. The display MO UI
is going to be, falls here, falls
for the display. And we can hide the UI
whenever we drop the weapon. Okay, let's compile
and save everything. Let's test it out and see
if it actually works. Let's select terrorists. Actually, we need to
hide it by default. You can see it's right now
and we don't want that. So that is the first bug. Let's go over to the main here. Let's click on the overlay
here in the visibility. Let's set it to hidden
by default and compile. And let's click on play again here in the client
select Terrace. Right now we can't see it,
but when we pick up a weapon, it's going to display with the
correct amount of bullets. If I drop it now it's not
going to display anymore. I pick up the pistol,
it's going to display, I pick up the AK. It's not going to
update the bullets unless we switch to the AK. If I drop the AK, it's not
going to display anything. You can see now, it
is working correctly. Whenever we are
holding a weapon, we are going to see it
whenever we switch the weapon. Whenever we drop the weapon, we hide the UI and so on. And let's actually also
try this on the server, so I don't know if I'm playing
as the server as well. So clicking up here,
playing as the server, and I'm going to play
as two numbers or two players and let's
select terrorists. Let's also test it
here on the server. Remember, you have to test
it on the client and on the server to know that it actually works
on both of them. Here I have the client as well and you can go ahead
and select terrorists. And we already tested
it on the client. Everything is working perfectly. Yeah. Everything is working, Everything is nice,
awesome. It all works. We have no bucks, no errors, and that's how we do it. Let's move on to the next one.
145. 10.16 Calculating Ammo: So now let's go ahead
and calculate the MO, because right now whenever
we are shooting the weapon, so if I pick this up
and I try to shoot, we're not really
calculating the MO. It's still 20. So let us
go ahead and do that. Let's go to the player base once again to calculate the bullets. Remember, we have made
this timer down here. If we can find it down here with the line
trace by channel and playing the visual effect
and sound effect over here, We want to subtract a bullet
every time you shoot. Let me just move this
line trace away because we are going to use it later when we apply the player damage. But for now, let's work here. What I simply want
to do is I want to take my equipped weapon
that I have right now and I want to get my
current MO in my mag. Then I just want to subtract
one from it, minus one. And then you can go ahead and
set this current MO in mag. Current MO in mag. And we need to set it. Set
the current MO in mag. And we just minus one from it, we're subtracting a bullet
every time we shoot. Now instead of just
having it like this, we need to drag from
this and say clamp. What clamp does is it
prevents our value from going below zero because we don't want to
have minus one bullet, minus two bullet, minus
three bullet, and so on. We're setting our
minimum value to be zero when we subtract here. We're preventing from
reaching minus one, minus two bullet and so on. That wouldn't make any sense. Now, the maximum for this one, we can just take this
and say we can get the current bullets and
then we can set it here. Now this one doesn't matter. We can even set it to 999. Doesn't really matter right now. But I'm just going to good practice, good coding practice. Take the current extra bullets
and set it as the maximum. Okay, we have that set now. Let me just create rewrote
notes around this one as well. Let's go ahead and connect
this execution pin here. And let's connect the
execution pin here as well. What you can do this one, you can even right click
and promote this to a function or collapse
it to a function. Let's call this function
tract MO from mag like this. Okay? Now we're subtracting and we can just let it be here. Now instead of just
having one bullet, you can even make it
dynamic in the future. If you want to shoot
a bullet and you actually want to subtract
two instead of one bullet. You can even just plug
it into here and you can write MO to subtract like that. Let me just move
all of this away, this, and go ahead
and compile now. If we go back now, you
can see you can write how many bullets you want to subtract for my game right now, I just want to subtract
one bullet. That is fine. Then let's go ahead and make a sequence note because we
are going to reload later. I'm actually going to disconnect this line trace and I'm going to move this
away a bit here. Let's track from here
and do sequence. And choose the sequence node. Now with the sequence note, let's connect both of them here, from the pin here,
from the zero. Let's connect this here. What a sequence note is, it's just used to
organize your code. It's not doing anything
else than that, it's just organizing your code. We're first going to do the effect here and we're
going to subtract the bullet. Then we are going to
lay this line trace. I can move this line
trace down here. I'm just going to move all
of this down here as well, because it looks a
bit messy right now. You can even delete those and just connect them directly here. And I'm going to move
this up like this. Okay? Now it looks a lot better. And now we can connect
this to this here. A sequence node is just
to organize your code. It's going to do the sound
effect and all of that, subtract the bullet, then we are going to create the line trace. Then after that, we are going to do the reloading
because we need to check, are we out of bullets? If we are, we need to
go ahead and reload. Let us go ahead and do
that in the next lesson. This will be a not very difficult but you have to
be awake for that one. For now we have finished, we are calculating the bullets. We can even click on plate
just to test it out for good reasons here and
see if it's box out. Right now we need to actually
to update the UI and let's do that inside of the subtract
amo from mag function. Let's go inside of here
and inside of here. Let's strike from here and
call the CL update MO I. This is what we created earlier. And then we can take
this MO in mag, this is just this one here and the other
one, the extra MO. We can actually just
take this one and create a re route node or just make it lower here and we
can take it to here. Okay, now this is done. Let's compile. Let's
click on play. Let's test as the
client. Let us now play. I'm going to shoot my weapon. It is working now. I'm going to play as
the server as well, taking the weapon and shooting
as well. And that works. Both the client, the server, they are both working perfectly. Okay. Now it is calculating. And let's move ahead
in the next lessons. And you can see, we
can shoot the weapon. You can see if I keep
shooting the weapon, I can keep shooting whenever
I'm at zero bullets. And the reason for
this is because we haven't really
told the engine to stop shooting whenever
we are at zero bullets. And we will do that
in the next lessons. But first we have to calculate the MO and do the reloading. And after that we can add
all of these conditions. But for now, let
us save all of it. Everything is working. And
let's move on to the next one.
146. 10.17 Reload Weapon Animation: Hello and welcome back. Now we are ready to do the
reloading functionality. Now you have to
be very awake for this lesson because
it's going to be maybe a long one also. We have a lot of math to do, so you really need to
pay attention here. Okay, let's do the
reloading first. Let's go ahead and
create a custom event. So let me just right click out here and make a
new custom event. Let's call it set
reloading weapon. So we're going to set
a bull in to make it reload or not run this actually
to run on server. Just do that. Not run on server, that was a mistake, just
set is reloading weapon. Normal event, let's
make a server one down here called set is
reloading weapon. Let's run this one on
the server, reliable. Let's make a new bulling here called reloading and
go ahead and click in. Let's take this and set the
reloading bull in over here. Remember to set it to replicate
it since we're running on the server and the client needs to know if we are
reloading or not. Over here we need to run server event set is
reloading weapon. Let's go ahead and connect
this here as well. Okay, so whenever we are
reloading we want to actually play the montage
for the reloading. Let me just break from
here and make a branch. And let's make a branch here. And let's say if we are reloading we want
to play an montage. And remember the N montage
we need to play through a multicast because
all of the clients needs to see this visual change. Multicast set is
reloading weapon. Now I'd like to just call it the same name as
the main functions. You can name it whatever
you want and run it through a multicast reliable over here. We need to take
the mesh, so this not both of them but
just this mesh here. And you can write
montage and you can play this montage
just like before. This montage to play, you can just connect it here. Let us call it reload M. Let's play this
multicast up here. Set is reloading weapon.
That is the correct one. Then we need to tell it which
montage do we need to play. Now, I don't think we
have any animations. Because if we just go up here, let's take one of them.
This structure here. I'm just pasting
it so I don't have to write it all over again. I can take my equipped weapon
and plug it into here. Okay, so here in the structure we only have the
equip animation. We don't have a reload animation
for each weapon because each weapon realistically has
its own reload animation. So let us go ahead and add
that to the structure. In the structure, open
it up and go ahead and add the reload animation. Let us setage, go ahead and search for
that and select it, just like the one above. Let's go ahead and
save everything. I want you to go ahead and
open up your data table. Because here in the data
table now you can write reload animation. I can copy all of my equip
animations into here. Because as I told before, I don't have a separate
equip animation. But as you can see for
your own game now, you can have an equip animation, separate one, and you can have a separate reload animation. All of this can be
customized really well. Now you can go out and
click on File and download, Download as CSV, and then
you can minimize this here, go to the data tables folder. And here, just like before, I'm going to delete my old
one and rename this new one, and then drag it into
here to update this. Now I can go back
to my player base inside of here montage to play. Now it says zero for no reason. You just have to
click on File and refresh all nodes
just like this. Now I can actually have my reload animation here
and you can plug it in. Okay, now we have this
sorted out and we also need to set this is reloading to be
false at some point. Let us set this is
reloading to be false. And the way we do
this we can just call this again on the server. Remember when you
are on a multicast, you can go back to
the server here. When we complete the reloading, we can say server set
is reloading weapon. We're going back to
the server and we're setting the reloading
to be false. We can actually go ahead and try it out and let's
go out and compile. And that was it
for this one now, we can't really test it
right now because we don't have any reloading
functionality. But we are going to do
that and we're going to calculate the reloading
and so on over here. But for now we have the
reloading animation finished and let us
go ahead and compile, save everything, and let's
move on to the next one.
147. 10.18 Reload Weapon Functionality: All right, so now
we are ready to calculate the bullets
when we are reloading. And before we do
that, let's just add this set is reloading
up here in the code. Before we continue, remember
we made this sequence. So as you can see here, and we are shooting the bullets, we're subtracting a bullet
every time we shoot. However, at the end,
we need to check, do we have more bullets? If we don't, we need to
go ahead and reload. What we need to do is we need to take this equipped weapon, and remember we have
this current MO in me. We can ask if this
is equal to zero. If this is equal to zero, let me just make a branch here. If this is equal to zero, let's just take this
and connect it here. If this is equal to zero, let's go ahead and
say set is reload. Set is reloading to be true, we want to reload whenever we don't have any more bullets. Let's compile. Let's
click on play. And let's see if
it actually works. I'm going ahead here and I'm going to shoot
all of my weapons. I need to be careful because
I don't want to shoot under because I haven't
made conditions for that. If I shoot to zero, you can see it's going ahead and reloading and that is correct. Okay, so it's playing
the animation now. We need to calculate the bullets whenever we are reloading. So let's go ahead and do
that. Let me just move this multicast away because
we need the code here. Now you have to be
really awake because there's a lot of math going on when we calculate
the bullets. Okay, First what we need to do, we need to take the
equipped weapon, we need to find out the
extra bullets that we have. Because if we don't
have any extra bullets, doesn't really make
sense to reload. Now the first thing I
want to ask about is, is this extra MO that
we have in this weapon, is it greater or
equal to? Now let me paste this down here.
Is it greater or equal to the max MO in the mag? Now why we ask about this is because let's
say this is the AK, and the AK has 30
here in the max M in the mag if we have more
than that as the extra MO. Now let's go ahead
and make a branch. And let me just connect
this down here. If that is true, we can simply go ahead and take
this equipped weapon and get the current MO and mag. And set that current MO, and we can just set it to whatever is here
as the M in the, if that makes sense. Because here we found out
that our extra MO is greater or equal to what we
can have inside of the mag. That means the mag can be full. We're just filling up the whole
mag here, just like that. But before we do this, I also need to calculate
whatever we have left in our current MO because we
need to subtract from here. Let's take this extra MO
and let us say minus. What do we need to
subtract from here? We need to subtract how much we have
right now in our mag. If I just search for current
MO in mag this one year, we need to subtract the max MO in mag from
the current M max. Let's just give ourselves an example so it is
not too confusing. It might sound very confusing. For example, let's say my max MO right now
in the AK is 30. Right now I subtract. Let's say I have 27 MO left. In my current mag I only
shot three bullets. Now I have 27 here. 30 which is the
maximum -27 that is 33. I'm going to
subtract three from my extra MO if I had
90 as my extra MO, now I have 87 because I
only shot three bullets. Now the math makes sense
here for this one. Now this value, I need to
set my current extra M here. Instead of copy pasting this. I'm actually just going
to draw from here and say extra M. We can set
that to this value. Let's go ahead and do that. And let's go ahead and
connect this as well. I'm going to make some
reroute notes and re, explain this to you just to make sure that we
are on the same page. All right. So now I have created rear out notes and
organized this. Actually this one we
need to extend it a bit because I can
see that we are getting a buck later on
because we're asking if the current extra MO is
larger or equal than the MO. And if that is the
case, we're setting it, we're setting the current MO to the max MO because
we can afford it, we have enough bullets. However, when we have like, let's say we have
five bullets left. So if I just open up the UI so we can
understand a lot better. Let's say I have five
bullets left here. I have something like let's
say ten bullets left. It's not going to set it to 15, it's actually going
to be wrong here. What we need to do
is we need to ask is the current extra
MO that we have, we need to actually add
this here plus the current. We need to add both of them. We get the current M
plus those together. If those are greater or
equal the max M in max, now it is correct and we don't
get a buck with this one. I know you might need to understand this like
you might need to just post this video and try to understand the
logic behind this. It's just pure math. You
can even write it on paper. It's a lot better.
Sometimes when I create logic like this, I write it on paper, it is in front of me, it's
a lot easier to understand. We're basically just asking, is the current extra MO that you have plus the current MO in mag, are they greater or
equal to max MO? If it is the case like this, that would be false because
the total would just be 15 and the maximum in Mac
would be 30. So it'd be false. And we would do something
like this here. All right, so now
that is correct. And also let's
remember here when we subtract here and set the
current extra MO again, let's take a clamp and let's make sure it
doesn't go below zero. And let's us just
connect it here. The maximum is just
this extra MO. We can actually
just take this one or you can just copy
paste it just for it to see to look a lot better and more
readable like this here. Now when it is false, and I'm just going to
move this bit away, so it looks a lot better. Now when it is false,
what we need to do, we need to take this weapon and we need to get the
current MO in Meg, and we need to set that value. What we need to set it to is let's say it was the
case like this year. We have five bullets left here,
we have ten bullets here. We need to say five
plus ten, that is 15. And we need to set that to the
current amount of bullets. We need to actually
just take this up here. We need to say current
extra MO that we have, which is ten for example, plus the five that is 15. And we need to set it down here. And that is done whenever we don't have any
more bullets left. The extra M plus the
current MO in mag, they are not even larger
than the max MO in the mag. Then we just need to
take all of the bullets, put them together,
and place them inside of our current mag. Something like this here. Okay, now this is taken care of. We also need to make sure that the extra amount
of bullets here, we need to set it to zero. Now, because we have put
all the bullets in the mag, we need to take this,
we need to say extra. We need to say set the
current extra MO to be zero. Now we also have to
remember to update the UI. Let me just save everything
and let's say CL update I. Let's connect this one here, and let's connect this one here. We need to update the
UI after these events. Let me just double
click on this one. Make it look a lot
better like this here. We can now take, no, I'm just going to copy
this past it here. Now we can plug in, let's plug them in
differently here. First, the current MO,
in mag and extra MO. Just pay attention to what
you're plugging in here. Let us compile now and save, and now let us try it out. The reason why I wrote the logic here in the falls
is because I'm waiting for this animation to
finish before we're going to allow the player to set the amount of
bullets correctly. Because I actually,
I don't want to give the player bullets
during the animation. I want to wait for the
animation to finish. When it, it to falls, it's going to play
this code down here. Okay, so you can see you have to be a bit awake for
this code here. Again, feel free to just
pause, take a look at it, get a paper and pen and
just write the values down. Try to do the math and see
if it makes sense for you. Let's go ahead and
click on Play. Play as Terrorist. And let me take the
M four for example. Let me just maximize
the viewport. Now if I go ahead and
shoot all my bullets, when I hit I can still shoot. You can see it's still bugging. I can shoot whenever I
keep holding my mouse. We haven't done this condition yet. We're going to do it later. But if I let go of my mouse now, going to reload and it's
actually going to calculate the bullets correctly if
I just keep doing that. And it's going to reload again. I'm going to do
the last one here. Going to reload again, and this is what it looks like. You can see it bugs
out here at the end. That is because we haven't really done any conditions here. If I go back here and let me take the code we wrote
with the sequence. If I just find the
sequence up here, this is the sequence
we are shooting. And then we're asking here if the current Mo in mag
is equal to zero. This is the only condition
we're asking for. We need to add some conditions so that it doesn't
bug out like this. But for now, save everything, now this is correct, this is what the
code looks like. Again, feel free to just
take a look at it again, I know it's confusing. This is the hardest math so far we have
done for the game, but it's not really
that difficult once you get it down on paper. So let us save everything and let's move on to the next one.
148. 10.19 Shooting Conditions: All right, welcome back. Now let us do the shooting conditions so we don't shoot randomly when we are reloading
and stuff like that. So let us just start up
here with the shoot weapon. I don't want to shoot my
weapon whenever I'm reloading. Right now, we can't shoot
the weapon when we are unarmed or when we are
still equipping the weapon. Also, I don't want to shoot my weapon whenever
I'm reloading. Whenever the reloading
here is false. So not reloading, we can go ahead and add a pin
and add it to here. Go ahead and compile, okay, so that is taken care of. Now, let us go down to this part here on
the sequence here. I don't want to shoot
whenever I have zero bullets. I have to write it here before I play the effect and so on. I need to say if I
have zero bullets, I'm not interested in
playing all of this. It's actually just
the same as this one. I'm actually going
to make this into a function since
we're reusing this, collapse this to a
function and I'm going to call this one is out of MO, make it pure because we're
just getting information. We're not setting anything when the current M Mac is zero, that means we're out of bullets. If this for reloading, if you're out of MO, then you can go
ahead and reload. That makes sense. Now for this one up here,
let's paste it. Let's write n bullion
and select it. When we are not out of MO, we want to go ahead and shoot. If we are out of MO
we don't want to shoot also for the reloading. Let's take the reloading and say if we are not reloading we want
to go ahead and shoot. If we are reloading we don't
want to go ahead and shoot. That is what is
saying right now. Let me just go ahead and
move all of this away. I'm I think very soon clean the whole project
because it's getting messy again because we're writing a lot of code right now. But as you can see
here, if we are not out of MO and if
we are not reloading, then we can go ahead and
shoot the weapons down here. When we are reloading
the weapon, I don't want to reload
twice this one actually, since it's a sequence, it just takes this into account. And when it reaches down here, it doesn't take
this into account. You actually have to add
this down here as well. When you are not reloading, you have to reload here. We don't want to
reload again and again when we are
already reloading. And there's also
another condition now when I shoot my weapon. I also want to make
sure that I actually have extra MO when I reload. Because you can imagine
here, for example, let's say I have 15 bullets and I have zero
as extra bullets. It's actually going
too if I reload, if I shoot the weapons or shoot the MO and
it gets to zero, it's actually going to reload. I have to here ask
if I have extra MO. The way we do this again, let's take the quick weapon and say get the extra
current extra MO. If that is not equal to zero, equal that is not equal to zero, then we want to go ahead
and do all of this. Let me just connect this
here and connect it. We're just making sure that
we actually have extra MO. Before we reload,
let me just take this collapse to a
function again and call this one as extra MO
again, make it pure. Go ahead, let's put it here. And take this down here as well. All right, let's go
ahead and compile. I believe that was it. Let's just click on play. And maybe we are
missing something. We have to try the
game clicking on play. Now I'm going to loot my four and I'm going
to shoot my weapon. As you can see here, if
I just hold my mouse, it's actually not going
to shoot anymore, it's going to stop shooting. So I'm holding my mouse. It's going to stop
shooting automatically. I'm just keeping shooting
here, zero bullets. It's also doing that right now. For some reason it's actually
not calculating correctly. When I shoot my weapon
under 20 bullets, it's actually bugging out. I think it did that in the
previous lesson as well. Let me just take a look at
what's going wrong here. It must be something
up here when we actually subtract the bullet. Because whenever we
shot, it's doing that. It's not here because we are going through and
shooting the weapon. I think it's something
inside of here. We are taking the MO
in the minus one, because we have written one out here that is being set here. And set to the current
MO in it's setting to the correct
variable over here. This one is the wrong one. We're setting the maximum
to the current extra MO. If your current extra MO is one, this one is actually going to be set to one automatically. There is a mistake here. What we need to do, let's this, yeah, let's take this here, let us say name variable. Let's get it here.
Let's get weapon info. Get the weapon info
just like before. Break it down and this
is the current MO. And let's take the Max MO and mag and place it here instead. Let's not use this one, let's just use this one
over there instead. Let me click here and
hide unconnected pins. And that should work perfectly. Now, the bug should be fixed. I believe it happened in the
previous lesson as well. So clicking on Play,
let's do that now. I'm just going to shoot
all of the bullets. And show you now I'm shooting the final bullets
reloads and I shoot. You can see it is now correct. I can't shoot
anymore when I am at zero bullets and everything
is working perfectly. Now I have to check this
for the client as well. Remember, you have
to check the client, even though it works on the
server, it might be wrong. When I drop this weapon
now and I pick it up, you can see it actually has the correct
amount of bullets. When I have ten bullets left, nine, I can drop it. I can pick it up. It has the
correct amount of bullets. If someone else is
going to loot it now I have to test it
with the server as well. If I just bring up
the server here, and I minimize both of
them here as the server, I can drop the weapon
as the client go away. Here as the server, I'm
going to pick it up. And if I just maximize this, it's actually the correct
amount of bullets. If I shoot as the server, now it's four bullets left. Here as the client, I can go out and pick it up and it is four bullets left.
Okay. That is correct. Everything seems
to work perfectly. And it does that as
well for the AK. Let's try to shoot some of
the bullets here as well. Everything is working fine. Okay, we fixed all of the box. Right now, everything
is working correctly. Let's do the reloading with the keyboard key in
the next lesson.
149. 10.20 Reload Weapon With Keyboard Key: All right, so let's go ahead and reload with the keyboard. So let's go ahead
just like before, let's go to the
player and Input. And right click
here, go to input, make a new input action. Let's call this
one reload weapon. And let's open this one up, actually just the
mapping context. Let's add a new mapping. Go to the bottom, select the reload weapon one and go
ahead and press the R key. I'm going to reload
with my R key on the keyboard and
then pressed here, we only play this one time and it will be a
lot more optimized. Okay, over here with the
set is reloading weapon. I'm just going to
make it above here. I reload weapon and
I'm going to have this my input action simply
when we press the R key, we just want to say set
is reloading to be true. We just want to reload
whenever we press the button. However, remember you
need some conditions because you don't
want to just reload. Because right now
if I just play, I can just press on
the R. Right now, for example, let's take this. I can just press R, even
though I have full bullets. I can press an R. It
doesn't make any sense. I can actually press an Re. Whenever we don't have
any weapon equipped, I can press R as well
and that will give us Bucky. We don't want to do that. First off, we need to take
this equipped weapon type and we want to make sure that
it is not equal to arm. Let's drag from here
and say not equal M and we're making sure that
it is not equal to D. Okay, so that is the first thing. Let's just drag
from here and say bullion because we need
to add a couple of them. The next thing is if we
are already reloading, we don't want to press reload, so let us find our reloading bullion
and say N bully in here. If we are not reloading we
can go ahead and reload here. Okay, so let's add
a new pin again. The last thing I want to ask for is if I have full bullets. If for example, let's say
if I have 30 out of 90, for example here, like the AK, I don't want to reload because I have full bullets in my Mac. Just say, let's take this equipped weapon and
let's get the current M. Let's actually just
copy paste the structure. I don't want to write it again. Let's paste this structure
down here for the weapon. Let me just connect the
equipped weapon to it. Now we're going to ask, is
this current MO in mag, is this equal to the MO in Ma? Because if they are
equal, it means we have full MO in our Ma and we
don't really need to reload. I say it is equal. If the current MO
is not equal to the max MO and me, then we
can go ahead and reload. Else we will not reload. Okay, let me just
place it behind all of this like that and let us connect this to a branch and let's
connect these together. Now we're asking, we're
saying if we are not, if we're not reloading and if we don't have the full amount of bullets already in
the current MO and me then we can go
ahead and reload. Let's try to do
that. Let's compile, let's save everything,
and let's click on Plate. If I click on R on my keyboard, we can see actually
I'm getting an error. Let me just take a look
at what is happening here right now. It's just saying
that the era is this one. If I just write spam
R here and I quit, it's actually going to
show me the era that the equipped weapon
is not valid. Actually, I need to have
this to be valid first, let me just drag all of this. Let me take the equipped weapon, right click, convert
to a validated get. Let me connect this. We make sure that the weapon
is valid before we do all of this because when we haven't looted anything before, if we press R, it
will not be valid. Now we're not getting
this bug anymore. Let's go to one of
the weapons now. If I press R now going to reload because
I have full MO. But if I shoot one and reload, then I can go ahead and
reload just like that. And it's going to calculate
the MO correctly. Now you can see it should
say 39, that is correct. And if I shoot four
of them and I reload, should say 35 as the
extra MO correct. Now whenever I shoot
all of my bullets, let's say if it
calculates correctly. Now let me just shoot
three of them and reload. It should say 12,
that is correct. Now let's say I reload here whenever I have
five, Just say 170. That is correct as well.
Now if I shoot all of them, it's not going to reload. And if I click on R, now it's going to reload. There is this last condition
that we need to check for. We need to check for
if we have extra mo. This has extra mo as well
before we can reload. Now all of the box are fixed. Now, we cannot
reload whenever we have zero bullets in
the extra mags as well. I'm going to move this bit down. I'm going to reorganize this a bit later when we are
finished with the section. So let us save everything and let's move on
to the next one.
150. 10.21 Reload Weapon on Weapon Switching: Okay, so the thing is right now we want to reload as well, whenever we are on
the weapon switching. So now you can see
here if I have zero bullets and I
switch my weapon, let me just quickly pick
up a pistol and switch it. Now you can see
if I switch back, this is the pick up animation. It's not the reload right now. I'm trying to shoot
and I can't shoot. I'm trying to reload
and I can't reload. This is because here when
we reload the weapon, we're actually
setting the reloading to be true whenever we reload. However, if we cancel
the animation, we play the animation montage. However, we're actually
not completing it. This will never be set to false. This is why it's actually
bugging out somehow. When we switch the weapon, we need to set it to false
and automatically reload. We can actually do that
in the equipped weapon. Whenever we loot a weapon, we're setting this set is
equipment weapon to be true. We're also doing that whenever
we equipped it manually. Not just picking
it up, we're also setting this set is
equipped weapon. Remember we did
this one down here. Let me just click here, Hide unconnected pins.
We're doing it here. Whenever we set the
equipped weapon and we finish
equipping the weapon. Let's go ahead and
do that Automatic reload whenever we are out of more automatically. Let's just say the reloading
is false because we need to set it to false whenever the player is actually
changing the, the weapon during the
reload animation. Whenever we finish
equipping the weapon, we're automatically going to
set the reloading to false. We're also going to
reload the weapon. The set is reloading. Whenever we don't
have any more MO, what we need to check
for is we need to say is the player out of MO and does
the player has extra MO? Because if you don't
have extra MO, it doesn't make sense to reload. We need those two and we need
to make a branch as well. After that we can go
ahead and reload. Before that we cannot reload, we need to set the
reloading to be true. If we don't have that, we are not going to
reload or do any, just make sure that the
reloading is set to falls. Because when you interrupt it
here through the reloading, when you interrupt the montage, you're never going
to set this to falls and your code
is going to buck out. Now this is fixed,
let's try it out. Let's try to play here
as the terrorist. I'm going to pick up the four
and I'm going to go ahead and shoot if I switch
the weapon now. Now remember the
first animation that it's going to play is
the equip animation. Not the reload then it needs
to reload just like that. Now reloads
automatically whenever I don't have any bullets
left when I switch it. Okay, as you can
see, now I reload. I switch the weapon
and I switch it back. Now I can press R and
it's actually reloads. It doesn't bug out,
just like before. Let's try it out.
Let's try again. If we have, we have zero
bullets and I switch weapons, it should not reload
and it doesn't reload. Now everything is
working perfectly.
151. 10.22 Adding Pistol Shooting: So far we've been working
with the rifle and now let's go ahead and do
the pistol shooting now. This is very easy because we already have the set up done. Let's go to the player
base inside of here. What we're doing right now
here in the shoot weapon, when we are shooting the weapon, we're just going ahead
here and playing the, the timer is looping the code
and we're firing the rifle. Now when we have a pistol
that we want to shoot, we don't want to this timer because we don't want
to loop all of this. We just want to shoot one
gunshot because it's a pistol. Of course, if you have
an automatic pistol, you can just use this system again because it's
an automatic pistol. However, it is just a pistol and I just want
to shoot one bullet. I don't want to run this timer. What we can do here
is we can actually, from this one, you can
take the weapon type here. We already have the weapon type. What you can do is you
can drag from here and say switch on enumeration. We can see which weapon type we are currently firing with. You can go out and
connect. When we are firing with a rifle, we want to play this timer. When we are firing
with a pistol, we don't want to do
anything because remember we're already
shooting one bullet. We're already running
all of this code here. We're already
running all of this here with this
initial weapon shot, because we have called it here. Actually, you're finished, I believe. Let's click on play. So that was a very easy
one if we just click, let's try it for
the client here. Now I can see here, I can't shoot anymore. I'm only shooting one
bullet. I believe that is. Because here we are setting
this, can shoot again. We are closing this one. We're doing this code once and whenever we
shoot one bullet, we're actually not doing more. This is because here
when it's false, remember we already set
the shoot weapon to false. Why does it do this shot again? Try to answer it
yourself if you can. Without my help. Now, I
can give you the answer. The problem is right now is
we never go into this timer. This one will never be valid. Here. We're asking,
is this valid? That will be false because we
have never run this timer. Now, running the pistol to
actually here from the falls, you need to connect it
to can shoot again. And I'm going to make some Mirarte notes and
now it should work If I compile now and I
click on play and select terrorist again
and pick up my pistol. Now you can see I can actually
shoot my pistol without any problem and everything is working as it's supposed to.
152. 10.23 Stopping Shoot VFX on Weapon Switching: But now we have one problem. If I play as the server, for example, actually
let's play as a client. If I play as the client, you can see, try to take a look at me here
on the server one. You can see here, you can see when I shoot
and I switch weapon. If I just shoot
and switch weapon, I can actually shoot the
weapon still on the ground. And the muzzle flash
is beside my leg. And see it looks very weird. Cat shoot my weapon and change and it looks like this and it's all
like bugged out. Actually, we have to
stop shooting whenever we switch the weapon because
we don't want to do that. Let's go ahead and
close it down. The first thing I
want to do here in the hot weapon right now, we're canceling the hot weapon whenever we let go
of the mouse button. However, I also want to cancel it whenever this is not true. Whenever we are reloading
or equipping a new weapon, or we go to the unarmed state, I actually want
to stop shooting. Let's copy this one. Paste it. Let's connect it with this one. Here, let me just push this
a bit away. And here it is. We're canceling the shoot weapon whenever one of
those is not true, we can actually go ahead and click on play and see
what it looks like. Again, I'm going to
play as the client, and I'm going to
take a look here on my big screen to see
what it looks like. So if I just shoot and switch, now it does stop. However you can see there is still one muzzle flash playing. When I switch, you can
see it on the ground. It doesn't register too fast. If I shoot and switch, you
can see it's still playing, that one muzzle
flash on the ground which still looks
buggy in the game. So we need to fix that. Okay, let us do it here. If we find the muzzle flash, I'm going to clean all of
this after this section. We need to have this
clean before we continue so it's
actually easier to work with the muzzle flash is down here where I play
the sound effect as well. Here for the muzzle flash, I'm actually going
to write click and promote this emitter
that we create to a variable and let us
call it muzzle emitter. Let us connect it here Again, I'm just going to play
the sound just to see what it is like
with the sound as well. Let us compile, okay, now we have this muzzle flash. Now we need to stop this
muzzle flash at some point. We need to find an
early here in the code. When can we cancel this muzzle flash early on inside of the code
to make it nut book? Maybe when we are
equipping the weapon. If I just go up here and we try to find
equip weapon here, when we are switching
the weapon over here, we don't really do it. Because here for the
equipped weapon, you're trying to look for
the weapon in the inventory. If you don't have it
in the inventory, if this is false, you're
actually doing nothing. It doesn't really
make sense to stop the muzzle flash if you
don't have anything in the inventory and
you're not switching the weapon here in
the Quip weapon. I think I'll do it
here whenever I actually found the
weapon in my inventory because now my
character is switching to another weapon here. I want to take my muzzle
flash emitter and I'm going to right click and say
convert to a validated get. Then I'm going to
connect it here. If it is valid, let me just move all of this code a bit away
so I can work here. Whenever it is valid, I'm going to drag and
say destroy components, Destroy a component and
then going to continue. However, if it is not valid, I just want to continue. I don't want to
destroy anything. If it is not valid,
just go ahead and continue whatever
you did before. Let's go ahead and take a look
here at the muzzle flesh. What I'm going to do is I'm
going to take this here. Before I do that, actually
here we can also say that you can't do this whenever you are
equipping the weapon. Whenever you are
equipping it up here. When we say set equipping
weapon is equipping weapon, we need to stop
shooting as well. If I just take this weapon, if I can find it here, this one. And I can take it
and place it here. And again, right, not pull
in and I can connect it. If you're not
equipping the weapon as well, you can go
ahead and shoot. I'm going to copy all of
this and I'm going to paste it right before
the emitter place. I'm actually going to,
before I do all of this, I'm going to check if you can
still do this. All right. What we also need to
do here, I believe. Let's go up here in the
weapon found in inventory. Because when you find a
weapon in the inventory, don't want to play the
muzzle flash anymore here. We can also check before we play the emitter and we can avoid it. We can take this weapon found in inventory and put it
here, get it here. Also, I set it to replicate it. It was not replicated. I set it to replicate it because remember now we
are on the client, we're in the multicast, and this is also
used by the client. You have to replicate
the variable in order for the client to
know what we're talking about. Let me just write bullion, whenever it is not
found in the inventory, we can go ahead and shoot
or play this emitter, however it is found
in the inventory. I think this is a lifesaver
for us because it is playing early on whenever
we are switching the weapon. This is the first variable
that's getting changed. It is catching this early on and it will not play
the muzzle flash. Hopefully, we need to test constantly because we don't
really know before we test, let's play as the
server right now, actually, let's
play as the client. As the client up
here, let me play. Now I'm going to take a look
here on my server again. If I shoot as the
client and I switch, I tried to do that a couple
of times, that was it. There are a lot of checks
that we are doing. This is necessary to not
play that bug effect. Now it's not really
affecting the game, however, It's still
affecting it visually. Not affecting the
damage or anything because this is
actually not played. This is stopped early on. We're actually not
damaging the player. Remember, we're creating
the player damage after the line race. It is just a visual bug
that we got rid of. All right, let's go ahead
and compile everything. Let's save everything and
let's move on to the next one.
153. 10.24 Shooting Animation: Now we need a shooting animation because right now the
player is static. Whenever we shoot, let
us add an animation. Let's go to the assets
and animations. And here are all the
animations we created before. If you just search for shoots and I think actually
it's called fire. If just search for fire, you can see fire
pistol and fire rifle. These are the animations
that we can use to add whenever the player
is shooting the weapon. For these two, I'm going
to take both of them. I don't think we need the C, maybe we do later on. I'm not sure right
now. But let's just use these ones for now. And let's get back to
those if we need them. Let's right click here, go to Create and create an animation
montage just like before. For these two here, now we've created two
animation montages. I'm going to rename them, Remove montage from the end. At the beginning, I'm
going to call it as a prefix just to stay consistent with our
current code right now. Let this and call this
other 11 as well. If I just search for so I can
see the animation montages. I can click on the pistol first. This is a reloading.
I'm clicking on the pistol fire,
it's this one here. And what we can do here again, you have to change the
slot to upper body, just like what we did before. Slot name, upper body like this. And let's close it down. And let's open up
the rifle as well. Change it to upper
body, just like this. Okay, And save everything now. Let us close it down. Okay, what we need
to do right now, we need to play this animation. Whenever we shoot the weapon, we need again to add
it to our structure. Let's go back to the blueprints. I'm going to remove this
search word so we can see. I'm going to go to structures and open up the weapon info. What we can do here, we
can add a variable called shoot animation for this one. Now you can have a different
shooting animation for each weapon.
This is really cool. Everything is customized in
this game shoot animation. And I'm going to have it right after the reload or
right before the reload. Equip, shoot, Reload. Okay, let's go ahead and
compile or just save here. Let's open up our data table. Once again, here inside
of our data table. Once again, let's go over
here to the equip animation. Let me add a new one to the right and call this
one shoot animation. Now we can minimize
this here in the game. And let's find our
montage again. If I search for one and I take this fire rifle,
copy the reference. And let me go back
to the data table. Paste it for the AK and M
four, these are the first two. Then I go back and
copy the reference for the fist animation montage. Copy reference, I go
back here and paste it for the pistol shooting.
Okay, that was it. Let's go ahead and click on
file, download CSV file. Let's open it up here. I'm going to again, rename it
just like before. Rename it T Weapon Info. And I already have one here, so I'm actually going
to copy this one. Delete it here, and
rename this one. Now let's go back in our game. Let's go to blueprints, data tables inside of here. Again, I'm going to
close this here. You can drag this
data table into here. And now it is updated. Okay, let's go to the code
now and code it in in the player player base inside
of here whenever we shoot. It's actually also here if we
just drag all of this away. So we're going to play
the animation together with playing the muzzle
flash and the sound effect because it's still
just an animation. And we need to play
it in a multicast because all of the players
need to see that animation. Let's take the mesh again. Once again, let's say montage. And we can play this montage, and let's go ahead and
connect everything. And now what we can do as well here for the
montage to play. Now we have it from
the data table. Let me just copy all of this. Paste it down here,
and let me just hide unconnected pins for the weapon. Now we don't really have a
reference for the weapon. This is not the weapon class, this is actually just
the weapon mesh. You can see here.
If you remember, if we go back to the hot weapon, we take a look here at
the server chute, weapon. This is the weapon mesh. This is the skeletal mesh. Remember, this is not the
blueprint class itself. This is the blueprint class. This is the skeletal mesh. And the skeletal mesh is the one we're plugging into
the weapon here. This is actually
the skeletal mesh. It's not the blueprint
class itself. We need the blueprint clause
because it's not really the skeletal mesh we put inside
of here. It is this one. So you can see if I drag from all the way up here
and plug it into here, you can see that fits together. What we need to do here
to optimize it better. I'm actually going to switch
it out if we click on the multicast and
if we click on the Plus and we search
for the weapon base. And we choose the weapon base, we're just going to
call this one old, so I can actually rename
this one to weapon. We remember to compile first
before you can do that. Now it's called Weapon, and now we can go ahead
and connect it here. Now we can see it works, okay. Now all of this
really need to be here because I already have
this weapon reference. Now you can actually get
all of this information here for this V effect that
you have connected here. Remember this is the shooting, you have the shooting
sound effect and you have the muzzle flash. And you can connect the muzzle
flash to this one here. And you can connect the shooting sound effect to this one here. You can also connect the shoot animation
we just made to here. You don't really need also the weapon, We can
get it from here. If you just drag from here and search for weapon variable, this is the skeletal mesh. You can connect it here as well. Then I can see all of
this is actually useless. So we can remove this one, and this one, and this one
and go out and compile. We got a lot of errors because
now we're not using them. Let us go ahead and
delete all of this. We're actually going
to remove this by clicking on the Alt
button on the keyboard. And clicking here, clicking
here, clicking here. And I'm going to remove
this reroute node, remove these, click here,
hide unconnected pins. Now we need a reference
to the weapon. It is this weapon up here. I can just click
and drag for now. I'm going to make it
a lot cleaner later. So let's just compile for now. Now this shoot
weapon is correct. Okay, we don't really
have more references now to make sure if I have more
references to this or not. Just to make sure
I'm not bugging out, I can write, click
and find references. And you can see it's
either here or here. I don't have more
references than this. Okay, so everything is good now. And now we have also connected
the shoot animation. And I don't want to play
it whenever it's complete, like what we did before. Remember the other montages that we have created earlier.
For example, this one. We play this event here whenever we complete
the animation montage. Now for the shooting weapon, I only want to play it and
then continue my code. I don't want to wait for
it to be complete before I play my effect
here. This is fine. Let us compile and
save everything now. It should play the animation. If we click on play, let me just play at
the server right now, and I select terrorist. I go here and I just
shoot one bullet. You can see it is actually
playing the animation. Now we do have a bug. Now if I look down,
you can see it's playing the animation here
at the center of the screen. You can see it goes to the center of the screen
whenever I shoot, which is very weird
and we need to change that also the
animation is really slow. I'm going to go to the assets and search for Anim one again. I'm going to open up the pistol here for the shoot animation
for the rate scale. So how fast this animation
is going to run. I'm going to change it to three. I think I want to
shoot a lot faster. Also for the rifle, I'm going to change it
to three rate scale. It shoots a lot faster. Okay, now let's fix it. Actually, this is also affecting the reload and I don't know why I didn't notice it earlier. I think I was busy just talking and recording
and showing you. But if you just reload, you see this is the reload
animation we have so far. However, it's not reloading correctly because if I
look down and reload, it's actually looking
in the middle again and reloading just like this shooting problem that
we have right now. Okay, we need to fix this now. Let me just go ahead and
disconnect the sound again, just so it's not annoying
inside of this course. Let me just disconnect the shooting sound
and compile now. Let's go ahead and open
animation blueprint. Because the problem is
in there right now. The problem is for the
animation blueprint is this upper body animation
and layered per bone. We actually need to play
this before the Aim offset. The Aim offset, remember, is the offset where
here as the player, I look up and down with my weapon and the
movement like this. We need to play this upper body animation before the aim offset so it
can blend together. This is the problem right now, what I can do here,
let's go over here. Let's start with a
pistol right now here for this state
machine cached. Let me delete this
pistol movement for now. Let me take this layer per
bone and paste it here. Now remember to use the
pistol state machine cache. We have the state
machine cached. If I can find it, we
have this state machine cached and we also have
the movement itself. We have the state
machine cached and movement cached over here. We're using the state
machine right now. Let me copy paste it
down here as well. This is just for the pistol and let's do that for
the rifle as well. Let me just delete this, clip this, and paste it here. Let me take this state
machine for the rifle, remember it's the state machine. And copy paste it
down here as well. And go ahead and
connect it up here. Okay, so that was it actually, let's just copy paste this.
Let's copy all of this. I'm going to delete
this down here. I'm going to paste it. And I'm going to connect
it here as well. Let's do it up here as well. Let's copy the pistol one
pistol state machine. Let me delete it down here. Let me copy or just
connect this up here. Paste connected here as well. Now we're playing the
layered blend per bone. Before we play the aim offset, that will be the
correct solution. Now we are saving
all of this into the pistol movement cached and
the rifle movement cached. We can go ahead here
just like before, right click and
search for cache. You can get the pistol
movement connected, right click, search for cache. Take the rifle movement cached and go ahead
and connect it now. It's also a lot more
cleaner than before and can them together like that. And let us compile and
let's check if this works or if we have any box
that we need to take care of. Let's click play here
as the terrorist. Now when I show, if I look down, you
can see it is working. I shoot up as well. I
shoot in the middle. It's working also
for the reload. Now we can actually reload
while we are looking down. It doesn't have to go
here to the middle. If I shoot up, I
reload, I can do that. If I just take a, if I
open up this other guy, I take a look at that guy here. So I can see the animation. I pick up the K as
you can see here, shooting. I can reload
even looking up here. Or if I look down, I can reload as
well. I can shoot. And you can see my
shooting animation. If I come close here, you can see my
shooting animation. And the same here, if
I play as the server. You take a look
here as the client. If I just maximize this. So you can see I
minimize this a bit. Here, I'm taking a look at the server and the
server is now shooting. It is also, you can see
the shooting animation. I can reload from
up here as well. I can reload while
looking down as well. Now it is working well and
they are blending together.
154. 10.25 Out of Ammo SFX: For this lesson, I want to
show you how you can play a sound effect whenever
you are out of MO. Whenever you're out of MO, you hear this clicking
sound from the rifle. You can try to
implement it yourself, I believe you can, if you
just take a good look at it. However, if you're not sure, let's go ahead and
do it together. Let's go ahead and open up the player whenever
it save here. Let's open up the player
base inside of here. Again, we need to
use this multicast. However, I'm going, I'm going to add a bully in
here saying has mo. Whenever we have MO, we can play all of this. If I just drag and write
a branch like this here, whenever we have MO, we're going to play all of this like what we
have done before. However, if we do not have Mo, I want to play
another sound effect. I want to take this sound can just from
here and say location. What sound do you
want to play now? We need to add it to the
structure once again. As for the location, we
already have the location. We can just plug it in here and compile now for the structure. Let's go ahead and
open up the structure, and let's make a new variable. We can just call this
out of M sound effect. Let's change this to a sound,
go ahead and select it. And go ahead and save. I think I'll just move it up to where it's under the
shooting sound effect. All of the sound
effects are together. Let's save everything
once again, let's open up the data table. Let's go to the right here at the end here after the
shooting sound effect. I'm going to right click
and add one to the right. Then we can say out of
MSX and inside of here, let's just copy the reference. Right now we don't
have any references because we haven't
imported anything yet. Let's go to the
audio folder here. Open up the sound effects. If you go to the
cause materials, I have included for
you some audio. If you open up this audio and I have included this out of MO, if I just make this
larger out of M K 47, out of MO for one and
out of MO pistol. And select all three.
Click and drag them into the content browser. Inside of here, select
all three right click and create multiple cues. Once again, I'm going to rename all of them just
to stay consistent, we rename them S C as
the prefix for Sound. I'm also going to do that
for the pistol here. Let us do that for the last one. The last one is the K 47. Let's call it Sound at the beginning just
like that. Okay. I'm going to open
up the AK 4071. I'm also going to
open up the pistol and I'm going to
open up the four. I want to reduce the sound
because it's probably really loud for me. I'm going to put it
to 0.2 also to not make it annoying for you on this course. So
now I can hear it. This is the out of
MO sound effects. Now let's close it down and
let us copy the references. Let's right click the
AK copy reference. I'm going to go back to my data table for the K,
this is the first one. Going to paste it for the four, right click reference
past the pistol, right click p reference
and paste it here as well. File download, download,
CSV, just like before. Open up the downloads folder. And inside of here,
once again I'm going to delete the old one,
paste it on the new one, rename it and go to data tables and drag it into
here it is updated, and let us save everything. Okay, let's go back to the player and let's
open up the player base. Now for this one, we now have this here. What we can do, we can use
this out of M sound effects. I'm just going to drag this here back because we don't really need
to copy paste this. Once again I'm going to make re wrote notes
for all of this. It's actually better to look at within one to
two lessons here. What we can do is out
of MO sound effect, we can drag it into here. Now it's going to
play the sound effect whenever we do not have MO. Now we're not fully finished
because we actually also need to define
when we have MO or not. Here in the MC shoot weapon. We need to take this,
remember to make this true. This is the normal
code that we have. And we already have MO here
whenever we're shooting. Because we're basically taking a look here if we are out of MO or not and all of that stuff here here. And that
will be correct. Now, whenever we do not have MO, whenever this is actually false, let's try to do some code here. Let me just move
this up slightly. Let me just copy paste this. Let me move this down
slightly as well, just so we have some
space to work with. Now for this one,
let's connected here. We need to do the code
for the weapon Again, I'm going to break the same weapon from up
here, drag it into here. And for the location,
it's the same location. And for the Mo, now we need
to make sure we have Mo, because we don't want
to just play this whenever we go down here here. Basically what you
want to check, we want to play this sound. Whenever you have zero bullets, zero bullets in the Mac, and zero bullets in
the extra bullets, we can actually use the
extra bullets to check. Here I believe we have
a function already. This one has extra Mo, we can actually use this one. We can go ahead and say
if you have X Ramo, you're going to go ahead
and play it as normal. If you don't have Ramo, you can go ahead and play
sound effect whenever has extra MO is false then we can go ahead and play this
shooting sound effect. Where we are out of this
should fix everything. Let's compile and
let's click on play. Here I want to play as the terrorists just keep
shooting my weapons. I'm going to keep shooting
and skip the video. Okay, Now I am at
the final bullets. And if I keep
shooting and I reach, if I reach zero bullets, I'm going to play this
out of sound effect. And you can hear, I
don't have any bullets. If I just switch here and play the other sound effects,
see it's normal. Because remember, I've disconnected
the sound effect for the shooting right now. If I reach zero bullets, you can hear I
have zero bullets. So this is how we can do it. Let's compile and save everything
like before I continue. Now, I'm actually going
to clean all of this up before we continue because
it looks like a mess. And it's also how to
follow on this course. Let me just compile
in my off time. I'm just going to
organize all of this, so it's a lot better to look at. Just go ahead and create, reroute notes, create
comments and all of that. I'll see you in the next one.
155. 10.26 Bullet Impact VFX & SFX: All right, so everything
is looking good so far. I think we're missing
some visual effects and sound effects for when the
bullet hits something. Right now when we are
playing and I take, for example, the four
and I try to shoot here, Now I'm hitting this part here, but we don't really see any visual effect on
the part we're hitting, and I think it will
look a lot better. Let's go ahead and add that. You can try to edit yourself
because I think you can, if you try to think hard else, let's do it together. Let's go here in
the player base. Just like before, we need
to create a multicast. Now we can integrate it into
here and add more variables, but I think it will
get a bit messy. So we need to create a new one. As you can see, I have
organized this here, as you can see, and I'll
teach you just this a bit. Here we have the event graph. We have the basic
character movement that we did and finished. And we haven't really touched it for a long time right now. By the way, I have added the functions to
different graphs. This is because if you create a lot of code inside one graph, it actually starts
to, maybe you can already feel it on your
computer. It starts to. When you look around inside
of here, what you can do, for example, let's say I wanted this crouch specifically
in another graph. I just control x to flip
it here, control x. Then I create a new graph
called, for example, crouch. It's because an event is called crouch.
So I can't do that. Let's just call it crouch events graph or something like that. Then inside of here, now I am. Inside of the crouching
graph, I can control V, and there it is, I
have the crouch. Now, for some reasons, you might have functions
that are not getting pasted. Let me just click
on control Z here, control Z, control control
Z until it is here. Sometimes what is happening
is if you copy something, let's say I wanted to copy
this part, control X, I wanted to make a new graph, call it something random, and then copy paste. Now I can see when you paste it, this appears and it says some functions references could not be resolved in
the new context. Would you like to fix them here? Then you can choose something. However you don't
want to do anything here, just click Confirm. When you click on Confirm, you can see you have
a lot of errors here that you need to fix. However, don't
press on anything. You can just click
on File and then click Refresh all Nodes. And that will fix
everything for you. This is how you copy paste code from one
graph to another. I'm going to click on
controls just to go back to what I had
before like this. This is what I
did. I just copied from here and made a new graph. I made one called Lot
Equip and Drop Weapon. Here is my Lot and
Dropping Weapon Logic. And my Equip weapon Logic. I also added some
comments for you. When I give you
the final project, you can try to take a
look at it and it's a lot better to look at
than it being messy. As you can see here, this is
the lot weapon and so on. Yeah, that's all of
it. The last one graph I made is the shot
and reload weapon. This one where we have
the shot weapon logic. And I try to organize
it as best as I can. Here is the shot
weapon multicast, then I have the reload
weapon as well. And here is the logic for that. A lot barriers to
stay organized, having multiple event graphs. We have the normal event
graph with just the movement. You can't rename this one, This is the default one,
you can't rename it. However, I made the other ones and I renamed them to Loot, Equip, and drop up in and shoot weapon here. Reload as well. It's a lot better to stay
organized and we can find them a lot better later on. I'll also create
categories for all of those like I showed you
in the earlier lesson. You can create categories
and add them here. It's probably good to
do that for all of those and all of your
functions as well. That out of the way, let's
go to the shoot and reload. In the shoot and reload here
we have this multicast where we play the emitter here
with the muzzle flash. However, let's create a
new one for the impact. Let's right click, make a new custom events
just like before. Let's call this one
MC bullet Impact. Let's run it through a
multicast and reliable as well. Now what we need to
know is of course we need the weapon
we're shooting from. We also need the hit location. Where is it that we want
to spawn our emitter? This is the place we're hitting the hit location for the weapon. It is the weapon base. Go ahead and select
it and compile. Okay, Where do you
want to play this? We want to play this
whenever we shoot. This is the shooting logic. We're shooting the weapon first, we're playing the effect, and then we are playing
the line trace. Remember the line trace, if I select the debug type to be persistent so
you can see the line, this is the line when we're shooting, this is
the line trace. It's shooting this line. Now we know where
we are hitting with this line trace after we
have actually hit something. This is what it means, Blocking hit after we actually
hit something. We want to play this effect. So I'm just going to
delete this hello for now. Let's play this MC bullet
impact that we just created. Right now we have
a bit of a problem because it is a blocking hit. And here it also says that the actor hit has
the tech player. Right now, it's actually
only playing this for the players that we
need to fix that. Instead of combining
them together, I'm going to delete this. Let's take the blocking
hit here and connect it. Let's make a branch and
go ahead and do that. If it is the player,
you can do something. If it is not the player,
you can do something else. So instead of just adding here, we have to play this effect. We don't really care if it's the player that has
been hit or not, We just play this effect anyway. Because if you hit a wall, you're going to
play this effect. If you hit the player, you're
going to play this effect. But we don't really need to connect it after
the player here. So we can connect it
before the player. I'm just going to give
it some space here. We can add it before the player. I think we also need
to know who we hit. Because if we hit the player, we want to play blood instead of just some decal or some
stone that we hit here. For this one, I'm going
to add a new one. Let's call it hit Actor. For the hit actor,
you can see it here. Now if you're confused of what type of variable you need to add, you
can just go up here. And this hit actor. If you
hold the mouse over it, it says Actor Object Reference. Let's go down here, click
on it and change this to an actor object reference here. This one, we can just put it
above this here and compile. Okay, Now we have that
information as well. Now for the weapon, you
have to connect it. The weapon is up
here, so you can just click and drag it into here. And let me just create
some rear route notes to stay organized.
Okay, here we go. Now we have created that.
That's out of the way. The next thing is the hit. The hit actor is just
this one hit location if you click on the arrow, so you can see all
of the values, this is the location
we have hit. After we have a blocking hit, we're taking this hit location, we're applying it
to this multicast. Let us minimize
this a bit again, and here we have it. I'm going to connect
this once again. And after we hit the player, we can apply some damage. Now what we can do, yeah,
we can go down here. Now. We don't really have
anything to do out there. Let us spawn emitter
at location. We're going to spawn
emitter at a location. We're also going to play
sound at location as well. Now if you want to have decals, if you have played
Counter Strike before, you know that decals spawn on the wall. If
you shoot the wall. I don't really have
decals in this course. However, if you
want, you can again, just drag from here and say
spawn decal at location. This is going to spawn decals. Decals are basically
just images. You can spawn them on the wall. For example, a
bullet hits image, you can spawn that through
a spawn decal at location. We already have the location
here for the location, the decal size, you can make 111 for example, or whatever. Here you can again
select the decal depending on what it
is in the structure. You can add the decals
to the structure for the specific weapon and so on, but I don't really have a decal, so let's just delete it. This will be easy for you
to do after we've done on all of this 100
times. Let's delete it. Now here for this spawn emitter, now we need the emitter, we also need the sound effect. Let's go ahead and do that. Let's save everything,
Let's minimize this. Let's go to the structure now. Open it up and here
let's add two variables. Let's add one called
bullet impact VFX. I'm going to make
some space here, we don't really need to put them together,
Bullet impact VFX. And I'm also going to add
another one, Bullet impact. X, one for the sound effect and one for the visual effect. For the visual effect,
it's a particle system. And go ahead and select that. For the next one, the sound
effect is a sound cue. And God, and select that as
well for the sound effect. I'm just going to yeah, right after the
shooting sound effect. So just to stay organized
and for the visual effect, I'm just going to move it
right after the muzzle flash. Go ahead and save everything. And remember now
we need to add it to the what it is
called the data table. Go ahead and open
up your data table. All right, so here I am,
inside of my data table. And now for this
bullet impact effects, it's after the
muzzle flash here. I'm going to add a
column to the right. I'm going to call it
the same name here. I can just copy paste this. Let's go to the side
and paste it here. The next one also the
bullet impact effects after the shooting effects here. Add a column to the
right and add it here. Now we need references to. Now for those, I'm just using the ones from
the marketplace. Instead of searching
for it in the folder, because I don't have an
idea of where it is, just click on the
Marketplace folder and just search for Impact. And then you can see them here. What I'm going to use is
maybe this one called Stone Medium for the
impact particle effect. Right click and
copy the reference. If I can find it here,
copy reference and I can paste it for
the bullet effects. I'm just going to paste
it for all of them. I just want to have the same bullet
impact visual effect for the sound effect. Now I believe we have
something called the rifle impact here. I'm just going to double
click it and reduce the volume to 0.2 because
I think it's too loud. This is actually the body one, This is when we hit the player. Let's actually also add
that while we are added. Let's add one for the player. Let us just open
up the structure again and add a new variable. Let's call it bullet impact, bullet impact, player
effects for the other one. Let us add this one
for the sound effect. Let's add a new one. Call it bullet impact player
sound effect. I think it will be a lot more interesting to
have both of them. Let's search again for
particle system system. Go ahead and select
it for the other one. Sound And just move them up
again for the bullet impact, visual effect, and
for the sound effect. Okay, now they're at it. Let's go ahead and add them
again to the data table. Open it up and make
column here to the right. Make a column here to
the right as well. This one copy paste the name, the other one as well, copaame. Here we are. Now we can add a new visual effect
and sound effect. Let's go back to the
Marketplace folder again, search for heat. Let's copy this Body one, we just reduce the
noise of right click. Copy reference and
we can paste it for the bullet impact
player sound effect here. Now we need the one where
we don't hit the player. I think this one
rifle impact surface. Go ahead and reduce the noise to 0.2 Let's play it and see what
it is. Okay, sounds good. Let's right click and copy
reference and paste it here. Now we need a bullet impact
player visual effect actually need some blood. Where we hit the player, I'm not sure if
they have one here. Maybe you can search for blood. We don't really have one here. You can see we only have
those metallic ones. We only have the impact on
the stone and the wood. However, let's just copy
the metallic one for now. It takes a bit of
time to get into the particle system here and it's not really a
part of the course. This will be a bit too advanced, takes some time to make. Let's just copy the spark
here. Spark medium. Let's right click and
copy the reference. And you can also paste them here in the visual
effect for this one. Now if you really
want to go in here and change something,
you can open it up. You can maybe click on
the Color over Live. You can click on here, here, this arrow
and this constant. And you can try to
play with the colors. You can always try to
play around with it. Make it more red,
so the color here, over life, you can
play with the color. And with the arrows
here make it more red, so it looks like blood. You can always do
that, or you can always go to the Epic
Games marketplace as well, and download some
blood article systems. There are a lot of them
inside of the marketplace. All right, now we
have added those. And let's go back
to the data table. And now we can click on File and download and download
the CSV file, once again here in
my download folder. Let me just rename this
data table once again. And let me go to the
data tables folder. Let me just close this for now. Let me drag the data table into here and update everything. Okay, so now we have
that locked in. Let's go to the
player, player base. And now let's just
copy all of this. Paste it so I don't
have to write it again. This is just what we
have done before. Let's drag the weapon,
get the weapon name, weapon info from here. I'm just going to hide
the unconnected pins. What I need from this one
is the bullet impact, the effect bullet impact, the effect player, and bullet impact effects
and effect player. I need those here And
then I can go ahead and do the particle effect
instead of just king, for example, the bullet
impact, the effects here. We can always ask if it is the
player we have hit or not. Because if it is the
player we have hit, we want to play this one. What we can do is we can
take from this hit actor and say or not get but just
actor has tag just before. Just like what we did up here when we hit
the player here. We're asking if the actor
has the tag player, so we know it's the player. We can do the same
thing over here, depending on if the actor
has the tag player or not, then we know it is the
player we have hit or not. Then what we can do is we can
take this and say select. And we can take the select node and we can plug this into here. False, it is not the player
then we just want to play this effect if
it is the player, if it is true, the actor
has the tag player. We want to play
this player effect. Now it's going to
play a visual effect depending on if we hit
the player or not. Okay, cool. For the location, it's the hit location, For the rotation scale,
everything is the same. Nothing really needs
to be changed. Now for the sound effect, I'm
doing the same from here. And say select depending on
if it is the player or not. Here, this one. Go ahead
and connect it again. If it is not the player
normal sound effect, If it is the player, the player sound
effect just like that for the location
it is the hit location. I'm just going to add
some reroute notes and organize this code here. I have added some
reroute notes and I'm going to save
everything now. Let me just go up here and recheck that I've not
forgotten anything. Now, we have added
this, we have added the visual effect and
the sound effect as well up here in the code whenever we shoot and we
actually hit something, we're going to play
the sound effect and we're also going to
play the visual effect. And the hit actor is blocked in. The weapon is
blocked in as well, and the hit location
is blocked in as well. Let's just save everything
here and give it a try. Let's go select terrorists. I'm going to select the four. Go ahead and shoot. I can hear the sound, if you
can hear the sound. Awesome. Okay, let me just disconnect this
part of the code here for the shot weapon. I'm just going to disconnect the chote weapon
part of the code. Can only hear the bullet impacts just so I can see if
it works properly. I'm just going to take
the AK shoot here. Now you can see I'm
actually shooting. I can see the impact. I can
hear the sound as well. If it's far away, I
can't hear the sound. If it's close, you can
see it's getting closer. It looks a lot better. If you want to make
the impact larger, you can always go into here
and increase the scale. Something like crazy. You can actually
see the difference. The scale is now ten. I can
play, I can shoot something. And now you can see how
crazy it actually gets. Now you can see this is, the effect looks bad
because it's so scaled up. However, I think
one on one is fine. If you wish, you
can always make it 1.5 so it's a bit
larger if you wish to. But I think it's fine for now. This is what it looks like. Now let's just remove this line. We don't really need to see this debug line so
I can press none. I also want to try it on the client just
to make sure it's working on the client as well to go ahead and
try it on the client. Okay, nice. Again, if you wish to change the
color of the impact, you can always go into
the particle system and click on the color. And you can go ahead and change the color for that as well. But now you can see it
is working awesome, and it's also
working over there. However, we can't really see it over there because
it's really small. Here it is. You can try, you can see here it is here. Awesome. Sounds really good. Nice. Okay, this has been finished and
I'm just going ahead and connecting this part again and compile
and save everything. Now we have the shooting effect, visual effect, and
sound effect as well. Again, if you want to add a
decal like counterstrike, you can also strike
from here and say Cal. And you can spawn decal at
location just like before. You can always select here, make a select node and
plug in the player. If it is the player you hit, you don't want to
spawn anything, you can do that if it is the player or if it is not
the player that you hit. You can always spawn a
bullet cal on the wall. You can always do
that. Let's compile and save everything and let's
move on to the next one.
156. 10.27 Bullet Spread: Now, instead of having
all the bullets hit in the middle of the cursor, now you can see if
I shoot something, it always hits at
that same place. Instead of doing that, you can actually add a bullet spread. We can do that just like
in Fortnight for example. If you hit on the cursor, it's not really hitting
the same spot, 2047. If you keep shooting. To do that, it's really, really simple in the
bullet end location. You can see here we're
creating that line trace. Before I do this, let's
actually take all of this, copy this, and
paste it down here. I think I'll prove it later, because here I
don't want to shoot a line trace if I'm
out of MO and so on. Maybe I want to improve this by actually
removing the sequence, because then we don't need
to copy paste this code. We can just add this
part right after this. But let's just keep it for now, like this and see
where we go with it. The end location, what
I want to do with it, I want to randomize it a bit. Start and end location. The start location is
fine for the line trace. However, the end location,
let's randomize it. The line race doesn't shoot
at the same place every time. The way to do this,
very, very simple. We can take this
end location right now and we can take it
and say break vector. Now from this one,
what we can do, let's just disconnect
it from here. For now, delete this one, that we only have this here. And you can just click and
drag and paste it here. Actually, this end location,
we're breaking the vector. So I can see the x, y, and z, and I can
randomize the value here. What I want to do
is use this one called random float in range. Now we don't really have
a random vector in range, else I would have used that. But we have a function called
random float in range. So it's going to choose a random float depending
on a random number, depending on what you give it as a minimum value and
as a maximum value. By the way, this is also
how you roll a dice. You roll a dice by writing here, the minimum value of
the dice should be one, The maximum value of
the dice should be six. And then it rolls a random
value 1-6 to roll the dice. And you get like a number here. We're going to do this here
for the minimum value. We just want to take
this x and say, let's write minus
first, let's say 200. Let's try 200. Then the
maximum float here, let's say plus 200. It's going to take
the x location, it's going to find
a random number. We give this x -200
Take this x plus 200. Between this range,
you're going to find a random number with this random number we
want to make vector. Let's take this end here and say vector so we can put it together again and
select this make vector. Then we can plug it back
into the x right here. We're basically just modifying the x value and we're plugging it back into
the vector like this. Let's do the same thing
for the other one. I'm going to copy paste this. Maybe you can also actually create a function from this one, but I think it will
be unnecessary. Let's just add it here. And add the x or the
y and Z as well. Let's plug in the Y. Let's plug in the
Z just like this. Okay, now we have
this finished and now it's going to find a
random load and range. And it's going to randomize
our vector depending on what value it finds
here as the random. And let me just go ahead and add some reroute notes to
make it look better. Okay, so here it is. That was actually it. So we're finished. That was very, very easy. Let's just do debug again and let's play just
to see what it looks like. Now here as the terrorist, I can shoot my
bullet and you can see when I shot multiple times. It's not going to shoot in
the middle of the cursor, It's going to find
a random location, sometimes in the middle,
sometimes outside of the cursor. What you can see, it's not shooting the same
place again and again, this is how you can
randomize the bullet spread. You're not shooting
the same place. What you can do if you
want a larger spread, you can always increase
those numbers again, if you want to make it better, you can always right
can promote this to a variable and connect that
variable to all of them. And you can just
edit one variable and it will edit all of
them at the same time. That will save you
a lot of time, but I think I'll keep
it at 200 if you want. You can increase the
bullet spread and it will be to hit at the middle. But as you can see,
if I hit close, it's going to be a
lot easier to hit. However, if I hit far away, it's going to be harder
to hit the target. I'm not always hitting
at the middle here. Very easy method to do this. And let us just save everything, let's move on to the next one.
157. 10.28 Placing the Weapons Correctly: Right now, I think we are at the time where we can just
place around the weapons, those weapons we
have around here. I'm just going to
delete all of them. You can do it quickly. You can click on
here, old shift, click on the last one, delete, and I'm also going
to delete this one. What you can do now is we can
go to blueprints weapons. Now you can just
drag them in and place them around the
level, for example. You can place an AK
here if you want. You can turn on
the snapping here. I think it will be
a lot to have can place the AK and just drag it up a bit so it's not on
the ground like that. What you can do is I just
wanted to have it in the back. I'm just taking a look
at how far away we are from this wall. Maybe
we can add it here. Actually, let me just
drag it to here behind cover and hold alt
and drag to copy it. I think I will increase
this one to 500 instead to hold Alt
and drag like this. I think I'll copy it like
this a couple of times. Here, here and here. Just do it however you
want for your level. You don't really
have to follow here. I'm just doing it
randomly. Now we have it. Maybe we can add one here
as well. Now we have it. And what you can
do is you can add an four in the middle here. Maybe I just need to
decrease my snapping to 100 once again here, I think I'll add
it in the middle. I need to decrease this
to 50 instead here. And then increase, let's
just take it up here, increase it to 100 again, increase this to the other one. Put it to 500 again,
just like before. Keep dragging it like this. Now it's between the K
here, here and here. And just go ahead and
continue like that. Okay, so now we have this and if you take a look at it looks
nice what you can do. You can also place the pistol so you can drag that
into the level. Let's me just decrease
this to 100 again. And place the pistol, push it up like before, like this if you want, you can add the pistol to
like all of the space here. If I just increase it to 50, you can add the pistol like
this to all of the spaces. Let me just go
ahead and do that. Okay. Now, I have
placed the pistols. Now you can see pistols
all the way here, the K and four all the
way here, if you wish. Actually, I don't want to
place weapons in front of here because this is where
the player is spawning. I can even move them a
bit further to the front. So they are not spawning
on top of the weapons. I'm just moving
something to here. We have to remember the spawning points for this one as well. Just go ahead and
select all of them. Move them one step to
the front like this. Also for those weapons, I want to select all of them. Click on the first one, scroll up Hold Shift and
click on the last one. Also, I have to select
the case Hold Control. And I'm going to just
select all of them here. And let us click on
for the move tool, hold Alt and drag to
copy all of them. Click on to rotate 180 degrees. Let me just hold them
to here and just try to make them
at the same level. So it's fair for both sides taking a look at if they are at the same level and they are now, what I want to do now
is just drag them to the other side and place
them somewhere like here. I think this is where it is
on the other side as well. They're very close to the wall. They are very close
to the wall as well. Maybe one more like this, we need to drag them
actually to the other side. It's something here.
It's one more, I think behind cover like that. Now, both sides are the same. If you click play now and we
can sell counter terrorist. Now for example, you can
see they are on the ground. We can pick up a
pistol and we can also choose to one of
the other weapons. And yeah, now
everything is working. What you can do
instead of picking up a pistol first
because it's annoying, maybe to switch to the rifle, you can switch them around. So you have the rifle first and then the pistols behind them. Okay, so now when you
have placed the weapons, you can also place them
up here if you wish to. You can place, if you
make another weapon, like a special weapon,
you can place it up here. So you have to get up this
ramp to take this weapon. That will be cool as well. Okay, so whenever you
have placed your weapons, let us move on to
the next lesson.
158. 11.01 Designing the Health & Armor UI: All right, so now we are at
the health armor and damage, and we are ready to create
the health and armor UI. So let's go ahead
and go to the UI. And we already have our main UI, so let's open it up
here to the left, I want to create
armor and health UI. Okay, so what I want to design, I want to show it to you first so you can actually see it. I want to design a UI like this. I like
showing it to you. So you can actually, we are on the same page here and you
know what you are doing. We are doing this one. And this is what I
wanted to look like. Again, what I told you before, try to take a look at it, try to break it down. So, you know, if
you want to create horizontal boxes,
vertical boxes, overlays, just like what
we have done before, this is what we're
going to create. Okay, first we need
an overlay because we have a background and we
have something on top of it. Let's drag this into the canvas panel here.
And now it is added. Now click on it. And
for the anchor point, I'm going to change it to the
bottom left and write 00 in the position to
get it up here in the canvas for the
alignment for the y, write one, now it is up
here at the position of 00. Okay, for this one we
want to have an image, we want to have a background
place, the image here. I want to make it
the same as here. Instead of just doing
the same thing. What I can do here
is just hold shift and right click to copy this. Or you can just right
click and copy. You can go to this
image and you can hold shift and left
click to paste it. Just like this for
the alignment, Just fill the whole
thing for the overlay. Now I want to have it size
to content like this. Whatever image size
we have here is actually going to automatically
size with this one. For the space on the screen. I want to push it a bit away, 30 in the X and -30 in the Y. We have a bit of a space here. It's not up here on the edge. Okay, let us compile now. This is what it looks like.
Now let's add the health bar. Let's add a horizontal
box because we want an icon and a progress
bar beside it. So let's add a horizontal
box to this overlay. For this horizontal box. Let's, let's first add an
image because we want an icon. And then let's add
the Progress bar. However, remember the Progress
Bar has text on top of it. We actually need an overlay. First, let's search for an overlay and place it
here for this overlay. Let's find the Progress bar. For the health bar, we are
using a progress bar and then we have some text
on top of it to display how much
health the player has. Okay, now it looks a bit
confusing for this overlay. Let's see here we have
this horizontal box for this progress bar. I basically want to fill the
whole thing in this overlay. Let's just place
this in the middle. Clicking on the horizontal box, I'm going to align it to
the middle for the image. Let's select the icon. Now we haven't an icon right
now. Let's go to icons. I want you to go to
the course materials. If you just go to the
course materials here, I go to the UI to icons and import the health on the heart
icon and the shield icon. Click and drag them into
here. Now they are imported. Remember to click on it, change the texture group to
UI just like before. And compression settings to user interface tot the
same thing or the heart. Change it to UI and change it. Let's see here, the
user interface to T. Now we can go into the UI. We can click on the image, search for CO or icon. Let's just search for
the heart one on heart. Select it. Now you
can see exhibits. And this is because
of the alignment. I just wanted to have it
in the center like this. And I'm going to change the
size of it to 45, 45 maybe. Let's actually just
change it to 40 by 40. Now for this progress
bar, let's click on it. For the progress bar,
you can see here, I can increase and
decrease the percentage. And it will increase and
decrease the progress bar. Now for the style of it, we need a background
image and we need a fill image and marquee image. Now for the background, I just want to click here. And I think we can
search for input box. I have like input boxes here
we can use as a background. And we can just use this
one image, input bar dark. Go ahead and select it.
Remember what I said before? Change it to a box and also
select 0.5 as the margin. So it stretches correctly
for the Phil image. If you just search for Phil, I have the progress
bar, Phil, for you. Let me just import the other one because I haven't
imported it yet. You have probably already
imported it here. Let me just go to my older
cost materials, I images. And let me import this
red one, red, Phil. Let me import it here.
Click on it, change I and change this one
user interface to save. And let me go back here. Let's select the fill red. Go ahead and select this one, also for the mark image. You can just copy this. Paste it here. Remember for the margin what I said before, 0.5 for the margin. This one again changes to
box and 0.5 for the margin. Now this is fixed and you can see the color
is not correct. It's showing this weird
bluish color, teal color. This is not what we want. This is because the
fill and color opacity is this light blue color. You have changes to white.
You can see the correct on whatever you have
selected over here. Let us compile now. Let's make it a bit larger to see it better for
the marquee image. This is where you
control the size. If you try to change the image size on these ones,
it's not going to work. Let me just go here to the marquee image image size
and you can change it here. Let's just make it wider. For example, 350
Lee for example, 60 here in the height. This is what it looks like now, 350.60 You can again copy the image size and paste it
on top of the other ones. You can click on the
text here and align it in the middle of
this progress bar. Let's change the text
to rubic semi bold, what we have been using so far. Also, let's change
this size to 20. I make it smaller, let's just write a random
number for now. Let's write 76. I just want to write a number so we can see what we are doing. We are changing this later
dynamically within the game, But this is what it
looks like right now. Let's add an outline. I'm going to add two to the outline size and then change the color
for the outline. For example, you choose
this color picker. You can pick a color from here. I think I'll just pick the
background color of this progress bar. Okay.
Click on it again, and I'm going to add
some shadow as well if you write 66 here for
the shadow for example. So you can see it clearly
and you can click on this shadow color and you
can change the alpha to one. This is the shadow for the text. Now for the shadow, I'll go with the offset
of three by three. And I'll change the
opacity to 0.5 It's not too visible when you
look at it from here, it looks a lot better. Okay, that looks nice. Now we can disable
the dashed outline so we can see what it
looks like right now. I think what we can do now, we can click on, let's see here, the
horizontal box. And we can give it some space. What we can do here
for the padding for the left and right, I'll give it, for example, 30.30. This is what
it looks like. Now we're pushing it
away from the sides. I actually want to give it more. Clicking on the
horizontal again, 35 by 35, and top and down. I think I'll give
it by 30 by 30. Now this is what it looks like. Okay, let's give it some
space between the icon. And this is done if we
search for a spacer and put it between the icon and
the horizontal box. Actually, not here. Let's drag it down to here. Between the image for the heart and the progress
bar. The spacer is here. Let's in the x, give it a space of 15 maybe. Let's actually give
it more space. I think we can give
it more space for the spacer, maybe 20 instead. I also think I'll give it more space here for the
horizontal box up here. Instead of 35, I'll
give it to 40. Left and right will be 40, and the top and down will be 30. This is what it looks like now, looks nice, we can compile now. Let's copy paste this and edit as an armor for the
horizontal box. Let's just click here
and click on Control. You can see now they are on
top of each other because we actually need a vertical box to have them on
top of each other. We forgot to do that. Let's
search for a vertical box. Let's just, let's see here
below the background image. Remember this is the overlay, this is the background image. And then we can have
the vertical box where we have the
health and the armor. Let's strike them into
this vertical box. Now for the horizontal box, instead of having the
padding inside of here, you can see it's added
double because it's adding a padding for both of
them. Let's just copy this. I'm going to click this
arrow to remove it. Click on the horizontal
box here as well. Remove, Add it for the
vertical box instead, the parent of these two. Clicking here, Paste the padding you had before, and
now you have it here. Let's just add a spacer
again between these two because they are too close
together here for the spacing. This is the Y. I'll
add 15 for the icon. Let's change it to icon shield. Let's change it to that one
for the color of the fill. Let's change it to
the purple one. Let me just copy paste
it down here as well. I think, yeah, everything
should be fine for now. Now if you wish, you
can also click on them. For example, this image
image. This image. Let's change it to the
visibility of Hit Testable. We can't interact with
it, with the mouse, I believe this one and this one. And we can also change the
visibility to hit Testable. Yeah, that should be everything, just so the mouse doesn't
interact with them. If you need to interact
in the future, we're going to change the names of them later when
we need them as variables. So we can change
the names up here, but for now this is finished. This is what our health
part looks like. If you click on Plate to take a look at what
it looks like, make the screen larger. This is what it looks
like. Looks nice. So now we have the health and the armor and we can add
functionality to it.
159. 11.02 Applying Damage: Now that we have the healthy, let's go ahead and
apply some damage. If we go to the player base
now we have this projectile, this line trace that
we're shooting here. What we're saying is if the
actor has the tech player, we want to apply damage to them. To apply damage,
you basically just drag from here and
say apply damage. You have this function
and very easy to use, it's going to move this away. We have some more space to work. Here we are applying
some damage. Now you have to specify how much damage do
you want to apply? Now let's say for
example, we have a static number. Let's say 20. Now we also have
to specify who is the damaged actor.
It is the player. We are hitting the
hit actor here. From the hit actor, you can click and drag and plug it in. Okay, now we have
the damaged actor. Let us just try it out
and see if it works to test and see if this
is actually working. Let's go ahead and down here, let's make any damage event. Now, before I do
the damage event, I actually want to
make a new graph, so we don't put too many things inside of here. All
of this is fine. But when we apply damage, I want to go to another
event here or another graph. Let's call this one Health
and Health Armor and Damage. Let's call it that. Inside of here if you right click
and say Any damage. Now this event is played whenever a player
receives damage. We can just try to print a string to the screen
to see if it works. And drag this damage
into this string, it prints out how much damage
we are doing to the player. Now if we click on Play
and select Terrorist here, and select Terris here. If I just pick up a weapon
and try to shoot the player, you can see it prints
20 to the screen, because now I'm applying
20 damage to this player. Okay, this code works. Now if I go back, instead of applying like 20
damage like a static number, let's go ahead inside of
a structure once again, let's open up the
structure inside of here. Let's add two variables. They are both a
float and a float. Now for the first one,
what we want to call it, let's call it head damage. Now what you can do, you
can make it very specific, like how much damage should
you do when you hit the legs? How much damage should you do when you hit the arms and so on? But to just keep
this course shorter, complex, or shorter
and simple, rather it's getting very
long for this course, just keep it a bit more simple. I'm going to do one damage for the head and one
damage for the body. Body damage, two
types of damage. However, I am going
to show you how you can do the rest of this. It takes a bit more
time, but same process. Okay, now we have it
inside of our structure. Now what we need to do is also
add it to the data table. So go ahead and open up the
data table inside of here. Now, before I do this, I'm
actually going to move the damage up here just to
stay a bit more organized. After the MO, I'm going to do the head damage and
body damage here. Let's maximize it after the max MO. Let me just add
two columns to the right. The first one is
called head damage, the next one is
called body damage. Then you have to specify
how much damage you do. Now let me just say for
example, for the head damage, I'm doing 20 damage, I'm subtracting 20 health. For the body damage, I'm
just doing ten damage. I'm going to do the same. Actually, let's just
change it up to see if there is a difference
for the four. Let's say we're doing 15
damage and five damage, maybe that's to eight damage For the pistol,
that's a lot less. Ten damage for example. And let's say five damage here. Okay, So you can just adjust this how much however you like. Let's now download it as
a CSV file and let me go to my download
folder inside of here. I'm going to rename it
again to T Weapon Info. Now inside of here, again, let's go to the data tables. And let me just close this and import the data table here. Okay, so now we have
this information, let's just save everything. Now it does crash sometimes
whenever you try to save and you edit something
inside of a structure. This is normal, like it does many times. When you
edit this structure and you add new values
and stuff like that, it usually just crashes. Just remember to save your work. Make sure here, let me just open up the data table
to make sure all of my values are plugged in, just like before and it is not. You can see it's down
here. It does crash sometimes and you
have to redo it here. But luckily we don't
have much to do, we just have to drag this
up here and then I can just re drag the data
table into here. Okay, let's now
save everything and hopefully not crash.
Now it worked. Let's now open up
the player base. In the player, open
up the player base. Now let us try to do the head
damage and the body damage. Now what you usually
are looking for is if you go to the assets
you have imported the player. Here we have the
player skeleton, the players skeletal mesh. But we also have something
called a physics asset. This is actually
where you're hitting. This physics asset is where
you're hitting the player. You can try to adjust
this physics asset. You can make those shapes
larger and smaller. This is actually your hit box. You can build up the player
like you can create shapes, basically just kill them up,
skill them down, and so on. But right now for the head damage, we're
hitting this one. Let me just minimize
the camera speed. You're hitting this shape here and this one
is called a hit. They're basically called
bodies body shape. If I go back here
to the player base. Now over here for
the hit results, if you click on the arrow again. Let's over here after
the applied damage. I just want to print out
this so you can see it. I want to print out
the hit bone name, Hit bone name, and
drag it in here. And I'm just going to
minimize this once again. Now we're printing out
the Hit bone name. We can see what happens
if click on Play Terrorist and I on as a
terrorist for the sky as well. Let's just shoot dis player. If I shoot on the
head, it says it. If I shoot on the
leg, it says thigh. This is, this is the foot, right? This is the thigh. And this is the hand, hand, right, hand
left, and so on. You can see we are shooting
different parts of the body. Now, just to make it a bit
more interesting for us, let us just take
this hit bone name. What we can do is just
like enumerations, where you can do
switch on enumeration, you can do switch
on the name here, switch on name, because remember
this is a name variable. Switch on name and you can
just plug it in before you apply the damage and click
on the plus for the spin. Now you have to specify
what the name is. My name is Head. If you just go back here, you can see it's called Head. You can go ahead
and write Head and then connect it to
here by default, I'm going to apply body
damage by default, but if it is head, we are going
to apply the head damage. I'm just going to
copy paste this. And by default I'm going
to apply the body damage. Now let us get the
information here. If I just copy all of this, our weapon info down here
and our weapon variable, I believe it's on
this long one here. Actually, this is the hit
actor. This one is the weapon. I just plug it in here. Hide unconnected pins. I just want to see the body
damage, head damage here, and connect the head damage, connect the body damage, and also for the damaged actor. Remember to connect this
again like this, okay? Whenever we are
hitting the head, we're doing the head damage. Whenever we are
hitting the body, we are doing the body damage. Let us just click on play
and see what happens. Now if I again play as the terrorist and
I shoot the head, you can see it does 20 damage. If I shoot the body,
it does ten damage. Okay, So now we have
like a head shot damage. Okay, awesome. So
that is working. I'm just going to minimize this. And I'm also going
to remove the debug here for the line tray so
I don't see the red lines. And that was it for this. Again, you can make a
more complex system, but just to make this course not too complex, this is
how we can do it. We're doing some head damage and some body damage as well. Remember to set the values
out of the data table. You can adjust those numbers. Yeah, let us go ahead and
move on to the next one.
160. 11.03 Player Info Structure: All right, so now we are
going to add the health for the player and the armor
and the amount and so on. But before we do that, let's actually create a
player structure. Now let's go to the blueprints
and go to Structures. And now instead of
the weapon info, let's right click now go to Blueprint and then
add a new structure. And let me call this
one layer info. Let's open it up. Now
for the player info, what I want to add is what is the maximum health that
the player can have? That is a float, not an integer, because sometimes it's
calculates like a decimal place. And then you run up the health. Then you have the Max Armor. Remember we also have
the armor in the game. I can add more to this. Remember if you go to the
player and player base, we also have some
running properties. We have the walk speed,
run speed, crouch speed. You can also actually
have it inside of here. We don't need to have
separate variables out here. Just add the run speed. I add the walk speed, I can also add the crouch speed. Like this. Okay,
now we have this. What we can do, we can
delete those later. So we need to just finish up this first before we delete it. Whatever you have like a static value that
will not change. For example, what
is the run speed, walk, speed, crouch speed. And they'll not change
during the game. If you have static numbers, it's really nice to add
them inside of a structure. I think that was
it inside of here. What we can do, just
go ahead and save it. Save everything. Let us move on to the next one and
create the data table.
161. 11.04 Player Info Data Table: All right, so here I am
back at the data tables. Now for this one, the
old one I'm going to call down here DT weapon info. Let's actually create a new one. I'm actually just going
to duplicate this so I don't have to reorganize
all of this stuff. And I'm just going to
call it DT player info. Let's just click on control A and then just delete everything. Okay thing here. Let's just go back to, go back to the structure
and see what we have. Not the weapon info,
the player info inside of here.
What we have first. Now, before you add anything, you need to have an ID column. We have that in the weapon info. Remember, we have
this one called ID. We need an ID one for this one, we don't really need for the ID. You can just call the name, for example, you
can call it one. Let's just call it one
because we will only have one row for the player with
all of the information. We don't need
multiple rows here. Okay, For the first one,
we have the max health. Then we have the armor, and then we have the run speed. Then we have the walk speed, and then we have
the crouch speed. Okay, we have those values. And let me just make
this slightly smaller. What you can do now
is now for the ID, we have set it to one
for the max health. I'm going to set it to 100 for the max armor 100 as
well for the run speed. Now we already have set
those two at default value. If I go to the player, I click on the run speed, it is set to 750. Right now I'm going
to set it to 750. For the walk speed,
I've set it to 400, and for the crouch speed, I've set it to 200. So let us write that.
Now we are ready. Let's click on file download
TSV just like before. Let's open it up
here and let's call this one player info. Let's close this. Now over in the data tables. Now before we import it, I'm going to create a new one. Go to Miscellaneous
and select Data Table. Now let's select
the Player Info. Click. Okay. Let's
call it T Layer Info. It is here. Now we can import it if you click a drag
right now into this. Now it has uploaded
all of the values. Also now it is working and
we can save everything. Now remember, when we need
to use this data table, we have to create a function inside of the library
just like before. Let's create a new
function in the library. New function, Let's
call this one, get player info, because
we need to do that. Let's just copy paste
the thing here. Let's copy paste all of this. Paste it inside of here. Connect this like here. And let's connect it here. Instead of the DT weapon info, we need the DT player
info and return. Drag it into here
and call it info. Let us compile and
save everything. Also, remember to change it into a pure function
just like this one. Because we're only
getting information, we're not setting information. Let us try to use it just to
see if something is wrong. Let's go to, for example, the player, their base. Let's say I wanted to use it. Here I can rightly say get
player info, and here it is. Now you can get the player
info from this one. Okay, Right now we don't
really have like an ID. Just like when we used
with the weapons. Like we have a weapon name. From the weapon name,
we're extracting values for the player base. We actually only
have one line of code or one line
in the data table, we only have this line here. It doesn't really make sense
to just write one every time to extract from
this line from this ID, because it's going to stay
the same all the time. To make it better,
what we can do, we can actually just go back here in the player info here, then we can actually
just disconnect this. We can actually also
just delete all of this here and remove this
variable from here. Now what you can do is just the row name,
it's always one. Just set the row name to one. That is it, if I compile
now in the player base, when I say player info, now it always gets
that player info. So we don't really need
to write anything here and it doesn't really make sense when we have one line Anyway, we're just getting the
data table information from that first row. Okay? Now we have this
information and we can use it. Let's just save everything
and move on to the next one.
162. 11.05 Setting the Base Health & Armor: All right, now we are ready
to set the base health. Right now, when we
spawn into the level, our health is basically saying 76 because this is what we
have set inside of the UI. This is just a static number that we set here through
this percentage. It doesn't really
make any sense. Let's go ahead and
set the base health and armor whenever we spawn. For that, let's go to open up the player
base, it's out of here. Let me go to the Health
Armor and Damage graph. I want to make two events. I want to make the first one
called Set Layer Health. I want to make the other
one called Set Layer Armor. We have these two. We want to run it through
the server as well. Let's run it through the server. Set layer also run this
one on the server. Set layer armor. Let us run them both on
the server and reliable. Let us run the
server one up here, dragging and saying set
layer for the armor one. Let's strike from here
and say server layer, set player armor just like this. Okay, now I'm just going to move this down so we have
some more space to work with. What we want to do is simply just set the health variable. Now we need two variables here. We need one called
current health, because in the structure we
made one called max health. This is the maximum health
the player can have. But we also need one
for the current health. Right now we have the current
health and current armor, both for the health here.
Let's take it up here. Let's set the health
in the server one. Drag this pin into the
event it creates one. And also drag this pin further
into this event. This one. Remember, you are setting
the variable on the server. You need to have
this replicated. The client also can see what
the other players health is. You also need to do it for here. Let's strike for the armor. Plug it in and plug it in
here. Plug it in here. Let's set this one to
replicate it as well. Now we have this. What we can do with this now is let me
just move them together. Now I can go back
to the begin play. This is where I want to set
the players base health. Whenever the player
spawns instantly, you're going to set
the health over here. I want to direct from
here and say Set Health. Our Set Player health is what we call it, Set Player Health. We also want to
use the other one called Set Player Armor. Then we have to specify what is the current health
and current armor. It is full when you spawn. When you spawn, I want
to say get player info. We can break it here. Then we can set the maximum
health here for the armor. We can do it like this.
But I actually think I'm going to make two
different functions. But this one I'm going
to right click and say promote a function or
collapse to a function. Let's call this one, get the player max health and
make it into a pure function. Instead of this insane, insane name, I'm just
going to say Max Health. Let's go inside of here.
Let's just organize it a bit. Let's do it for the
other one as well. Let me just copy paste this. Excellent. Copy paste this. Let me just duplicate
this one over here. Duplicate. Let's call this
one Get armor instead of the. I'm going to remove this one. Call it Max armor. For the max health,
let's disconnect it, switch it to max armor
and plug it in here. So now we can take this, get player Max Armor and
plug it in here as well. Okay, we just have this
looks a bit cleaner. And now we are
setting the players maximum health and
Maximum Armor. Now if we click on play, right now nothing is
going to show up. And maybe you
already guessed it, This is because we're really not updating the UI right now. We're only setting
these variables and now they are correct. However, we're never
going to the UI right now and actually updating
those values here. This is what we're going
to do in the next one.
163. 11.06 Health & Armor UI Functionality: So here I am inside of
the main Uji blueprint. And now let's go ahead and update the health and the armor. So the first thing
we need to do, we need to use them inside
of the event graph. In order to do this, remember
we need them as variables. Click on the first one. This is the progress part
for the health. I'm going to call it health
just for progress bar. The next I'm going
to call it Armor. Also remember to take
this is variable. So we can see them as variables
here inside of the graph. And I can use them and
we can modify them. Let's click on the text as well. The text we need
to modify as well. The first one is called
Text Health, also variable. The next one is called arm fixed armor and
also is variable. Now we don't really need
anything else to be a variable, This is the only thing
we need to edit. Let's compile and go
over to the graph. I'm going to make
two new functions, the first one called
update, update, health I. I'm also going to make the other one
called update, or they're almost, or they are actually going
to do the same logic. But this one is for the health,
this one is for the Ama. Okay. What do we
really need to do? This is always what you have to ask yourself on your coding. What are we trying
to do right now? We're set this percentage
here for the progress bar. Okay, let's go to the graph. Let's take this progress,
let's get it here. Now let's strike and say
percent because this is what we're interested
in editing here. It is set percent, let's do that. That is easy. Let's connect it.
There is something you need to know about the
percent for a progress bar. You can see here, it
goes 0-1 It doesn't go 0-100% it goes
0-11 is 100% here. What we need to do now, we need to get the
current health using a float current health. Let's make that variable,
this current health. Let's say for example, I have 100 health and I got
damaged like ten, and now I have 90 health. If you plug this in right now, the value will be 90. That doesn't make sense because
the maximum value is one. Even though you have like
one health left of 100, it will still show
you the full bar because one is actually
the full bar here. We need to divide it somehow. We actually need
the max health as well, current health, health. When we divide those, if you drag from the
current health and divide the max health, for example, let's say
you have 90 in health. We can say 90/100 because
this is your max health. This will be 0.9 Then the
0.9 we plug into here, that will be correct because
now the percent bar will be something like this
whenever you lose ten, okay? For example, let's say
I have 40 health left, 40/100 is 0.4 and that
will plug into here. And the progress bar will
be at 0.4 Like this, it will be correct now. Okay, this is out of the way. Let's do the same
thing over here. We have the current armor
and we have the max armor. Then we are dividing
those two together here. Let us take the progress bar for the armor and
say set percent. Go ahead and connect
them together. Now let's connect this here. Now we're also setting
the armor correctly. The next thing we need to do
is also set the text here. Let's click on the text. This is this text Health. Let's take it here
and say Set Text. Let's see here. Set
Text, It's this one. And let us connect
it now. Set text. Let's do the same thing
for the armor set. We need to update both of them. What needs to be in the text? What do you need to display
here? This is very simple. Just this variable,
the current health. If my current health is 40, I want to display the
number 40 here. Very easy. Let's just strike from
the current health, log it into here. And like Unreal Engine
will automatically convert the float variable into a text variable and it will
just plug it into here. Okay, very nice, Very easy. Let's do the same
thing over here. Let us break this current
armor. Plug it in. And just like that,
that is now finished. Okay, so that was it. This is updating now the armor and this one
is updating the health. Let us continue in the next one.
164. 11.07 Updating the Health & Armor UI: Okay, now what we
need to do is we need to update the
player's health. Now we set to the
health right now. Remember in the player base
in the van graph we set to the player's health and armor when they spawn,
that should update. Now we can update it
in another event. But I think it's better to just do it like continue
the code here. And the health, when
we set the health, we set the variable
and replicate it. Let's just continue
the code here. Let me just drag this one down. I have more space. Let
me create a new event. Remember, when you update UI, it is running
through the client. Ui is running
through the client. You catal it, do it up here. We have to create a client event called Set Player Health. Then you have to run this
on owning client reliable. Now what you need to
do with this one is, let me just take all
of this away here. We already have the
WB main reference. Remember we have the
player controller here. And we can say in like this. Then we can drag from
here and say update, I believe we called it
update health, this one. Now we can connect it
into the event like this. We can now plug the
health now here, let's call the client
event CL update or CL set player health. This one for the current health. We're just going to
plug in this one here for the maximum health. We already have a
function that we created, set max player health. Like this here. Okay,
this is fully functional. Now let us do the same
thing for the armor. We have the set player armor. Let me just move this
down a bit like this. And let us make a new
event called L, Set armor. Run it through the
client, reliable. Then run the client one up
here, Set player armor. This one for this one, just before you need the
player controller reference, you need B main. Then we need to call the
update armor y connect, connect the variables to
the event just like before. Let us connect the
current armor here. For the maximum armor, I am going to plug
in the function, get player max armor. Remember the function is
basically just getting the player info and taking
that information from here. Okay, let's go back
to the event graph, Health and Armor here. And now it should be working. We're calling the event,
it's going to update the UI, whatever we call
Set Player Armor or Set Player Health.
Let's click Play. Now if I select Terris, you can see it is
correctly set to 100.100 What is happening
is in the Begin Play, we are setting the
players health. Remember the player
health you have defined in your data table,
this maximum health. It's setting the player health. It's going to go here to this event going
through the server. The server is going to set this variable to whatever
you have plugged in here. Then it's going
to update the UI, these values, because
it's going through the client updating the UI. It's going through
here update health UI. It's taking those numbers
you have logged in. It's giving you the percentage because you have divided those. And then you are also displaying the text correctly to the
screen through this one. This was it for updating
the health and UI, actually, our health and armor. And now we can actually use this set player health and set player armor as well when we are dealing damage
to the player.
165. 11.08 Dealing Damage to Health: Now that we are finished with the set health and set armor, let's go ahead and deal
the damage to the player. Here we have the any
damage event that we used before and we just used it to see if we actually deal
damage to the player. We checked that in
the previous lessons where you hit the head,
you do some damage. If you hit the body,
you do another damage. And we can see it's printing,
so it's actually working. Any damage is working
here. Okay, fine. So now we want to deal the real damage here
whenever you deal damage, and this is coming from
the applied damage. So if you go back to
the shooting logic here for the trace line, trace, when you hit the player, you are dealing this damage. If you apply damage to an actor, it will automatically
go ahead and fire this, any damage event if you
receive the damage. Now whatever damage you receive, this is the damage that you have applied here inside of
the applied damage. And we said that inside
of our data table, we're applying damage to the player here in
the any damage. What we can do now, we can take the current
health for the player. We can say, for example,
right now my health is 100. Then we can say 100 minus. We're subtracting 100 of minus, let's say the damage was
ten, that will be 90. We have to set the health again. Before I do that, I like
to have this clamp node. I'm just making sure we're
not going below zero. We don't want to have a health
of minus ten for example. We're clamping this value to be, the minimum is zero so it
can't go below zero anymore. And the maximum, I'll
just drag this one, get player max health
and plug it into here. Now it is clamped. And then
we can set the health again. Let's set the health to
this value that we have. Okay? What is happening is basically you're
dealing ten damage. For example, it's going to say the current health which is
100 minus ten, that is 90. We're going to go
through here to make sure we don't go below zero. And the value of 90 will
be plugged into here. Now the new health that
we have is actually 90. Now instead of setting
this health like this, this would work because
if you have this icon, this means that this
runs on the server. If you hold the mouse over it, and at the bottom it
says authority only. This event only
fires on the server. Again, it is okay to set
variable or it is correct to set variables on the server
and then replicate them. That will work perfectly. However, remember we already made this set player
health event, and this also updates
the UI for us, instead of just
calling this UI again, and we have to update the UI. If we had to do it this way, we had to copy this, paste it here, and
do it like this. Instead of doing
this, we already did a function or an event here. Let's say set player health. And we can just call
that that we just made. And we can plug it into here. It will automatically
just go through this and update the UI as well, because we called it here, fine. All right, awesome. Now
also here for the death, if the current health is equal to zero and we
can make a branch, if that is true, we want
to call a death event. This is when the player dies, when the current health is zero. We'll do that
later. But for now, we have this connected. Okay, let's click
on Play and see if it actually works here. If I just take a weapon
and I shoot the player, now you see the player
has 90 awesome. If I shoot the head,
he shot -20 Now I have 70 health that is working correctly. Let's
try it on the server. If the server shoots the client, let me just minimize this here. If the server shoots the client, that is working
as well, awesome. If I loot like
another weapon here, that is working as well. All right, that
logic is working. Now let's go ahead and do the
armor in the next lesson.
166. 11.09 Dealing Damage to Armor: Okay, for dealing the armor, we're basically going
to do the same method. However, for the armor, I actually want
to do less health to the player if you
already have armor. So I'm not going to
do the same amount of damage to the health, just moving all of
this away, like this. And I want to do the armor
first, just moving it away. Okay, so let's take the
current armor right now, it's 100 as a beginning. What I want to say is, let's take this armor and let's subtract it
from the damage. I don't want to subtract
it just one by one. I actually want to subtract it, this value, the damage, if I just multiply it by, let's say 1.5 and then I want to apply the
damage to the armor. The armor is going to be damaged a lot faster than
the current health. It's not going to be damaged
like the current health. It's going to be damaged a lot faster because we
have multiplied it by 1.5 I can also just
drag from this one, It stays organized
like this here. Awesome. Now, with
this subtract, what we can do is, again, just like before,
let's clamp the float. We make sure it
doesn't go below zero. The maximum is let's get this player max armor
and plug it in. And now let us set
the current armor. Again, we have the function
called set, set player armor. And we're going to set
the armor just like this. And now it is implemented, okay. If you just play here and
we can just try it out. You can see here, I am the
client shooting the server. We are losing the armor. Now, there is no point to
having an armor if you're going to lose that health that you're getting
damaged for anyway. So right now this
doesn't really make sense because you're still
losing health and dying. What I want to say is
if you have armor, you're going to
lose slower health, a lower amount of health. What I can do here, instead of subtracting the damage
from the health, this one here, instead of
subtracting the damage I want to drag from here and
say select float here. Now we want to ask, is
the armor equal to zero? Let's take the armor and say, is it equal to zero? When it says pick a, if this bullying is true,
go ahead and pick a. If the armor is zero, that means we actually
just want to apply this damage that we had
before just like this. However, the armor
right now is not zero. This will mean it's
the B value here. Then I actually, this
means we have armor and I want to deal slower
damage to the player. If I just drag this here, I want to direct from here and then say divide this damage by, let's say for example, 2.2 0.5 Let us then deal the damage. We're actually
reducing the damage before we deal it to the player. Okay, now it makes sense
that we have armor, because when we have armor, we're actually going
to take less damage. And let us click on play. And let's try out
this mechanic here. If I walk over to the server, if I just shoot the player here, you can see we're
taking damage now. The value here, we need to
remove the decimal places. That is fine for now. But you can see the armor is working. Whenever we lose the armor, we're going to take
a lot of damage. We're going to take the damage that is there without the armor. Okay, this functionality works. You can always
control these values, how much armor you lose here, also how much he you're losing. But now it is
working for the UI. We actually need to remove
the decimal places. Let's go back here
in the B main here. What I want to do is I basically
want to round the value. If I take this float, I can use this one called round and we're
rounding the value. If the damage right now we're not really
in the minus, but let's say in the plus. If we have 1.6 health,
it becomes two. We can use that one and
we can round the value. And now we can drag this into
the text and plug it in. Let's just delete
the old one here. Let us set up this instead, and do the same thing here. Let's use round and
delete this old one. Plug it into here.
Let us organize this. Let's now test this out
and see if it works. Just creating some route
nodes to make it look better. Now let us compile,
Click on Play, and let us see if
it actually works. If I show the player, you
can see it is rounding the value now everything is
working as it is supposed to.
167. 11.10 Preventing Looting Multiple Rifles: The problem we are
facing right now is if I just click on play here
and maximize my window. You can see here I
have looted an four. However, if I click
here to loot a weapon, I can actually loot this AK. And I can even loot this four. I can even loot this one, and they're all on my back. This is not supposed to happen. And there is a puck inside of the code in here in
the player base. I believe it's a simple fix. Let's go over to the lot. Equip and drop logic here. Over here in the lot weapon, something is going wrong
because we told it not to loot the weapon if it is the same weapon as
what we have equipped. It's this one request
loot weapon because here we are trying to find
the weapon in the inventory. We're trying to compare the
weapon with the inventory, with the one we
are looting right now. We're going through this. We're taking the weapon
from the inventory. We're trying to check if we
already have this weapon. If we already have it, we will
drop the weapon Are false. If we don't have it,
we load the weapon. For some reason I
believe it's going through here instead of up here. It's not dropping the weapon. It's like it can't
find the weapon. If I just print a string
here and saying two up here, I print another
string and write one. By the way, this
is how you debug. Now I'm going to see where
the code is running. Is it running up
here or down here? Let's compile and click on play. Let us now just
load this weapon. Now if I click on, it says, if I allude this
one, it says two, the code is actually
going down here. It's going down
here on the false. It's like it's saying, no, I don't have that item in my
inventory and that is false. I actually have this
item in my inventory. Let's see the code here.
Let's go over here. It's trying to find, it's trying to
compare the item in the inventory with the
one we are trying to lot. What is happening here is it first searches here
in the index zero. It searches in the first
index of the weapon. If I just go back here,
just close this down. If I go back here
to the logic here, when it doesn't find the
first weapon, for example, if the first weapon is a pistol, then this one will
be false actually, because you're
comparing the pistol to the one we want to
loot right now. And it's not a rifle, meaning that it actually
just goes to false. And then it adds this
weapon over here. We need to adjust
the code down here. What we need to do
is we need to make sure that it has looped through the whole inventory before
it continues the code. If it just gets the
first inventory item, which is the pistol, then it doesn't really
make any sense because it's going to give us
a buck just like now. What I want to do is I want to make sure
that this index here, this index you can see here. If I just right click and print a string and I can
just show you. And you can plug in the index so you can see what
it prints out. And I can compiling com
play when I loot this one. Now it says zero. It keeps saying zero because it only looks at
the first index. Now the rifle is, if I just click plus here, the first one could
be the pistol, the index one could
be the rifle. And it keeps checking
index zero only. Now let me just delete all
of this and delete this. Let me plug the ray
index over here. Let me just move it up. Let us just move it over
here and call it ray index. Let us compile, let us go back. Now, I want to check if this is the last index
before I continue. If I just take the
inventory and let us find the variable
here, weapon inventory. Let's get that. Let's say last index for this weapon inventory
that we have right now, is this number equal
to this area index? Let us just make
it prettier here. Now let's make a branch. And we're asking, are we at the last index of the inventory? Let us just delete this. Let me plug this in.
If that is true, we want to continue the code. However, if we are not
at the last index, if we still need to check
some things in the inventory, we have to loop back. And actually we don't have to do anything because if it
is not the last index, we're simply just going
to loop through this. Actually, we're not
breaking the loop, we're only breaking
the loop here. When we find an item, I actually don't need
to do anything. Let me just organize this a bit, let me move this away, and that should fix our problem. Okay, here I created some route nodes and it
is looking prettier. Let's now click on Play
and see if it works. If I just loot this
weapon for example, and I click on, you can see it actually
drops this in four. And if I click on here, also drops this one. You can see here it is working. I can't loot two rifles
at once and it is also working with a pistol
probably like this. Now I can see I can't loot
two weapons at the same time.
168. 12.01 Death: All right, so now let us
create the player death. Remember here we did the
any damage event and we calculated the health and armor and how much
damage you took. Now we said this one
here at the end, if the current health
is equal to zero, we want to play the death event. Okay, very simple. Let's overere make a new fast
event called death again, let us run it on the server because we are on multiplayer. Let us run it through this
server, reliable death event. And let's run the server death up here in the normal event. So it runs through like this. For the death you can imagine we're actually going to
make like a rag doll death, where the player just
falls on the ground. Now we can say play
animation montage. However, I just want to
make it a bit more fun and actually create a rag doll
death instead of an animation. Because we have
done this before. We know how to do this
instead of a multicast. I want to show you how
to do rag doll death. To do this, now we
need a rep notify because you are going to change
the visuals of the game. Remember, if you want to change any visuals for a
rep, notify here. Let's make a new event
or a new variable. And this one is going to
be called is dead Bullion. Let's set this is
dead to be something. Let's just drag it
into the event. And this one drag it
into the event as well. We can actually call this one. Now let's go over here. If the current health
is equal to zero, let's call this death event. Let us set the
player to be dead. Remember to make this true. Now we need to rep, notify this. Rep notify it
creates a function. So let's double click on it. Inside of here, what we
want to do is simply, first just ask, is the
player dead or not? Is this bullion true or false? Okay, what do we
want to do to make reg dole death when the
death variable is true? We want to simulate
physics with this mesh. Because if I just go over to the marketplace and
open up the era, just one of them
doesn't really matter. And you just open up
the physics asset. You open up the physics
asset as you can see here. If you click on Simulate, you can see the player
dying like this. This is actually reg death
if you just simulate it. And you can see it, this
is what I want to do. To do this, we need
to simulate physics. Let's take this mesh
and say simulates. Set simulate physics to be true. I also want to disable the
movement for the player. So you can't press on
your keyboard and move. The player take the
character movement and say disable movement. Now the player cannot press on the keyboard to move around. Let us just compile and see what happens if I just click on play. Now I spawn the other
player as well. Let me just shoot this
player and see what happens. I'm going to shoot this player. The player dies but falls
through the ground. Let's actually fix that as well. We need to mess up
with some collisions. And this is because the mesh
is now simulating physics. If we take a look
at the mesh here, if we go down to the
collision settings, we can see that it actually
has no physics collision, meaning it's going to
fall through the ground. It only has overlap. Physics overlaps when I hit with my line
trays to do damage, but it doesn't have
physics collision, we need to enable that. Let's take this mesh now. Let me just drag from here
and say set collision. Let's just go down here. Set collision enabled. I'm going to enable collision. I'm going to collision
here. Collision enabled. I have both a query and physics. Go ahead
and select that. I'm actually going to do
it before the physics else the player will
fall through the ground. I'm going to enable
the physics first. Let us try that. Now
we have physics. Okay, that bug is fixed. You have to try to see
what other box we have. Now again, I'm going to go
and kill this player here. Okay, Now the player is
dead. The player is here. Awesome. One problem with this player right
now is actually, it has the idle animation on. Because I can see the
player breathing right now. You can see the shoulders are moving and we have an
animation playing. We need to stop this animation
because it looks silly. Let us do that.
Let's stick here. You can actually
say play animation. You can select this
play animation. You just don't set anything inside of here that
will actually delete all the animations
and the player will not have any
animations applied. Now again, just double
click here to make a reroute note so you can see
what I'm doing and follow. So it's not difficult
just like this. Okay, now let us compile. I believe I noticed a bug
with the shadow as well. If I just spawn the player again. And I showed the player. Okay. Awesome. Now there is
a bug here with the shadow, because here as this player, you can see I can move around. This is because, remember
we have a third person mesh. Third person mesh. What we did before is if
you search for shadow, we made this one
show hidden shadow. We did this remember, a long time ago in this course because we wanted to show
the head of the player. We are using this third person mesh to show correct shadow. Let us third person mesh, let us just do it over here. For example, say set hidden, I believe it's called a set set hidden in game set
cast hidden shadow. This one, let us just say nothing because I don't want
to show my shadow anymore. There's also one
last thing I forgot. And this is the
capsule component. This capsule component,
I don't want it to collide with weapons
and things like that. I'm actually going to disable collision for this one as well. I'm going to do that before I enable the collision
for the mesh, because maybe sometimes this capsule collides with this
mesh and it creates a mess. Let us move it away and
say set collision enabled. Let us just say no
collision just like this. And that should hopefully be it. Let's move this away. Or actually just
move it down here. And we don't need to move it
away all the way over there. Now it should work. Let's compile now.
Click on Play. If I just go over here, let me just spawn this player. Now I can shoot the player. Now we have wrecked
all death, awesome. I don't collide with the player. The player is still not moving. And if I just move here
with the other client, you can see I can move
my camera however I do, like the shadow is
gone, I'm dead here. Of course, you can
make it more complex. Like you can create
a spectator camera. Instead of doing this, you can even disable the camera. You can't, you're like this and you can't
move the camera. But I think it's fine
for now. I love this. Yeah, everything is
working correct. The problem right
now we have is that the player is not dropping the weapons once you
have the weapon. You can see here, once you
have weapons and I shoot you, you're still holding
that weapon. I want the player
to drop the weapon, because imagine if
all the players are holding the
weapons when they die, all of these weapons will be gone like 2 minutes
into the match. I want the player
to drop the weapon, and we can also do that. Let us go ahead and move
on to the next lesson.
169. 12.02 Drop Weapon When Dead: All right, so let's go ahead
and make the player drop all of the weapons when
the player dies over here. Whenever we set this to true. So let me just drag
from this and make a branch and ask if is
dead is set to true. Because later on we
are going to set it to false when the player
is responding. But for now, the player is dead and we want to
drop the weapon. Okay, let's go back as a reminder and see what we
did for the drop weapon. If I go back to the
lutqudrop weapon event, or a graph, and for dropping the weapon,
it's actually over here. And we pressed the button and
then we dropped the weapon. We actually just need to
call this event here. We're not really
pressing a button, we're just forcing the player
to drop all of the weapons. So we're actually
going to do this. This event looked for the
equipped weapon type. And I think we need to
modify this because it's not only the equipped
weapon we need to drop, we also need to drop
the other weapon that is on our back
or on our thigh. We need to actually modify
this code slightly. Let's go back just to write it down and see what
happens over here. Let's call the server. I believe it's called
request request drop weapon. Drop weapon. This one. And go ahead and
call it right now. When we call this one again, it's going to drop
the equipped weapon, but we actually
want to drop all of the weapons in the inventory. Let me just modify
this for this event. I'm going to add a new variable. Let's add the weapon base. Because let's just
give it the input we want here, weapon base. And let's call it we instead. Here we have to specify
what weapon we want to drop when we click on the
button to drop the weapon, when we click on the K, I
want to drop my weapon. This one here, equipped weapon. Now this is correct
for this one. Now let's strike from
here and say name. Get the name variable
just like before. Get weapon info and break this and then
we can get the type. Instead of doing this, we can delete it and we
can plug this in a, let me just move all
of this code away. This, and we can see
what we are doing now. We have organized everything. Everything is looking good. Just expanding this here. Expanding this here as well. Awesome, We have this set up. Now if you go the
health and armor graph, now we can specify what
weapon are you talking about. We simply want to drop all of the weapons in the inventory. Instead of doing a four loop, I could do a four each loop, again with the inventory here. And we could plug in the
inventory for each of them, we could drop the weapon. However, remember with
a four each loop, it doesn't wait for
this code to play. It's going to play two times
of this drop weapon code. It's actually going to bug your code here because it's going to change the weapon here. It's going to change this
value here before you have a chance to finish
this cycle of code. Instead of doing this,
what I'm going to do is I'm going to
do a manual loop. What we can do here is we
can take the inventory. Just make sure this
one is not empty, because we don't want
to drop weapons. If this doesn't have anything, let's take the length of this inventory and make sure
that it is greater than zero because we don't want to do anything if it is
greater than zero. Just like that. If it's
greater than zero, also go ahead and
drop the weapon. If it is greater than zero, this means we have
something in the inventory. Let me just get the first item
we have in the inventory. This will be at index zero. I want to go ahead
and drop this. Let us strike from here. Just like this, I believe. We don't need to do more here. Because if you go back
to the drop weapon, remember inside of this
drop weapon function, you already remove this
item from the inventory. Because it's very important to remove it from the inventory. Now else you're going to get
like an infinite loop here. Let us delay this code. Let's delay by something like 0.1 Then we can go back
and play this code again. Then we're going to say again, I'm just going to
make some mirror out notes so we can
actually see what I'm doing for this one here, just like this and just make it on the
other side as well. What we are seeing
here basically is drop this weapon and then delay the code and then try
to run this again. Try to check if this
length is still over zero. Remember, we remove it
here in the drop weapon. Technically it should be zero
if we only had one weapon. However, if we have two weapons, the length of this
will still be one. Because the length of
it was two before. Because we had two weapons. Now it is one weapon.
Going to check again. Is the length over
zero If it is. And take it again. Take
this weapon. Drop it. So it keeps dropping
until you don't have anything anymore
you can drag from here and say no more
or no weapons to drop. It will print the string if you have zero weapons to begin with or if you have dropped all of your weapons
from the inventory, now you can make the smaller, I believe 0.05 maybe even. But let me just go with 0.1 It doesn't really matter that
the player will not notice. Anyway, let me just
click on Play. And let's try it out
and see if we bug out. If I have this weapon here, this player loots
all these weapons. Actually, let me move
this player over here. So we can see the
weapons being dropped. Let me shoot this player. Now we can see the player
actually drop the weapons here. This pistol and the K. If I just drop this and I
go over to the pistol, I actually have a pistol
myself, so let me drop this. I can loot this pistol. I can even loot the K
this player dropped. I can lot it just like before. Nothing really wrong
with it. Awesome. Let's try it on the
client as well. This was the server. Let me minimize this and
go to the client. The play for the server. I'm going to want the server
going to lot of weapons. Now as the ions going to shoot the players, here they are. I'm going to drop this in four. I want the K, I can take it. Awesome. Everything
is working right now. Right now we have an issue with not being able to loot
two weapons right now. Sometimes we have
an issue where we have dropped the weapon and we can't really loot it because it tries to compare
it with the dropped weapon. Let's actually go ahead
and fix that as well. This is like what we did
with the weapon fix. If we just go back, if I
go back here in my graph, lute and equip and this is
the weapon code we did. Remember we compared the
lot weapon variable with the one we want to lot right
now if it is the same, we cleared the notify,
then we run it here. Because remember if you have
the same value run twice, it will not run. Simple as that. Let's go back. Let me just open
up the drop here. Let's go over to the
drop weapon here. The way I want to do this
is because inside of a functions you can
actually not make a delay like we
did before here in the lot weapon where we made a delay here before
we run the code. In functions you
can't make a delay. This is something else. This is not the normal delay
we usually make. We need to actually do it
outside of the function. We need to do it
out here instead, over here, when we want
to drop the weapon. Let's make the code here. I want to make the weapon to drop here and set it
to nothing like this. Then I want to drag from here and say delay just like before. Set it 20.05 and then I want to go ahead
and drop the weapon. Before I do this, I don't
want to do this all the time. I want to check if this
is the same as before. I'm going to take this
weapon to drop and say, is this equal to the weapon here in the
inventory that I just found? Let me make a branch.
If that is true, I want to do this here,
let me move it back. If that's true, I
want to do this here. If it's false, I just want
to run the code like before. Let me just reorganize this so you can actually see
what's going on. Okay, just like this, we're trying to compare the weapon to drop with the one we're
trying to drop here. And if it is the same, we're going to clear this
out and do all of this. Okay, awesome over here, we
actually don't need this. We can just delete
this one from here. Also the other thing,
sometimes again, the weapon become invisible because this actor cannot
recognize this actor, even though they are the same. Instead of doing this,
let's just delete this. Delete this, and let's
just take it down here. Instead, we constantly delete this weapon to drop
before we set it again. And that is fine. There's not really any problem with this. Let us actually do that
as well for the looting. Instead of checking if it is the same thing,
let's delete this. Let's just do that
because it doesn't really hurt too much or
it doesn't really hurt. Actually, it doesn't
really matter. Just go ahead and
connect it like this. Go ahead and compile. I'm going to click on play
now, check again. It's mostly for the
client because this is where the replication
issues will happen. Here. As the client,
as the server. I'm going to loot some
weapons and stand out here and let's
kill this player. Now the player is dead. Now I'm dropping my weapon
to loot this one up. I'm dropping pistol now,
loading the pistol. Works so we can
loot both pistols. Let's load this weapon. Just keep looting the weapon
and see if you bug out, if you have any problems
or if everything is fine. We can see nothing is
getting invisible, everything is looking good. I'm just trying to see if
there is a bug right now. I believe I saw a bug where
actually I dropped the four. You can see now I dropped the in for when I press instead. Right now the bug
is if we choose a player here and we
equip two weapons, and if I click on G
to drop the weapon, you can see the weapon on
my back is getting dropped. And this is after the new
edits that we just made. Let us check what is happening. The problem is maybe
with the eluding the weapon or dropping
the weapon here. For the dropping the weapon, we are dropping the
equipped weapon. Let's just first check
if this is true. What is the equipped weapon? Let's actually do it down here. Let's do it down here so we can print out the weapon name. Just plug it in here
and compile and save. Now it should say pistol. When I try to drop my weapon
and it does say pistol, the equipped weapon is correct. There's nothing wrong
when we loot the weapon. Now we know the loot
weapon. Logic is correct. We're trying to drop the pistol, but for some reason the
rifle is getting dropped. Now let us print this. Let me also try to see
if I am unarmed or not. Actually, it doesn't make sense because we are
dropping the weapon. So we know we are not unarmed, we're dropping the pistol. Something is going wrong here. And I believe this loop, again, I told you before, loops do not wait for
what you're trying to do. This is one problem with loops. Sometimes they
just run the code. If I just go back here, I believe it's trying to drop the second
weapon that you loot. Because it's not going
to wait for your delay. It's actually going to loop through and drop the last index. I believe this is
what's happening. Instead, let's us
disconnect this. Let me delete this. Here,
let me move this away. Now, when we find a weapon, let's make a new variable. Let's make a new one called
found weapon to drop. It's this one, found
weapon to drop. Let's set this found
weapon to drop to be true. Then let's break the loop. Now we have found a weapon and just make notes
just like before. What we can do with
this now is let me just disconnect this
and move this away. Now let's take this and
make a branch and ask, do we have a weapon? He found weapon to drop. If that is true, we want to
first set this to false. Because the next
time we do this, we want to make sure
it's not bugging out. The next thing is we want
to drop that weapon. Just moving this away here, and this is okay. We're going to drop the
weapon just like before. But we're going to do it
down here when the loop is actually completed here. And the weapon to drop can just be the weapon that
you have right now. Because remember you
have broken the loop, so it is still at the
weapon you have found. We don't need to do
anything inside of here. Then we are going to delay. And then we're going
to set this to be to interact with again.
Okay, let's compile. The next thing we want to do
is all of this is correct. Nothing wrong here. The next thing I want to do, I want to go back to my health armor and
damage logic over here. Just make sure that you
have this delay maybe to 0.2 I think I had to
0.1 If it bugs out, sometimes this is because you're dropping the
weapons too fast. I think I'll make it to 0.2 and let us compile
and save everything. This is the logic
we have so far. If you have missed anything, just make sure that it
is looking like this, as well as the logic for
dropping the weapon. If I just go back
to my graph here, looting, make sure the
looting is like this. We removed the comparison. I can remove this
reroute node as well. This is what we have so far. We just delete this variable, instantly lay for a little bit, and then we loot the weapon. Okay, this is looking good. As well as for the drop weapon, we made this equipped weapon to be attached to this server. And then we use the
weapon type here and make sure we break the loop like
this so it doesn't bug out. Okay, this is our logic so far. If we need to, we can
try to fix things again, but I think this should fix it. Let us and test out and make sure that
nothing is bugging out. I'm going to
minimize the server. I'm going to play on
the client because this is mostly where the
replication is going wrong. Let us take a weapon
here as the server. Now, if I go to the client. Here with the client and I shoot the server here is
I drop the weapon. I try to loot. I can loot it. I try to loot the pistol. I can't because I have one. If I drop it, I go over and I try to loot
the pistol here. Right now I have a replication
issue with the pistol. If I just close it down and take a look again here
for the delays, I have 0.05 after the weapon drop and then
we delayed by 0.1 to make sure we can like this interaction after
we run this function. Also, if you go
back to the health, this one is 0.3 Now we can
try to make it 0.2 again, but let's just keep it at 0.34 Now also before we test stuff, let's go to the
death we made here. Instead of setting the
mesh to collision enabled. Because for the mesh, if you
go down to the collision, you can see that it is interacting with the
weapons as well. It's interacting with the world
static and world dynamic. Let us try to enable
collision only physics, not query, we're not overlapping with the weapons
and causing issues. Instead of collision enabled, I'm going to set physics only because we're only
interested in physics. So we can make that rag doll effect
and fall on the ground. Physics only should
be good here. Let us now try it out
and see if it works. I believe I got a bug before
with interacting player. I want to recall this
box so I can fix it here as the player or the client. Let's
shoot the server. Now I can drop this, try to lot can loot the K the pistol. Now I can loot the
pistol as well. I don't have any
problems if I exit. You can see here I
got an error saying axis non trying to read the
property interacting player. If you just click on the error, here you go to it. It's just getting an error here. I believe it's the
player who's dying. It is actually setting
that player to this when it says axis non. You can just fix this by
making sure it is valid. If I just move this away, I can take this and right click and convert it to
a validated get. And let us make sure it is
valid before we continue. Then the next thing as
well is the bug here, because it gives me that
the era is here as well. Now I made this is valid because it also
comes from up here. You can see it comes
directly to this loop. Even if though we fix this, this will buck
because of this one. Make sure this is valid. It gave us an era
because of this one. We're trying to check things
when this is not valid. Let us make sure here
after the player, and I believe we are interacting with the player
who is dropping the weapon. Let us copy this up
here, down here. Make sure this player is not the one that dropped
the weapon as well. Because we don't want
to loot the weapon, we just dropped ourself. That doesn't make any sense. Let us move all of this away. Just like this, actually, I think we can delete this one, because we're already
asking for this. Let's make a branch and let us connect it together,
Connected with here. If this is true,
we're going to set the interacting player,
let us move it forward. I believe we can delete this, because we just check this. Let's delete. Delete this. That should work fine. This one we are setting
it and then we're checking if it is valid.
That is fine as well. Okay, Now let us
make some notes. The reason why I'm not deleting this and just connecting
it here like this, because I want to make sure this is valid
before we continue. Because we are also
coming from up here and actually directly
connecting to this. Even though we're up here, we actually need
to make sure this is valid before we
continue over here. I'm also going to make sure
that the player is valid. Dragging here and
saying is valid, go ahead and as well, so making sure that the
player is valid and also making sure that
the player is not the one that has
dropped this weapon. Now let's shoot
the server again. Now let's drop the
weapon, load the weapon. Let me just make it
larger so we can actually see what's going on now. Everything is working. I can drop the pistol. If I load two things and I
drop we drop the pistol, we don't have that bug anymore. Okay. I can load everything and I don't get
any box when I quit this. Okay, Everything is working now. I know it has been
confusing because we had a lot of box we
need to take care of. Make sure that when
the player is dead, you are dropping the weapon. We're getting this first
weapon in the inventory. If the length of the
inventory is over zero, which means we have a
weapon in the inventory, we're dropping the
weapon and also delaying by an amount that would not make the weapon drop
buck 0.3 at this point. Right now, maybe we
can reduce it to 0.2 But I'm satisfied
with this right now, no one's going to
know this anyway. Then inside of the weapon drop, we made this loop here. We made this bull in,
so we don't bug out. And we don't need to
replicate this variable because we're only checking
things inside of the server. We're using this variable
outside of the server, so we're never using
it on the client. We don't really need
to replicate it. We're running
through this, we're clearing this variable first. Before we drop the weapon. We drop the weapon, we delay
it to make sure that this is run and then the players
can interact with it. Once again, the delay
is 0.1 for this one. Finally, for the
lot weapon, again, we just directly remove
the lot weapon variable. Notify cleared it and
then we run it down here. Okay, so that was all I know, it's a bit confusing but we had to get rid of all those issues. Now again, if you
have any issues, you're more than welcome
to visit my website, Pixel Helmet.com or you can always talk to me
on Discord as well. You can see my discord on my profile and it is just
the Pixel helmet as well. All right, thank you for watching and let's move
on to the next lesson.
170. 12.03 Respawn: Now that we are finished
with the death, let's make sure the
player responds as well. Inside of the player
base. Again, inside of the health and armor and damage. Let me just strike it over here to the right and right click. And then close
tabs to the right. Okay, inside of here, let us right click now and make a new custom event.
Call this one. Let's right click
again and make it a custom events and call it Re. Then this one is going to run on the server just like before. Let us run this, the
server reliable. This one up here, let's
call the server respawn. Now we are ready to
do the responding. Now for the respawn, what we simply want to do is we want to change the
player's location. Because imagine the player
has died here on the ground. We're basically going to move this player back to
the spawning point. This is what we're
trying to do now. We already have the spawn
points over in the game mode. If you remember, if you go
back to the blueprints, open up the game mode and
inside of the game mode, we have this one
request, spawn player. Now we don't want to
spawn the player, remember we only made the
player dead by not moving. Technically, you are
already spawned. We never removed
you from the game. We don't want to
call this again. What we want to do is we just want to do this
logic once again. What we can do is we
need the game mode to take the counter terrorist
and terrorist spawn points. Let us go back to the player
base and say get game mode. This is just the reference, let's say game mode
like this one. Then connected to this get game mode reference from
our blueprint interface. Now let us get the
darorist spawn points, let's get the terrorist points, this one gets pain points. Now what we want to
do, just like before, let's go back to the game mode. We can actually just take a random spa point and then copy this transform
just like before. We can also copy this here, control C. Let's go back to the player base control
V. Let's connect the condo terrorist
and the terrorist with these and let us now
do a rep notify also, remember to connect this one. We need the team that
you have selected. We need to know if the player is a counter terrorist
or a terrorist. Remember, we did that in the UI. We go back to the UI where
you select the team. You go to the graph here, you selected which
team you are on. This takes you to the game mode. The game mode here, select team. Let's actually create it as
a variable so we can use it, because right now there
is no way we can use it. Let's make a new variable team. If I just hold the
mouse over it, you can see it's an
actor class reference, if you actor and it is this one. And you can select
class reference. Let us compile now remember, we only need to set
things like this inside of the server,
not on the client. Here on the server,
I'm going to set it team and then connect this one down here to
make it more clean. Now, we don't need to
replicate this because we're never going to
use it on the client. We just need to use this on the server so we can find
the correct spawn point. This variable itself
is not needed, we don't really need
to replicate it. Now we set this
variable over here. We need to get the
player control. Let us right click and say get controller and find
the function here. And then let's strike and say player controller reference. Let us connect it now as
the player controller. Let's get the team variable
that we just made. And let us now
connect it down here. Okay, now we're asking, is the player a terrorist
or a counter terrorist? If the player is a
counter terrorist, which means this
is when it's true, we're going to find the
counter terrorist points. However, when the
player is a terrorist, this will be false,
so it will choose B, which is the terrorist points. Okay, let's right click
and promote this to our variable player
respond points. Or actually let me just call it respond transform.
That is more correct. Again, we need to
make it into a rep, notify because we're changing
the location of the player. This is a visual
change to click on it. Let us compile, let
us go inside of here. Simply what we need
to do inside of here is change the
act transform. Let's right click and
say set and selected. It is just self. It is the player who just
died. That is fine. Now for the new transform, let us take this
one we just said. Now the problem with
this one, right? Now the player, if you
click on the mesh, remember we made before I said the scale to be
1.6 in the scale. If I just connect this
directly into here, this will reset to 11.1 This is because this Spain point
here is actually 111. What you can do is we
are actually taking this transform from
the Spain points. If you make this point
point to 1.6 look, let me just go back
here to layer base. You plug this directly in and
you have this to 1.61 0.61 0.6 then it will actually be 1.6 even though you
have this set to one. It's actually taking the
transform of this spawn point. However, for my example
here now for your game, if you have to 111, you don't really need
to do this here, but for me, I'm just
going to break this here. I'm going to transform, break transform here,
make transform here. For the location is fine,
the rotation is fine. However, for the scale,
I want to keep it to 1.6 Let us connect
it just like this. Let's now compile
and let's go back. And we also want to
make sure that is dead is set to false because
now we're not dead anymore. We just respond, drag
from here and say death and set this
one to be false. Now we need to work on this
in the next lesson because we still have simulated physics and we still have no
collision and all of that. And we're going to work on
that here in the next lesson. But for now, let
us click on play. Actually, before we click on play, we need to respond here. We have never called this event. Nothing's going to happen. Let, let's call it here when the player
is not dead anymore. Whenever we set this to false. And let us actually do it here. Whenever you have finished
dropping all of your weapons, let me just delay the
code by 3 seconds. We are going to make
this better later, but for now, let us just
respond and see if it works. We're going to delay by 3 seconds and then we
are going to respond. Let me just click on Play. Elect Terrorist here, Select
Terrorist for example. Now I'm going to just lot
some weapons on this player. Go out here on the client. Now let me just open both
of them on the client. I'm the player here. The player should
respond at one of the spawn points after 3
seconds, As you can see here. Right now, nothing is happening. This is because we have
still simulated physics. And that is the issue. If we just try to click
on the capsule mesh. Let me say here, hidden in game, I'm going to turn
it off so I can see the capsules and actually
see what's going on. And if I just loud
the weapon again, go out here as the terrorist. I'm going to go out here. Now. Let's try again. Let's
shoot the player and see. Because if the capsule moves,
it's not a bug we have. If you take a look
now, after 3 seconds, you can see the capsule
disappeared from the player. And this is because the
capsule is here now. Now the player is actually here. However, the player is
still laying around again. This is because we have
simulated physics. And all of that we
need to work in the next lesson here on
this part and make it work.
171. 12.04 Not Dead RepNotify: All right, so now we are back and we are going
to work on this. Is that when it is false. So this rep, notify and so we can respond the
player correctly. What you want to do first,
let us remove the physics. This is the first
step. Let's take the mesh and I'm going to
say simulate physics off. The next thing we want
to do is we want to cast shadow again from
this third person mesh. So go ahead and do that. What I'm going to do
is put the mesh again. I'm going to drag it down. Set collision enabled. If you just click on the mesh, it is set to query only. I'm going to click here
and set it to query only. I can reset it to
how it was before. Let us just make a reroute
node here and move it down. The next thing we
want to do is just look up here and see
what we need to do. Now. We need to take
this capsule component and we need to click on it. And we need to set it to collision enabled,
drag from here. And say set collision
enabled and select it. Then set collision enabled here. For this one though, now this one is correct. Also, remember we
disabled the animation, we need to run it again. The animation for the player
is this animation blueprint. This one up here, animation mode is set to animation blueprint. We actually need to do that again from here. From the mesh. And remember this is
the mesh here from it. And say set animation mode. And go ahead and select
this set animation mode. And you need to set it again
to use animation blueprint. Right now when we set it
to animation blueprint, we actually need to also define
what animation blueprint. Because we reset
settings up here, what we can do is we can drag from this
mesh again and say class it is this one
set animation instance clad and connect it. It is the one we called
an MBP player here, the animation blueprint
we created before. Now what we need to do, we're still going to book out because I'll just show you and you can see
what is going on. If we just open this up again, plays the terrorist here. Now let us shoot this player. Now this player is shot. And you can see here the
player is still porting, but there's nothing here. And I'm also laying on the
ground on this screen, there is still a bug. This is because, remember
with simulate physics, we had this problem
earlier in the course. If you hold the mouse over it, it says if this component is currently attached
to something, it is the mesh is attached
to the capsule component, Then beginning simulation
will detach it. It's actually detached from
the capsule component. We need to reattach it again. Let's take the mesh here. Whoops, not both of them. Let's take the mesh and let us say attach component
to component. If you don't remember
what we did, you can always click
on the looted weapon. Notify if you find the unwrap looted weapon.
This is what we did. We disabled physics and reattached the weapon
to the root scene. Here is the same thing
that we are doing. Let's go back to here. Now we're going to
connect again or attach the mesh to the
capsule component. Remember it is connected
to, let's actually nothing. The socket is none.
For the location rule. Let us say snap to target. Snap to target. Snap to target. Okay, let us see what happens if you just
click on Play again. And test it out
here as the player. I'm going to shoot
the player again. Now let's take a look
at what happens. The player is spawned over here. However, there is
still an issue. The player is down here, also on my screen, the
player as a weird camera. The reason for this is because if you click
on the Mesh again, when you simulate physics, you reset all of your settings. For me, the location is this
and the rotation is this. For the player, initially
this is also reset it. I actually need to
set it back again. If I take the mesh and say set set relative location and rotation, I need
to plug that in. I'm just going to
click on my mesh and copy my location. Paste it in. This is the z value
and the rotation is -90 Let us now compile,
save everything. Let's see if
everything is working. Let's click on Play. Like
Terrorist again, like this guy. Let me shoot the player now
and see what is happening. Now the player is
spawning on the ground. For some reason, the
survey reconsidered. Now we are looking normal. The only problem
we have right now is that the player is
spawning in the ground. To fix the issue where the
player is beneath the ground. What we can do right now when we click on play and the player is actually spawning correctly, there's nothing wrong with
the St. points themselves. We don't really need to
do anything with those. The problem right now
is inside of here, whenever we attach this player, let's actually do
it keep relative. Let's keep the player relative. Scaling. Relative means just whatever we
have written here. Since it's actually
going to keep our scale. Let's go back to
the player rep here for the transform that we made. Instead of doing 1.6 I'm actually going to delete
it and put it here. Because again, if I set
it to keep relative, it's going to keep my scale. I compile and let's
click on play and see what happens if
I select terrorist here. Let's just shoot the player. I'll shoot more. Let's see
where the player responds. Now the player
responding over there. If I just maximize my viewpoint here you
see the player has pawn. However, the player is floating. This is because I forgot
to enable the walking. If I just go back
to instead here. Remember over here we set the animation to this and
we disable the movement. When you disable the movement, you have to enable it again. The way you do this is let us do it right before
the animation blueprint. Let's move this over. Let's take the character
movement component and say set movement
mode like this one. Set movement mode connected. Now you can set this
one to be walking, the walking on the standard
one you have by default, let me just move this down. And now it should work. If you compile and
you save everything, maybe I want to move those
spawn points further down. So they are actually
reaching the ground. The player is not
falling on the ground. If I just move them down, or they actually are
here on the ground, this should work if I
just move those as well. This one. This one.
This one, and this one. And I move them down
to be on the ground. Okay, let us play now
select terrist, here I am. Let us spawn as
the other player. Now I'm going to
shoot the player. Let's see what the players, the player is
spawning over there. And I can walk around
normally like before, if I shoot as the client. If I just maximize it to
see if it is working, now the server is dead. The player responds over there, that is working both ways. If I just try it again, now the player dies
quickly because we have not set the max health. And we can do that
in the next lesson. But you can see the
player is dying correctly and nothing
is bucking out. Awesome, Let's move on
to the next lesson.
172. 12.05 Resetting Health on Respawn: Let us now reset
the player's health when the player responds. And this is very easy because
we already did all of the work if you just go
back to the health here. And what we can do is over here, whenever the player responds, whenever we set the player
to not be dead anymore, this here will fire from here. What we can do is we can
drag and say set player he, I believe we called it this
one Set player health. Basically this is the
one we made before. So set player health. And we also have one
called set Player Armor. Call those we already
made functions. The one let's see here. Get player max health. And we also have get
player max armor. We're going to refill the
player with health and armor. Now we can play and
it should work. That was all that we had to do. Okay, let me just shoot here and make sure
that it is correct. If I just minimize this so I can actually see both of the health, this one, and the
client as well. Let's just shoot as the
Klein to see if it works, the player should repo. Here. You can see the
player has health again. We can see the player is resetting on 100
health and armor. And I have to shoot the player again before the player dies. Awesome, I'll try it here on the server
and see if it works. And the client
should respond with maximum health
that is correct as well and everything is
working as it's supposed to.
173. 12.06 Preventing Team Damage: Now we are able to
shoot the teammate. If you're a terrorist,
you shouldn't be able to shoot your
teammate terrorist. Some game modes that you
can have that as well, but if you wish to
not have team damage, let's go over to
the player base. The damage is done
here in the lot. Equip here the shoot and reload. This is where we shoot. This is the line trace we are creating. Simply what we want to do is we don't want to apply damage. If it is your teammate
you are shooting at. What we want to check is if the hit actor is in
the same team as you, you can take this hit actor
and say get reference. Let us connect it after here. If I just move this a
bit away out of here, let us just expand this so
we have room to work with. And I'm also going
to make space here. Let's add the code in between. Let's get the player reference. Let us say get
controller because we have this team variable
inside of the controller. Get player controller
reference inside of here we can access the
team variable we just made. We made that in the
previous lessons. We can use that to
see if the team here is the same one as the
one we have on us. If we just take the
player controller and take this team variable, we compare them, We're taking this team variable
from the player we just hit. We're taking our
own team variable. If this is not equal to this, then we can apply damage
if you just make a branch. And we can apply the damage If we are not on the same team, I want to apply damage. However, if we are
on the same team, we're actually going
to do nothing. Let me just reorganize
this a bit here. Okay, so now that
is reorganized, if we are not on the same
team as the other guy, we are going to apply damage. And that was actually
the only thing we had to do if I select terrorists now. And if I select terrorist here, I should not be able to
damage this teammate. If I shoot this teammate, you can see nothing
is happening. We are not losing any health. I try with this one. If we try here as the server as
well shooting the client, nothing is going to happen. Okay, so this is how you
prevent team damage.
174. 13.01 Designing the Score UI: Now that we have
the base game done, let's go ahead and
add some team scores. Score for counter
terrorist and terrorists. So you can see how much
you have won in rounds. Let's go ahead and
go down to the UI. Go to the UI in the main UI, we are going to do
the rounds up here. What I want to do is I basically want to show you what
we're trying to do so it's easier to understand this is what we're trying to do. Having a score for
counter terrorist and having a score
for terrorist. Again, break this down. See what elements you need to use and try to do it
yourself if you want to, without my help, because
you should be able to buy. Now if you still need some help, if you're not sure,
if you're not sure, let's go ahead and
do it together. First, we need a horizontal box because there are two
elements beside each other. Let's go ahead and search
for horizontal box. Let me make sure I don't
put them inside of here. Just strike the horizontal
box into the canvas panel. It is inside of here. Make sure the anchor point is in
the middle of the screen. If you write zero
in the exposition, this one should be in the
middle. We need to adjust the x alignment to 0.5 in the position of the
x. I'm just going to say 30, actually, the xy 30, so it is not on the
edge of the screen. Again, size to content. Okay, now it's going to size to whatever content I
have inside of here. First, let me add an overlay. Inside of this overlay, we need an image because
we need a background. I add this image to the
overlay for this image. Let's just search for panel, the same panel we have
been using so far. So this one panel doc again, change the draw as to
box margin to 0.50 0.5 and now we can stretch it. So now at 11 in the zoom, I can see how large it is. I don't think I will
make the size here. I think I will actually
control this later. So let me just write
32 by 32. Once again, going to control it down here. First, let's have
a vertical box. Because we need two text
on top of each other, we need the first one. Let's just search for text. Put it inside of
the vertical box. Duplicate this one. I'm going to click
on both of them. Actually, let's copy
the style of this one. Let me click on it, Hold
shift and right click. Click on both of them.
Hold shift and left click, We paste the style. I'm also going to,
let's see here. For the shadow, we
don't have any shadow applied and that should be fine. We don't have outline either. Okay, this one is fine. Let's now select both of them we need to do. Actually,
let's edit the first one. Let's say counter terrorist. Let's just write one here. Let me maybe write a
here for this one. I'm going to put it
here in the middle. Actually, this one as well.
Put this in the middle. Put this in the middle as well. Also here in the justification, I'm going to set
it to the middle. Now click on the lines
to remove the dashes. Now we need some
space between them. Before I do that, I'm also going to change the front size. I think it's a bit too large. I'm going to set it to 20. Clicking on this overlay, have the image, then we
have the vertical box. I'm actually going to put some margin on
this vertical box. Let me just write, or padding. So let me just write 30 and this is what
it looks like now. I think this is fine. 30 is
fine for this vertical box. We pushed the vertical box away from the edges
of this image. I'm going to change
the color of this one. Just try to find whatever
color you like here. For the counter
terrorist, I'm going to reduce the saturation a bit. Maybe something
like this is fine. Okay, I have the
counter terrorist, let me just add a
space between these two. Just search for space, add them between
these two texts. For the Y, let's write ten. Maybe that is a bit too much. Let's write five, and
take a look again, I think we need more. Let's say 88 for the spacing. Let us just duplicate this. I'm going to
duplicate the overlay because we are in
the horizontal box. It's going to add
another one beside it. Let me change this
one to terrorist. Let me change the color here, the hue to something red. Just zero here. It's red. I'm going to reduce
the saturation slightly because I
think it's too much. The saturation is 0.8 And I'm going to do that
for the other one as well, changing it to 0.8
it stays the same. Let's add a spacer
between these two. If I take the spacer again, add them between is to overlays. Then for the size and the x, let's write something like 50, maybe something less, maybe
not 50. Let's write 30. I think this is fine. Okay, if you compile now, let us just change those
variables because we are going to use them
later. This one the number, call this T terrorist score. I'm going to copy
this and make sure this is variable because we
need to modify it later. Click on the other one, call
it text terrorist score. Make this variable as well. I'm going to click on all of
them and making sure that the visibility here
is said to not hit testable because I don't want the mouse to interact with them. Okay, if you just click
on Play to take a look at what it looks like, this
is what it looks like. I think everything
is looking good. So let us move on
to the next one.
175. 13.02 Designing the Team Win UI: Before we continue, let's design the team win I inside of the UI. Let's go back to
the main over here. I want to have so
that it says count a terrorist win or terrorist
win whenever a team wins. Let us actually add
it beneath this. What we need is this
inside of a vertical box. Because we have this and
the text beneath it, let's search for a vertical box. Let me just minimize
all of this so I can see where I can drop it. It needs to go inside
of this vertical box. I'm just going to drop
it in between here. And then dragging
this horizontal box into the vertical box. And now click on
the vertical box. Set the anchor to the middle. Set this position to zero. I'm going to set the alignment. Actually first click
size to content and set the alignment to 0.5 And
for the position in the Y, I'm going to set it to
30, just like before. Now we have it inside
of a vertical box. And what we can do
is search for a text and add this text to
the vertical box. This text can be in the middle, and the justification can
be in the middle as well. Let us just give it some space, search for spacer,
Add it in between, Click on it, Let us say, for example, 15 or
20, or 25 maybe. Let's just say 25, and this is what it looks like. Now let us click on this text. Let's shift right click to copy this front style click on this one left click to paste it. For the shadow offset, I'm just going to give it
a shadow of two by two. Right now you can't see anything because inside of shadow color, you need to increase the alpha at zero, it is transparent. But if you write 0.3
for example, let's see, there is a slight
shadowy effect, 0.4 maybe it becomes more clear
and this is what we have. For example, we can
write terrorist win. This is what it will look like. Okay, for the fun size, let's just make it a bit
bigger because it's important. Now it looks good. Let us compile everything and let us move on
to the next one.
176. 13.03 Score and Team Win UI Functionality: Now let's go ahead and code
the functionality for the UI. Let's open it up again and
clicking on Counter Terrorist. I'm going to set it to be hidden to begin with,
set it to hidden. We don't want to
see it by default. Also, if you just up
here, change the name. Let's change it to text Team win announcement
for example. You can call it whatever
you want and set it to variable so we can
change it in blueprint. And this one the counter
terrorist score we already have as well as the
terrorist score. And they are both variable.
Okay, so that is done. Let's go over to the
graph inside of here. What we have done so
far is the armor as we can see here and the MO
now let us go down here, let's make a new custom event. Let's call this one update
terrorist score UI. I'm going to copy
this name because I will write it down
again down here. Let's say now
codterrorist score. What we need to do is for the
terrorist we need to take the score terrorist score and set text and let us connect it. And we're going to
do the same thing down here for the
counter terrorist score. Set text and we're
going to set the text. For the text we basically
need the score. Let's click on this event
and make a new variable, and integer and numeric value. Let's call this one score. The same thing for this one. Let's make a new variable
integer. Call it score. Now we can just plug this
score number into here. Neural engine will
automatically change your integer variable into a text variable so it can
print it to the screen. Let us do the same thing here. Let's move this away
just to organize this. Now we're finished with those. Actually, let us compile
and save everything. The final thing is this one, and this one is a bit larger. Let's right click and
make a new custom event. Let's call this one update
team win announcement I. Okay, for this one, what we need to do
is simply just set this text as well.
Let's take this one. Remember this one is
hidden by default. Even though we change the text, we need to show the visibility
before I do anything, let's strike here and say set visibility for the visibility. We're going to set it
to not hit testable, so we can't interact
with it with the mouse. Then we want to set this text. Let me just move this down
and drag from here and say set text like this. Set text, go ahead
and connect it. Now we're going to set the text, depending on if it
is the terrorist or the counter
terrorist that wins. We actually need to
know what the team is. Remember, inside of
the player control, if I go back to blueprints
player control, we defined this variable team. And we can actually
use this to know if we're talking about the terrorist or the
counter terrorist. Let me just add a
new variable here. Remember this team variable
is an actor class type. If I just change this to actor actor here and
it is class reference, let's call this one
team, just spelling it. Right now, we have
this team here. I can drag from here and say equal this team equal
to counter terrorist. If it is, then we can drag
from here and say select. We can select what text
we want to choose. We can plug it into here. We're asking is this team right now and later on we will
plug information into here, but right now we
don't have anything. But if this value is counter
terrorist, if that is false, then we want to display, for example, terrorist
terrorist win. If it is true, if it
is counter terrorist, then we want to
spell terrorist win. It's going to select the
text depending on which team has won and we will give it
that information later on. Now let us double click here, make a re route node. All right, right now we are displaying
this to the screen, but after a couple of seconds
I want to hide it again. If I go back and the amount of seconds is actually the time it takes for people to respond. Imagine if everyone dies, this comes to the screen
counter service win after, let's say for
example, 5 seconds. It moves away because it starts a new round and everyone's
going to respond. What I'm going to do
is just call this, for example, display time. And we can plug in
the response timer later on display time. I'm going to delay this with the amount
of this delay time, which is the response
timer in the future. And we can double click here
and make this organized. We're going to delay this. After this delay, we want
to hide this once again, just copy paste this,
adding connected, move it here, and I'm going to set it to hidden once again. Okay, so this is finished. So that was the score UI
and this was the score UI. And this is the announcement UI that we are going to update. So now we can use
these events later on. Go ahead and save everything
and move on to the next one.
177. 13.04 Keeping Track of Alive Players: Now what we need to
do is we need to keep track of who is alive in
the map and who is dead. Because we can't really display
here in the UI who won. If we don't really
know who is on the map and what
team they are on, we also need to know
what team are they on. For example, there could be five people alive and they
are all on the same team. For example, counter terrorist and all the terrorist is dead. So we need to display counter terrorist win
even though we have five alive because they might be from the same team. We
need to know that. Let's do that inside
of the game mode because inside of
the game mode we actually decide all
of those rules. What we can do here is
let's add two variables. First, let's add one
called Players Alive. Before we add it,
let's actually change the variable type
for the variable. I want to change
this to player base. Go ahead and select the player now I think I believe
this is wrong. Let's again search
for weapon base, but player base, it is this one. This one. This one
here. Player base. Now, instead of just an
original variable here, let's make it to a map. What a map is, as you can see here, it
can hold two values. If you just select it
here, we just compile. You can now see we
have this player base, but we also have the
second variable beside it. You can actually assign
different things to this player. Now if I click on the
plus, for example, if I add a player here, I can also add a number here. This map variable,
you can actually use it like in different scenarios. You can have two variables. For example, you can have each player and also how
many kills they have. Each player is
inside of this list and it also has how many
kills they have, for example. But what we want to do is we
want to have this player and we also want to know
which team they are on. Because this is something
we need here to see if all on the same team are alive or if they're
dead and all of that. Let's change this one
again to an actor, last reference, because
this is our team. And I'm just going to
change this variable type. Here we have it. Now we have this variable,
we have the player. If I just compile, this will
disappear if I compile. Now we can have the player, we can here, which
team they are on. Now we can have each player
and which team they are on. Okay, so we have
the players alive. I'm going to make a new
one called players. Dt's a last one later on, and we will work with that
later. But let's make it now. Players spawn. We're going to use that later. And this one is just going
to be a normal array. We just know how many players has spawned inside of the map. Let's begin here. Let's
make a new custom event. And this one we're going to
add to players alive map. And this one is called
a map, by the way. This is a single variable, an array, a set. And now we're
working with a map. Add two players alive map. What we are going to do
is we're going to take this and say add here. We can add the player, actually we need to have this
player reference. We can just drag and
plug it into here. And this is the player base. I'm just going to
rename it to Player. Before I do this, the
player might be dead. The player might
be added to this. Players dead, because when they respond, they
will be added to this. Here, What we need to do first actually is take
this and say find. We can use this. By
the way, for maps, you can just drag here, go
to utilities, go to map. Here are the functions
you can use with it. You can see there aren't really
much you can do with it. You can add, find something, ask if it is empty and so on. Not really much to do with it. What we want to do,
we'll try to find this player and see if this
player is inside of this map. Let us just connect
it here, Find here. Let us make this branch to ask if it has found the
player inside of here. Let me just move this
down four a bit. If we find the player we
want to take this and say remove and select
the remove function. Go ahead and remove this
player from the player's dead. Let me just double click here and make a rear route
note so it is organized. Now I'm going to drag
from this player, go ahead and connect it again. Click, I'm going to move all of this down so I have more
space to work with. And we can move this down
like this. And now it is. Here we are going to find this player inside of
the players dead map. And we're going to
remove the player if the player has been found. However, if the player
has not been found, we just continue the code. What we want to do here
is this one where we add the player to the players alive. Now we remove the player
from the player's dead, and now we're going to add this player to the map.
This is the player again. We can just disconnect
this because now we have this reroute node. I'm going to double click
here and plug it into here. Again, double click here, and just add it to down here. Now what we need to
do is we actually also need this here. We need to know what
team is on to do this, we need to get a reference
to the player controller. Because remember inside of the player controller we have this variable
and we need it. Let us go down here,
let me move this away. What we can do is double click here to make
a reroute node. We can drag here and say get
controller and selected. Remember this is the player. We're trying to get
this play controller. Then from the
blueprint interface we made the get player
controller reference. Now we have the
player controller. Now we can access everything inside of this
player controller. And we want this team variable. Let's strike here. Team
get this team variable. And now we can click and drag
and plug this into here. Let us just plug it into here. And I'm going to
move all of this down so I have more
space just like this. And let's move it
closer and connect it. Now we are actually adding
this player to the map, and we're removing the player
from this players stead. Okay, now this is finished. Let us compile everything and let us move on
to the next one.
178. 13.05 Keeping Track of Dead Players: What we need to do
is now we need to keep track of the players here. What we need to do just
like before, right click, make a new custom event
and call this one add to players map. Just like before, we need
the player reference. So if you search
for a player base, go ahead and select it here
and call this one player. Let's take this
player's dead map. Actually, let's take the
one that is alive first. We need to remove the player if the player is inside
of here before we add them to the dead map
here, just like before. Let's take this, let's see if we can find the
player inside of here. Let's make a branch. Let
us connect this here. By the way, for this one, I forgot to actually
connect this as I can see here here for the remove, if it is false, if we can't find the player
inside of here, go ahead and continue the code. Don't remove anything. Let us actually double click up here and double click over here. Okay, that is corrected. We need to do the
same thing here. If we can find the player, go ahead and take
this and say remove. And let us connect it. Go ahead and remove the
player, just like before. I'm just going to
reorganize this. All right then now when we
have removed the player, let's now add the player
to the player's dead. Let's take this, say add, go ahead and add the
player just like before. Double click here for the
player, make a rear route node. Let's strike this into here and make a rear
route node again. Here we go. Now we have
added the player here. And I'm just going
to move this a bit away so I have more
space to work with. We need to get the
controller to know which team this player is on. Let us drag this away. Let's double click here. Let's say get control, get controller actually
get player controller. Go ahead and connect it.
Now we need to take this team variable just like before
and connect it down here. Let us just move it down here. And let me move this
a bit like this. I'll move this one a
bit up, just like this. And go ahead and move it closer. Okay, now we're adding
the player here. And just like before, if
we can't find the player, just go ahead and
find the controller and we can add the
player to this map. Okay, this was the code. Now we're keeping track
of the players that are alive and we're also keeping track of the players
that are dead. What we need to do now is keep track of the players
that are living, all of the living players. Let's go ahead and do
that in the next lesson.
179. 13.06 Keeping Track of All Spawned Players: To keep track of all the players that are actually
spawned into the level. This is very easy compared
to the other ones. Let's just make a custom
event called add to players spawn array
inside of here. Again, we need the player, let's change this
and call it player. And the type is player base. We simply just want to take this players spawn array
and say set array elements and we want to add the
players inside of here. Let us now we need
to choose the index. And the index is just taking
this and saying length. And we're going to
plug it into here. It's automatically going
to find the length of this array and it's going to add the
players inside of it. The item we want to add
is simply this player. Remember also to take
this size to fit, because if you don't
take it initially, what we needed to do is actually take this
and say re size. Then we're going to
give it like how much this array
can hold in size. But instead of
doing this, we can actually just say size to fit. Size it automatically. That is fine. And we can double click this to
make a rear route node, and we can move this closer. This is actually done. This
is all what we need to do. We can now use all
of these events. Now it's a lot easier for
us because we have now made all of these and we
can use them in the future. Let us save everything and let us move on to
the next lesson.
180. 13.07 Checking the Amount Of Living Players: Okay, so now we
actually need to check if the players are all dead
or if they're all alive. Because we need to go to
this Nui and display this. We need to check for the amount of players that are alive. Still, the best way we
can do this is here. When we add the player
to the dead map, then we know that this
player just died. And from here we can check
how many players are alive. Every time a player dies, we're going to
check if we need to play this counter terrorist
wind screen, for example. Let us do this, let me
just make a macro here. Let's click on this plus. For the macro, let me call this one check Amount
of living layers. The reason I make it into a macro instead of a function is because I'm doing
a for loop here. Or for each loop actually, for each loop I'm
going to use this one. The good thing about a
macro is this return. If I just add two
variables here, both execution pins, this one is called execute,
this one is called. Then the reason why
they're called, that the text disappears if you actually write
execute up here. And if you write, then it
also disappears down here. The output, instead of doing
it up here like a function, when you start
with the execution pen and you end it here, we can, with a macro, add the output to the complete. We actually wait for the loop to happen before we
continue the code here. If I add this macro to here, it's only going to continue whenever my loop has finished. This is why I'm actually
creating a macro. In this case what I want to do, let's now add two variables. First one we can call und
terrorist terrorists alive. Let's make this into an
integer normal variable. Let's make a new one called
alive and let us compile, Okay for this one, let's first set the counter
terrorists to zero, the ones that are alive and
this one to zero as well. Because we're going to loop
this and we're going to increment the amount depending
on how many is alive. Okay, let's take
this players alive. This is where we can
check how many is alive. Still one. Let me just delete
this for this one. For race, you can
just take this and say for each loop you
can actually use this. However, for a map you
can't say for each loop, it's not an array, this is only for rays. What you can do is you can drag, if you just go to utilities map and you can see this function. You have something called keys. You also have something
called values. If you click on keys, you can actually get
all of the keys here. Like all of this part, you can get all of the players. If you drag and say values, however, you can get
all of the values, you can get all of this section, this section over here, we have keys and we have values. And you can see them here. If you just drag from
here and say add, you can see you're
adding to this one, which are the keys, and you're adding to this one,
which are the values. This is what we did before. Let's take all of the values. Let me just delete this here. Let me take all of the
values and say for each loop now we can loop it
because this is an array. Now for each loop, let me just delete this
one and move this down. We're going to
check what team is alive I can drag
from this and say, actually we need to take
this first and say equal and ask if this is equal to
undo terrorist for example. And select this one BP counter terrorist make a branch here. Now we're taking the values
here and we're asking, is this a counter
terrorist value right now? It means a counter
terrorist is alive. If that is true, we can take this counter terrorist
alive and say plus plus. What plus, plus means? It's the same thing
as saying plus one And then setting
this variable like this, like this, doing this
is much shorter. It's actually the same
thing as adding one. You can hold the mouse
over it and says add one to the specified
value, then set it. Instead of doing all of
this, we can just do this. We're taking the counter
counter terrorist alive and adding one to it because we just found out this specific value is
a counter terrorist. Okay, if it is false it
means it is a terrorist. We can take this
terrorist alive and say plus and add it
here to the false. If it is false, it is a
terrorist that is alive. When it finishes the loop, what we need to do now
here in the return, we need to say how many terrorists are alive and how many counter
terrorists are alive. We need to add two variables and both of them are integers here. Outputs, call this one
count terrorists alive, and call this one
terrorist terrorists alive and without a space. Now we can add both of
those variables into here and output them
to the player in the. When we complete the
loop we will continue the code and so if
I go back to vent graph and I just compile here is we will continue
after the loop and now we know how many counter
terrorists are alive and we also know how many
terrorists are alive.
181. 13.08 Team Win Announcement: Now that we know how
many players are alive, let's now take this terrorists alive and ask if this
is equal to zero. We can do the same thing
for the terrorist. Ask if this is equal to zero, right from here And say and
use this one or bullion. If either the terrorist or the counter terrorists are zero. This means we need to this text here because there are no more counter terrorist or
terrorists on the map and we need to say or tell who has won the game or the
round over here, we're asking, is this equal to zero or is this equal to zero? If one of them is true, let's make a branch and
go ahead and connect it. If one of them is true, we need to play
the announcement. So let's go back here as a reminder and see what
we call the announcement. So here we call it update
team win announcement. I now to play this, we can't do it directly
in the game mode because remember the game mode
always runs on the server. And this is why here we're never replicating to the server
because it doesn't make sense. It is already running
on the server. The client cannot access the code inside
of the game mode. Also, remember the UI is
running on the client. Client and server can't communicate like
this, like you can't. The client can't just
jump into the game mode because the game
mode only exists on the server and can't communicate with the
client Stuff here the UI, we actually need like a
medium to run it through. Either need to run it through the player base or we need to run it through
the player control. Since we're controlling UI inside of the player
control, we're creating UI inside of
the player controller. Inside of the play controller. It makes more sense to do stuff inside of here with
the UI. Let's do that. Let's right click. What we actually
need to do is simply just take the WB main. We need to call this one
update team win announcement. Let's go back to
the play controller update team win announcement. This is what we're trying to do. Let us create a function
or an event for that. Let's make a custom event called update win announcement
announcement. Let me just copy
this so I don't have to write it again
because now we have to make a new customer
event running through the clients
because we need to run some UI stuff and click on
Owning Client reliable. Let's run the
client one up here. Okay, let's move this down. Let's connect it here. Actually not the M,
this is the wrong one. Update team announcement I. Let's delete this and let's
connect this instead. Now we need to run this through here and we also need
to run display time. Do the same thing up here, just continuing with the flow. And now we need to call it
here through the game mode. Now it works. We can just call this one because it runs
through the server. Remember, you can only call client events if we are
currently on the server. We are on the server
because if this event here, if I go back, if you call this event here
through the game mode, we are still on the server. This is saying you can
only run this server, you can only run Client events
if you are on the server. We are doing that. Let us
go back to the game mode. Now here, after we checked
that one of them is zero, now we need to play this. We need to get the controller
or all the players, because we need to display
for all the players, we need to display this text
up here for all the players. What we need to do is
we need a for loop. This is why we made
this players spawn. Let's take this
and say for each, because we don't really care about who is
alive and who is not, we actually just want
to play it for all of the spawned players. Let's here for each of
the spawn players, let's get the controller
It controller. Then we can again say
get player controller reference the same thing as
what we've been doing so far. And now we can call this one called update team
win announcement. Let's call it update team
announcement. This one here. Now we need to know
what the team is. We also need to know what
the display time is. The display time, again, I told you before, this is actually just the respond timer. While we are responding, we want to display
this to the screen. Let me just make a new variable here in the game mode and say. Respond timer. And we
can just make this into a float and let us
connect it to here. Now we also need to know
the team for this team. We need to display
who won the game. For that, we just need to
take this players alive, because whoever is alive
is the team that has won. We can take this and say values. Go ahead and select this. Just strike from
here and say gets. Because now it's like an array. We can get this value. We're just going to get it from the first player we
find inside of here. It's not really
important to know who the player is because
they're all alive, the same team that has won. So we're just going to get the first player
that we can find. And then we can plug
this into here. The alive player is
the one who has won. Go ahead and connect everything. And I'm just going to make rear route notes here.
And here you have it. So now we are actually finished. So we're taking
all of the players that have been spawned
into the game. We're taking all of
their play control laws. And we're displaying
for all of them, this update team
we announcement. And what we are displaying
is whoever is alive, this is the team that has won. So now we click on
the respond timer. And I'm going to set
this respond timer to maybe something like 3 seconds
for now going to compile. And now let's click on
Play and test it out. And let us play the game here. I'm going to select terrorists here, or counter terrorist. And I'm going to
select terrorists, I'm going to move in front
of the counter terrorist. Now I'm the counter terrorist, I'm going to shoot
the terrorist. Now it should say
counter terrorist one, But right now nothing
is displayed. So let me just close this
and see what is going on. All right, before we continue, just remember to set
this response timer to something that is not zero, maybe something like 3 seconds. Also, we need to set the players to be
alive when they spawn, because right now
nothing is happening. We have never called
these events Here, let's compile everything,
save everything, and let's go to the player base whenever this player spawns. And this is inside
of this event graph. Begin play whenever this player spawns and we set the
health for this player. I also want to set them
to this alive map. Remember right now
on the client, this begin play runs on both
the client and the server. It will give us a buck if
we call this directly. Because the game mode only can be accessed
through the server, we cannot access it
through the client. We actually need to
make a server event. Let's make a new custom
event through the server. The first one I need to add two layers alive map and run
this through the server. Reliable. We need to make
the other one as well, called server two
layers spon array because we have
that one as well. And we need to run this
on the server as well. Okay, here we need to get
the game mode reference. I don't believe we made
a variable for this, like we made for the
player control law. Let's actually do that for
the game mode as well. I'm going to move this away. Say get game mode. This is actually the reference. Let's get the game
mode down here. This function, run it through this get
game mode reference. Let's move this down. Let's
go ahead and connect it. Let's promote this to our
variable and call it game mode. Okay, let's connect it. We don't need to replicate this because this only
runs on the server anyway. Let us now over here, take this game mode variable. Let us call the add to
players a live map. Let's connect this for this one. Let's say game
mode. Again, let's take this game mode
variable that we have. Let's say add to
players spawn array. Let us go a and
connected like before. Now what we can do
with this is we can call it here
in the Begin play. We can call server add
layers to a live map. And we can also call
the adypawnarray. We need to define the player. Remember, we are already
inside of the player base, so we can just say self and drag from
distance itself again. Now we have added them
whenever they spawn. We're adding the player
to the live map, but we're also adding the player to the players who has spawned. So we keep track of how many players are
actually inside of the map. Whenever the player dies, we need to add them
to the death as well. If I just go up here, go to the health
armor and damage. If we just go down
to this death, remember we made the respawn here after this where it
says no weapons to drop. And we respond, the player. Let's now disconnect this
and just move this away. The player, whenever the player dies and drops all
of the weapons. Let's add the player to
that game mode event. This is already
running on the server, so we don't need to
make a server event. This game mode
reference we made, let's say Add Player, or let me see what I call it. If I go to the game mode,
add two players dead map. Let us strike from
here and say add two players dead and connected. Now we need to say
who is the player? It is self, we are
still in the player. Now we're going to
add this player to the dead map whenever
the player dies. The reason why it's not printing for me is actually I added this code here up here in
the to players alive map. And I need to call it down
here because I need to check every time a player dies. Let me just disconnect
this code here. Let me just copy all of
this I have wrote and I'm going to move it down to this one instead and connect it. A small mistake, just make sure it doesn't
happen for you as well. Add it to the player's deadmp, because we need to check
every time a player dies. Let's compile and
click on play now. And I'm just going
to maximize this. Select Counterterrorist
here, terrorist here. And then I'm going
to stand here in the open as the
counter terrorist. I'm now going to
shoot the terrorist. I'm just going to
move a bit closer. If I shoot the terrorist, now it says counter terrorist
win on both screens. Now it's going to
disappear after 3 seconds because this is what I
have put on my timer. And let's try to test it
out with more players. If I choose four players and I play the game, here they are. I'm going to select terrorist, terrorist, and this
one counter terrorist. On my other monitor, I believe or behind this one. There is one more. Here it is. And I'm going to select counter terrorist for this one as well. Now we have two
counter terrorists and we also have two terrorists. Let me just stand here
in the open for all of them and as the counter
terrorist stand over here. Now as the terrorist
for this one, I'm actually going
to go to the spawn, let's try to kill here
and see what it says. Now if I kill this
counter terrorist, nothing is going
to display because not all players is dead here. As the counter terrorist
that are alive, I'm going to shoot
this terrorist. Now this terrorist is
dead and still we are two players left alive here
as the counter terrorist. If I now go over to the terrorist and I
shoot this terrorist, now it says counter
terrorist win. On all of the screens, everything is working perfectly. Now we can go ahead and add the team's scores before
we respond to the players.
182. 13.09 Adding the Team Score: What we need to do now
is add the team score. If we go back to the main Ui, remember we made the
team score here. We made these two events
update terrorist score UI. And we made this one update
counter terrorist score UI. Let us add them as well to the black control
law because again we can't access the game
mode as the client here. Let's go to the
player controller when this one displays,
Whenever it is played. Whenever we are showing
the team win announcement, usually we want to
increment one of those. Let me actually just
edit here after the update team
win announcement. What we can do here, we can
ask which team has one. We can drag this
and say equal this. If this is equal to
counter terrorist, let's make a branch
here, let's connect it. Let's take this WB main once again and go ahead and paste it. Whenever it is the
counter terrorist, we want to update the counter terrorist score UI whenever it is the terrorist, Whenever this is false, we want to update the
terrorist score UI. Go ahead and connect
this to the false. Now we also need to
connect the score score. Let's go ahead and make a pin
here. Because we need it. Let's make it into an
integer, call it score. I'm just going to
move it up beneath the team here. Move this down. Then I'm going to drag
this into the score. We're just going to move this
away so it looks better. And I'll click here to make a re route node and
make it like this. And go ahead and
connect this as well. Okay, now we have
the score as well. And let's compile. And also up here, remember
drag the score into here. I'm going to move it up
one here beneath the team. The final thing is
inside of the game mode. Inside of the game mode now
we have this score pin. And we need to add the
score for the score. It is either the
counter terrorist or the terrorist score that we
need to plug inside of here. Again, we need to take
from this and say, is this equal to the terrorist? And let's move all of this away so we have more
space to work with. We're asking is this
equal to terrorist or is it equal to counterterrorist?
Depending on that. We're going to select
drag from this and say select Integer and
plug this bull in in. We have done this before,
we're going to select A. If this is true, let's make new variables. Let's make two variables, One called Da, terrorist,
terrorist score. Let's make this into an integer. Let's make a new one. I'm going to call
it terrorist score. And this is an integer as
well for these two scores, Whenever it is the
counter terrorist. So it's going to
pick a, we're going to put the counter
terrorist score up here. Whenever it is the terrorist, we're going to
take the terrorist score and plug it into here. And then it's going to select it depending on what
this polling is, and plug this score
number into here. Okay. Let us now just
move this together. What we need to do now is
set those because right now the terrorist and counter
terrorist score is just zero. We're not really doing
anything right now. Let's make a new function, and I'm just going to make
a new function up here. Let's call this
one a team score. We can actually use this alive if the counter terrorists
are alive here. We can take this one and
say if this is equal to zero and make a branch and
go ahead and connect it. If the amount of
counter terrorist alive is equal to zero, this means we need to award a point to the counter
terrorist score. We can take this again, say plus, plus to
incremented by one. However, if this one
is true or false, it means that the
counter terrorist is actually alive and it
is not equal to zero. That means we can take this counter terrorist
score and say plus, plus because it is
probably the count of terrorists that are alive
and not the terrorist. Since we like we
reached this point of the code, let us
just connect it. Now let's go back to the van graph and we're going
to add it after this one, because after you checked that one of them is
actually equal to zero, we can then award one
of them with a point. We can take this function,
plug it into here. Now it makes sense
because now we're asking who is it that is zero? Is it the counter terrorist
alive is equal to zero, then we need to give
the terrorist a point. However, if this is false, this means that the terrorist
is actually equal to zero. So we need to award a point to the counter
terrorists and now we awarded a point and it's
going to be locked over here. Okay, that should
work perfectly. Now let's save everything
and let us click on Play. And check if this is working. I'm actually going to reduce the amount of players to
maybe something like three. Going to select terrorists on this one, terrorist on this one, and counter terrorist
on this one here. Now as the counter terrorist, I'm going to go to
the base terrorists. I'm actually going
to minimize this. So I can see up here
and break it down. I don't know why it keeps
spawning on top of my screen, so let me just kill
one of them now. Okay, nothing happened
because one is still alive and I'm going
to kill this guy here. You can see the terrorist
now is awarded a point. This is not true, because right now I'm actually a
counter terrorist. If you take a look down here, the counter terrorist score
is plugged incorrectly. The terrorist score is
plugged incorrectly. If I go back to this award
score and take a look, this is the counter terrorist, and if it is equal to zero, we're going to award a point
to the terrorist score. Everything seems correct. The other thing is
because this has been disconnected because we
wrote this pull in here. Let us reconnect
this because it's actually the counter
terrorist that has one, but it's selecting
terrorist by default. Let me just drag this
into here again, just like before and you
can make a route node. Now it is connected. Let's check to be sure. Here in the Apple controller,
this is connected as well. This one here is disconnected because again, we
did this down here. Let us connect it. Now it should work. Make sure
everything is connected. And let's click on play
again and select Terrorist, Terrorist, Counter
terrorist once again. And I'm just going to
go to the spawn again. Okay, here I killed the first terrorists
and I'm going to go to the second terrorist
and kill this player. And if I just maximize
the screen so you can see now says counter
terrorist win. And it adds a point for
all of the players. Also it adds the point for
the terrorist as well. It adds a point to the
counter terrorist. This is working correctly now.
183. 13.10 Respawning the Players: Right? So what we are missing now is responding the players, let us do it down here. What we can do down
here is we can make a delay because we don't want to respond the players right away. We actually want to respond
after this respond timer. This respond timer right
now is set to 3 seconds, so it's going to delay
the code by 3 seconds. After that, we are
going to respond all of the players once again. Let's take this players
the way for each loop with this one we're going to call
this respawn that we made in the player in this
health armor and damage. Remember, we made this
respawn, Let us call that. Let's go to the
player and respawn. Now we're actually
responding all of the players and we can
communicate with it. Because this one is running
through the server. It's going to run through here. Running through the server
and doing all of this that we did before, responding
to the players. Remember, we also
have these variables, the players data
and players alive. And we need to update
those as well. Before I delay, I'm just
going to move this forward. I'm going to take these players
alive and players dead, and I'm going to
clear them here. I'm going to clear
the players alive, and I'm going to move this away. I'm going to clear the map
for the players dead as well. Both of them are reset. Then we are going
to delay the code. Like this here. I'm going to move this
down connected here. Now we are going
to delay the code. Whenever we have delayed it, we need to add the players
again to the players alive, else no one will be alive here. And it will book here
for the respond. Before we respond the players, I want to add them. Remember, inside of the player, we just made this event graph. We just made this one recently, the add to players a live map, we need to call this one on
the server, the list rake, and say server add to
players a live map. We need to specify
who is the player, it's just this one here. Then we can go
ahead and respond. I'm just going to drag it down. And again, double
click here to make a route note so you can see the difference
between those two. Here we go. Now we are
going to clear those maps, make sure it is not bugged. Then we can delay by
the response timer. So we're going to wait for a
bit and then we're going to respond the players and add
them to this alive map. Once again, go ahead and compile now inside of
the player what we did before here in the respond this code
here, we can just delete. Actually, we're not really
using it, this one, I'm just going to delete
it because I have no use anymore for
this print string. This is the that we have. Let us compile, save everything, and let's click on play again. Select Terrorist.
Select Terrorist, Counter terrorist, for example. Now I'm just going
to go to the base. Let me take this AK and I'm going to shoot
this player now. Now it says terrorist win and
I'm going to have a point. Then we are all respond. Here I am as the terrorist spawn with the other
terrorist here. This is the terrorist as well. Here is the counter terrorist. Respond here as the terrorist. Now, if I go over to the counter terrorist and I
shoot the counter terrorist, then it should say
terrorist win. We're going to get
the second point and we're all going
to respond again. Okay, so this is
working perfectly and this is the
counter terrorist and now I'm going to
kill this guy here. Now you see counter
terrorist win. All right, so everything is working correctly
and we are also responding out here in the terrorist spawn and
in the aterroristpaon, we're awarding the
correct amount of points or the round here round points
whenever we win the round.
184. 14.01 Adding Impulse on Weapon Drop: Okay, so right now we
are almost finished. And what I want to do in
this section is improve the game with some
small elements that need some adjustments. For example, right now
when we drop the weapon, dropping right beneath us. Also for this weapon is
dropping right beneath us. Instead of doing that, I
want to drop the weapon in front of us like we're
throwing it in front of us. To do this, let's go over to the player base again
and take a look at the weapon drop logic over here. We created the drop weapon, if I just extend this and
include this as well, this is the drop weapon
logic that we created. This is the weapon to
notify if click on it, it takes us to that function. Let's add the code here. Whenever we throw the weapon, we're de attaching the
weapon from the player. Setting the collision to be
physics only for the weapon, and then we're
simulating physics. After we simulate physics, we can then add an impulse because if
you don't have physics, you cannot add an impulse. We can't add it
before this step. Ls, you'll get an error. Well, just add it after this. Basically taking this weapon
to draw and then taking that weapon variable
that we have been using. It's the same one as this one. Basically, let's strike
from this and say impulse. Then add this impulse
which is physics. You can see here
if you connect it, double click here to
make a reroute node. What we can do now
is add physics. If you just write something, let's say one or 5,000
something very extreme, we can take this
velocity change. What this does is it removes
the mass from the actor. We're not taking a
look at the mass, we're ignoring the mass, set this velocity
change to true. If you throw
something right now, you can see it flew over there and it
even came back to me. You can see I can
throw this now. And it even came back to me, that's a pretty cool mechanic. This is the velocity change
that we have created here to make it so that we are actually right now,
we're throwing sideways. We look here and we're
actually throwing over there to make it throw in front of us
where we are looking. We can right click and say
get actor forward vector. Remember we have
been using this. If you go back to
the van graph and to the movement, we
have used it here. Get actor forward vector to get the forward vector for the
player so we can move forward. Let's go back to the drop repoify and take this get
actor forward vector. And let us now break it. So I can use the X, Y and Z again. You can just right
click if you want to and say split struct pin. That is the same thing, I'm
just doing it this way. Then I am going to make direct from here
and say make vector. And make this vector,
you also have the XY and Z because the only thing I
want to modify is the x. Andy, I will leave z to be
whatever it is right now. I don't want to throw upwards. Let us modify the xy x
right now. Let's take this. Now we need to impulse. Right now it is zero.
Let's take this. And it's zero. It's one. Let's multiply this one by 600. Let's multiply this one by, let's say 600 as
well, like this. And then we can connect
them back to the x. What we did here is
just take the x, multiply it by 600, and put back the value
again inside of here. Now we have added some impulse, but for the Z value
we're staying the same. Okay, let's just organize
it here and move this away. Okay, let's compile. Let's click on play Now, let's see what happens if I just take something and I
throw it in front of me. See, now we are actually throwing the weapon
in front of us. Whatever direction
we are looking at, we are throwing the weapon
in front of us. Okay, cool. It's a lot better than just having it thrown
here beneath us. That's a cool mechanic to have. Okay, that was it. Let
us save everything. Very simple, fix or improvement. But it does a lot for the game. Let's move on to the next one.
185. 14.02 Improving the Weapon Weight: So here I am back into
the game right now. You can see when I
throw something, if I throw this weapon, when it lands on the
ground, it bounces around. And this one as well. It feels like the
weapon is unrealistic. It's like too lightweight. This shouldn't bounce
this much on the ground. It should just, maybe
stands still a lot faster. Like the weight for
this weapon is too low and it's too light. It's a bit unrealistic also. The second thing is I
can see the capsule. I think here a hidden game. I want to take that as well in the weapon base
capsule hidden game. So I don't see it for the
weapon being lightweight. What you can do is something new that we
haven't worked with before. If you open up the weapon
here, weapon base. In the weapon base,
you can click on the weapon and you can scroll
down to the collision. You have something called
a physics material. With the physics material, you can adjust the
friction settings and the bounce settings as well. What we want to do is actually, let's just create it inside of this folder because we don't
have any folder for this. We could make a new folder, but let's just do it
inside of the weapon base. We can write, click Go to
Physics and then add this one called Physical
Material and Created. Go ahead and select this one. I'm just going to call it
PM for physical material, we can just call it weapon base or something like that.
Just give it a name. Open it up now you can see here we can adjust the friction and we can adjust
the static friction. We can also adjust
the restitution. And you can see
the restitution is also called the bounciness
of the surface. If I just set this
to zero and save, and I go to the weapon base
instead of the weapon base. If you click on the weapon and in the collision you select this new physics material.
We called it Pm. This one weapon base. You go ahead and compile
and click on play. Now you can see if I dropped
this weapon on the ground, it's bouncing a lot
less than before. The other thing I want to do is instead of
having this to zero, I'm actually going to put
it to maybe something like 0.15 Initially it was
0.3 maybe half of it. Then for the friction, I'm just going to put it to
25.25 So the higher it is, the higher the
friction and also it's not going to bounce around and
move around on the ground. Okay, let us go ahead and click on play and
see what happens. Fi drop this AK now this
is what happens, okay. It feels like it has a lot more weight to
the weapon like this. It feels a lot
better than before. If you want, you can even
increase this friction, static friction, you can
play around with it. And I think this
is fine for now. Let us close it down and let's
move on to the next one.
186. 14.03 Removing Reload SFX on Weapon Drop: All right, so one
thing here right now, a buck is if we try to shoot something and we reload and we drop the
weapon, for example. You can see I can
hear the reload Sound Even when I equip it and I drop, I can hear the reload
Sound just like this. I can hear it when I even drop the weapon on the ground.
We need to fix this. If we go to the player base, and let's take a look at what's happening when I equip a weapon. It's playing a sound.
If you go to the loot, equip and drop weapon, and you go to your equip logic. Here we're playing this
animation montage. Remember the sound effects are actually inside of the
animation montages. If I go to the assets
animations inside of here, if we search for, we can take the reload
rifle for example. Remember the sound effects
are inside of here. We can't really stop
the sound effect out here because it is inside of the animation montage
when we drop a weapon. I actually want to stop this animation montage from playing because I don't want to play all of these sound effects. If I go to the player base. Now let's go to the
drop weapon logic. Here we're dropping
the weapon and we're searching for a
weapon in the inventory. Whenever we find a
weapon in the inventory, we're going to drop it here. I actually want to add the code here that will make
sense whenever we actually found a weapon in the inventory and we are
ready to drop the weapon. Let me just move all
of this away for a bit and let me just
organize this here. Now what we want to do is make a multicast for
this drop weapon. We don't have one already, so I can actually just
create one if I just move this part down and I can right click and make a custom
event multicast. Because I want to stop it
for all of them and say drop weapon for this multicast. What I want to do is first just set it to multicast
and reliable. Then let's take this mesh to find the animation montage
that is currently playing. We need to find the
animation class first. If you search for, I believe animation instance,
get an instance. So you have to get the
animation instance first. Then you can say montage. Then you can see you have a lot of functions you can
use with the montage. But what we want to do
is stop the montage. Montage, stop and
go and connected. For this one we need to
connect it again up here. So we can't do this right now. For the target,
it's the instance, We can just call it
instance for the montage. We can just plug it in and
I'm going to call it equip, Equip montage, for example. Equip weapon montage. We can even call it weapon
here, so it makes sense. Okay, now we have this one, we can call it up here. Let's call MC drop weapon. And let us just
move it over here. Now we can connect
from the server. We can connect the
animation instance. We can also get the montage. If we break from here and
say montage, let's see here. We can say get current
active montage. And we're going to take this
montage that is currently playing and we can
plug this into here. Let me just make route
notes for this one. Okay, now that is plugged
in, let us save everything. Right now. It gives you an
era saying something here. Let's just click on File and refresh all notes. I
think something is wrong. We just need to refresh all notes and disconnect
this and plug it into here, compile it does box sometimes
like this makes no sense, I have no idea why,
but just make sure to refresh all the notes
and we can do this. Okay, let us play now. Because now it should happen. If I play, I pick up a weapon, take this for example. Let's now switch
weapon and drop. Now you can see the reload or equip animation is stopping. That is fine. What if I reload
now if I reload and drop? That is fixed now. Okay,
that is fixed now. It doesn't make any
sense to play the sound. If we are dropping
the weapon now, we are going to later add some things that
might bug this. What I want you to do is
before we do this logic, I want you to take from this
set current active montage, make sure it is valid. Before we actually do this
asking, is this valid? Let's just move
all of this away. Let me actually just
move this back as well and ask first
is this valid? If it is valid, go
ahead and stop theta, or stop this montage here. And if it is not valid, just go ahead and do
whatever you did before. Let me just create
some reroute notes for this one and move this
closer, just like this. And now this is finished. We are going to ignore
this MC drop weapon. If this is not valid, we
don't have anything here. Let's compile, let's
save everything. And now this is finished. We can move on to the next one.
187. 14.04 Adding Team Announcement Win SFX: So right now what I want
to do is whenever we play here and when we kill
someone and we win the round, when it says counter terrorist
win or terrorist win, I want to play a sound effect. It would be cooler than right now where we
don't have anything. What I want you to do is go
to the marketplace and go to the free Epic Games
content inside of here. I think it was on page seven, there is something
called Peagon mail on. You can just search for it
if you want to as well. This Perregon Ono, you can take this and
add this to the project. I'm going to say show all projects because
right now it's not compatible with N engine 5.2 I'm going to show
all the projects. Select the Cada strike project and select the
latest version here. Go ahead and click
on a two project. Let me just minimize this or just wait for it
until it finishes. Once it has finished,
let's minimize this. Let's go into our own project. I'm just going to go down here. And here it is, the
Paragon mail anons. Let us just add this to
the Marketplace folder. We stay organized
just like before. Now we can open up the
Marketplace folder and go inside of
this Paragon mail. Sounds Let's go to the Sound. Now we have the
sound for this ons, we can just make
something cool first. Before I do this, I can actually just select everything
inside of here. Right click Asset Actions and bulk edit via
property matrix. Because I want to reduce
the sound volume for all of them so it's not too
loud inside of this course, I'm just going to
reduce it to a volume multiplier 20.1 Close it down, and go ahead and save
everything inside of here. There are only two sounds
we need right now. We need the defeat one. We have this one called defeat. You are defeated. This is when you lose. And we also have
something called victory. I believe it's this one,
you are victorious. I want to play these two. Let's do that. Let's
go to the blueprints. And the best thing is
over here in the mode, because inside of the
game mode we played this. Remember we just made this. And it's going to update
the team win announcement. Let's double click on that and go to the player controller. Now inside the
player controller, we are running this
client sighted. We want to play the sound client sited because whenever you lose, it's going to play one sound. Whenever you win it's going
to play another sound. We don't want to play the
same sound for everyone. This is what you did
with a multicast. You played the same sound for everyone through
a multicast. But for this, we want to play
a win sound effect when we win and we want to lose Sound effect for
the player who has lost. It is client sided. For this, we can actually do it here because we
know who has won. Here we know the
team winning team. What we want to do
simply is play sound. Instead of playing a
sound at a location, let's play a sound two D, just for the player who is listening to this
sound right now. What sound are we playing? Let's drag from this
and say Select, then let's make it so when
you lose, you hear one sound. When you win, you
hear something else. Now we can use this
actually we can drag from this and say
equal like this. Remember to reconnect this. Whenever the sap in sells. This will bug. Reconnect it. Now we want to compare
this winning team. Is this winning team equal to
the team I am currently in? Now we're comparing
this winning team to whatever team I
am in right now. If it is the same,
go ahead and just connect this right
now to the select. We're comparing the winning team with the team I am in right now. If these are equal, if I have, we go ahead and play this. Sound. The winning
team is my team. I want to play the victory. Sound. And I believe it's
this one congress. This one. Maybe you are Victoria. Yeah. So this one I want
to play the victory. Sound. Because the
winning team is actually the team
I am in right now. However, if it is not the case, I want to play the
defeat team defeat. Sound And it's this one. Okay, so now we're playing
the correct Sound. Go ahead and compile.
And that should be it. Let us go ahead and play. And I'm actually going
to set it two players. Now I'm going to play, and I'm going to
minimize this one ahead. Actually I can
just do this here. Maybe like this and this. And let's go ahead and select terrorist, counter terrorist. Now as the counter terrorist, I'm going to go over there, let's shoot the terrorist. You are victorious. It says you are victorious. Whenever you win, now I'm
going to shoot the terrorist. And whenever I shoot
the terrorist and dies, I'm going to switch quickly
to the terrorist window. So I can hear if the terrorist
one is saying defeated. So you can hear it says defeated here on the terrorist side. Whenever I switch to it
quickly, now it is working. It's saying defeated
whenever you lose and saying victory for
the winning player. Let's go over to the next one.
188. 14.05 Adding Enemy Hit Indicator: Right now, it is a bit
difficult to know if you have hit the player
from a far distance. If I shoot this player, I can see the small effect. But if there are a lot of players and you're
shooting around, it's a bit difficult to know
if you have hit the player. We need an indicator to
know if we've actually hit the player or if we have
hit behind the player. Let us go ahead and add
that. Let's close this down. And what I want you
to do is open up the cause materials
inside of here. I want you to go into the
UI folder into icons, and I've included this one
for you, the icon spark. Let us go to the UI folder
and inside of your icons, and let's strike this
into the folder. Open it up, go to
the texture group, change it to UI and change the compression settings
to user interface. Let's close it down. Now
let's open up the cross, this one, the widget, blueprint that we
made inside of here. Let's add this image. I'm just going to search
for image added to the canvas panel and I'm
going to click on it now. Put it to the center,
just like the crossa. Put the anchor point
to the center. And the alignment should be 0.50 0.5 so it's in the middle. And set the position to 0.0 And then click on
Size Two content as well. And now it is fully correct. You can click on
the other image, the cross here, to
see the difference. If you want to make
it more organized, you can call this one images, you can click on the other one. I'm going to call
it image Spark. Go ahead and compile
on the image spark. I'm going to change the image to this spark icon
we just imported. And I'm going to make
the size of it to something like 70
by 70, I think. The Crosier. 60 by 60. So I'm just going to
make it a bit larger and I'm going to put
it behind the crosier. I'm not going to put it
in front of the cross. This is what it looks
like whenever we shoot. We are going to get
the markers to appear. Let's click on the Spark.
By default it is hidden. Make it hidden by default. Let's go here, Set
it is variable, Make sure we can edit it. Now let's go to the graph. I'm going to delete all of this. This is very, very simple. Let's just make a custom
event and call it Show. It's I like this. Now let's take this image spark. Let's set visibility. Set the visibility of it
to be non it testable, so it is visible and the mouse
cannot interact with it. Now after a very small
delay after 0.1 seconds, I want to make it disappear. It's going to appear
on the screen for 0.1 second and then it's
going to disappear. It's just going to indicate to us that we have
hit the enemy. This is the only
thing we want to do. Let's close this down. Now let's open up the
player and move over to wherever we hit other
players of the enemy. But let's go to the shoot
and reload weapon over here. Whenever we shoot the line trace and we actually hit
the player here. We remember we check if it is not the teammate
we are shooting. If it is not the teammate, then we are shooting someone. At this point, we want to play this client site
because I only want to show it for the player
who's actually shooting. This one is called Shoot Weapon. I'm actually going to
make one client sit. I just want to add it
down here, right click. Make a new custom event CL
shoot weapon, blind sided. Run it on owning
Client reliable. I'm simply going to go down here and take the player
controller reference we made. Let's see if I can find it. This one player controller. Let's get the player controller, let's get the B
cross a reference that we made earlier so we
can get the widget blueprint. Now from the widgit blueprint
call the one you just made called show enemy I
ahead and connect it. And that is the only
thing it's going to do. I also want to play a sound effect because
we can show the UI, but I also want to indicate
it with a sound effect. Play. Remember, inside
of this we have this one called Bullet Impact Player. I'm actually going to play
this one sound effect. What we want to do is we
need the weapon first. The weapon reference.
I'm just going to write Weapon base select the weapon
based class reference. I'm going to call it
weapon just like before, I just want the sound effect. I'm going to copy paste all of this. Go ahead and connect it. Let's hide the unconnected pins. And I'm only going to show the bullet impact
player sound effect. I want to play a
sound effect only for the player who
is shooting again. Play Sound Two D, only for the player
who's shooting. And go ahead and play
this sound effect. Now this should be
working if I just move this inwards and we need
to play the sound up here. If you just drag from here
and say CL, shoot weapon. So we can call this
event whenever we shoot. You can see this input is called something
different from this one. Again, I have to click on File and refresh all nodes,
it shows correctly. I'm going to move
this a bit away, so I can move this away
as well like this. And I have more space
log this in here. Okay, everything
is looking good. Taking this down,
plugging it in. And we have to plug in
the weapon as well. We have the weapon
reference, I believe. Yes, it's this one. It goes all the way here. All the way here. And I
can double click it here. Now I can plug actually one, I believe it's this one. Double click it and plug it in. Let's compile, and
now it should work. Now before I play it, I'm actually going to increase
the volume of it as well, so I can hear it clearly
to find it quickly, go to the data table,
open up the weapon info, and it's this one. The bullet impact,
clear sound effect. Click on the small icon here. It takes me there automatically. This is what it sounds
like right now. I'm actually going to
increase the sound maybe like 0.5 maybe that's too loud. 0.4 Now I can hear it clearly,
so let's save everything. Let us now play the game and
see what it sounds like. As the server, I'm just going to spawn a
counter terrorist. And now as a terrorist, let's hear as the
counter terrorist. Let me just move in front of everything so I
can see the player. Now when I shot the player, you can see this sound effect. And you can also see this
marker that appears on my screen whenever
I shoot the player, it gives him a marker whenever
there is a bullet spread, like it's hitting
right behind him. Remember we added a
bullet spread earlier, so it's not going to
hit 100% every time. Whenever it hits the
player who are Victoria? Whenever it hits the player is actually going to
show this marker. If I just go in
front of the player, once again like this
and I shoot the player, it's going to show me the indicator whenever
I hit the player, whenever I don't hit, it's not
going to show me anything. I can also hear it
on the sound effect. You can hear the
difference here as well. A victor, that's a lot better
to add than having nothing, because then the
player actually knows if they have hit
the player or not. That was it. Let's
save everything and let us move on
to the next one.
189. 14.06 Adding Ambience SFX: Right now, it's a bit too silent inside of
the environment. You can hear. It's fine. We have the walking
sound effects, we have the shooting
and everything, and it will sound really nice. Imagine if you have five versus five here,
like five players, and everyone's shooting and
loading and stuff like that, it will sound nice. However, there are no sound
effects for the environment. We need like an
ambient sound effect if you open up your project
settings once again. Here let's go back to the audio. I have included this for
you. The bird ambience. You can add whatever
ambience you want to, but for this one,
let's use this. Let's go back to the audio
here, sound effects. If you just drag
this into here and I'm going to right
click, make it into a. So I'm just going to call it, so ambience, go ahead
and open it up. Let me just reduce the volume. Something very low, like
0.01 I tried it and I think 0.03 is good.
Let me just save it. And I'm just going to click and drag this ambience
into the level. It just plays instantly for
everyone who is connecting. Now if I click on Play, you can hear the
birds sound effect. If I just select
terris now it's really nice because I have
some background noise. You can even reduce it
further if you wish to. Now, everything is
sounding great. I can walk around, I can
shoot, and we can play. But I also have some
sound effect here for the environment.
It's not silent. It feels nice. It feels nice. It's not an awkward
silence that you have in the level. This is nice. Okay. So it's a great addition. Very quick addition, but it makes the whole environment
feel more alive. Okay, so that was it. Let's save everything again. You can add whatever ambience
you wish to for your level, and let's move on
to the next one.
190. 14.07 Removing Mag When Reloading: All right, so the final
thing we're missing right now is if you select
Terrace for example, and we take up a weapon. Now whenever I shoot and reload, you can see the mag
is not being removed. It looks a bit
weird because we're reloading and the mag
is not being removed. So we need to do
something about this. What we can do is we can open
up the animation montage. If you go back to
your animations for the player and
you search for your animation montages
that you created earlier. Let's go to rifle. Let's start with this one. Now what you can
do inside of here, you can add notify.
Let's start doing this. I want to add notify
whenever I am reloading, whenever I take
this mag out here. Let's try to add this
mag that we remove. I can't right click
on top of this, so I'm just going to
right click out here. What you can do, you can also
add another notify track, so you don't add it on
top of the sound effects, you can add another track. And I'm just going to call it reloading maybe,
something like that. Whatever you prefer over here. I'm going to write
Click and then Add. Notify and add a montage. Notify this one. We can use code to do whatever
we want for this one. I'm just going to
call it lip in. Let's add one for clip
out, or this is clip out. Actually this is not clip in. Let's call it Lip out. Let's add one for clip in. Maybe here, let's right
click Montage Notify, and click on it and
call it Lip in. Okay, now we have those
montages or notifies. Let us minimize this. Let's go to blueprints.
Remove this search. Let's open up the
player layer base. And let's go to the code where
we are actually reloading. Go ahead and click
on this one here. This is the reloading code. Remember we commented
it out, Reload weapon. This is all of the things we have done calculating bullets. Here in the multicast, we are playing the montage,
the reload montage. Now what we can do is
actually we can use this one called unnotifiedgin. This unnotifiedgin
will start playing whenever it reaches a notify inside of an animation montage. Whenever it reaches
this notify here, then this code be triggered. Now you can have
multiple notifies for different things
in the same area, and this is why this is here. We can take this and say, is this equal to, for example, you called it clip in or clip out to begin with. And let's make a branch, let's strike from here. If this is equal to clip out, then we can do
something with it. What we want to do is, let
me just take this up here. What we want to do is we want to hide the bone for the meg. If I go back and find the
weapon in the marketplace, I open up FPS weapon,
bundle the weapons, the meshes, and go
back to my AK 47. Let me just open up
the skeleton here now, just like before where we
hide the head of the player. Now ideally like if you
have a serious project, it might be better to just
make an animation like a reload animation where the
Mac is going in and out. You can actually see
this in the other pack. We have downloaded the
military weapon doc. If I go back to one
of the weapons here, they actually have
animations here. Ms for example, they have an animation for
reloading this rifle. And you can see here they
have this animation low, so I'm just going
to close it fast. But they have this
reload animation that you can use and
it will be more ideal, but in this case we don't
have any animations and we can actually still
make it happen. We want to hide the bone, just like the player
where we hit the head. For this one, we're going
to hide the gun mag. Okay, it's called gun mag. What we're going to do is we need the weapon reference first. This is the equipped weapon. Let's take the equipped weapon
that we have right now. Let's drag from here. We
need the weapon variables. We need the skeletal
mesh inside of here. Again, just write bone. If you don't know
what it's called, write bone and then you can
see through it and you have this one hide bone by
name, just like before. If this is true, go ahead
and hide this bone. Now, whatever this
bone is called, mag, if you want, you can write it
statically here. But the best thing again, is just to add it
to your structure. If I just go back to two
structures, weapon info. Just go ahead and
add a new variable and I just call it name. Let's say name here, name, variable, save and
save everything. Go ahead and open
up your data table. I'm just going to make space between this here and
opening my data table. Let's go to the right here. I'm going to call it Mag Name. Then we can give it
the name for my AK. It's called Mag. The same thing for my info. I think this is my pistol. For my pistol. I'm not sure if we need to do anything
because for the pistol, I don't think you can see Mac. If I just go to weapons, dark weapons and I
open up my pistol, it is here but I'm not sure like if you
can see the mag fully. So I'm just going to leave
this one out for this one. You can just write
none for example, and you don't need
anything inside of here. Again, it's better to just make animations like they have
done here for these weapons. And it's a lot cleaner. It looks a lot better.
Let's save everything now. Let's go back here and let's
download this as a CSV file. Let me just go ahead and
go up to the data tables. And let me import this. Now I have imported the CSV
file and it is updated. And let me just save everything Now I can go back
to my player base. And what we can do here now
is just use that reference. We can just add a variable
here called name. And we can change
it to a name here. We can go back to wherever
we play the multicast. I'm just going to click
on those and hide unconnected pins so we don't
have to see all of this. Let me see where we
play the multicast. Let me hide this one as well. The multicast is played over
here in the server event. What we can do is
just click on here, click on the Mag Name, and let's connect the Mag name. Okay, now let's go down here. What we can do now is just take this mag name and plug
it into Bone Name. Let us just double click here, make some rear rock notes
so it stays clean as well. Here we go. Whenever
it is clip out, we are going to hide the mag
name whenever it is clip in. So we can take this here. Now for this case, we only have two notifies. We only have this and this. Technically, we can just do
the code ins out of here. However, if you have
multiple notifies, remember you can drag
again, say equal, and say whatever it's called, then make a new branch, and then you can connect it and say if it is true,
you can do this. However, in our case, we only have two notifies. Anyway, I'm actually
just going to drag it from here.
Just moving this away. If it is false, we're going
to take this weapon again. And if you just drag
and right bone and see there's something called
unhide bone by name, Let us use this one. Let us connect this bone name
once again. Let's connect. This falls to here and double click to make
a rear out node. Now it should be working if I compile and save everything. Now let us try it
out and see what it looks like if
I click on play. Now remember it only
works on the reloading. This one is the equip animation. This is not the
reload animation. Now if we reload, you
can see that mag is being removed. Okay, awesome. Let's try it out
with like an M four here if I should And reload. Awesome, that works as well. It looks a lot
better. And again, it's a lot better to just
have animations for this, but you can also hide bone names when you are
reloading the weapon.
191. 14.08 Fixing Reload Bug on Weapon Switching: I spend an hour trying my
game to see if there is any bug or something we need to fix before we
finish this off. There was just a small
issue now You see if I click on play now
and I loot something. Now if I'm shooting with
this weapon, for example, if I switch and then reload at the same time you see I
switch and then reload, it's actually bugging out. Now I'm trying to shoot, but it's not shooting, the reload is bugging out. Let's go ahead and fix that. Before we finish, let's go to the player base inside of here. Let's go to our reload the logic here and this is the reload weapon
inside of here. What is going wrong is we can reload even though we're
equipping the weapon. This is a very quick
fix over here. When you try to press
the reload button, the things we're checking for. We also need to check if we
are equipping the weapon. Remember if I right
click and say equip, we made this bullion earlier. When we equip the weapon, get is equipping weapon. And then bullion when we are
not equipping the weapon, we can go ahead and reload. However, if we are still
equipping the weapon, it doesn't really
make sense to reload. I'm just going to
copypaste this we've done before just to
make it look better. I'm copy pasting this code
where we hide the mag. I'm actually going to the
lutequip animation here. The MC Equip weapon. I'm going to paste it here. I think it will be a lot better. Maybe you might not
need to do that if you have like another
equip animation. But my equip animation is
the same as the reload. I'm actually just going to plug those in here to
make it look better. And also going to plug
this into here and call it mag name, just like before. Then I am going to, let's see here, it's this one, so I'm just going
to connect it here. And that should
be fixed as well. Okay, the last
thing is well here, inside of the drop weapon. When you drop the weapon
and you stop the montage, remember to not make the
reload sound bucked. We stopped the montage here, we got the animation
instance and so on. However, sometimes it gets confused of the
animation instance, Let's just strike
from here because it says access N.
Sometimes we can just strike from here and say is valid and go ahead and
add this node is valid, we're making sure it is
valid before we continue. If it is not, don't do anything. And again, just make some
rear out notes here to make it more clean and that
should fix all of our issues. I tried the game
for like an hour, hour and a half, and there was naturally more
issues to play with. I'm confident to say that we have removed all the
box in the game. We don't have any box when
we play the game as well. I'm going to clean
this project for you, create comments and
stuff like that. And then I will provide
this project for you. Maybe you already
have downloaded it. This is in the future.
Let us save everything. And Leah, let's go
to the next one.
192. 14.09 What Now: So congratulations
for making it so far. It has been a very long
course to what I'm used to, but it has been a lot
of fun in creating this for you and creating all
of these elements for you. So now we have like a good
start for an FBS shooter. And we have the
weapons dropping. We have the inventory,
we can reload, we can switch weapons, pistol rifle, we
have the bullets, we have the health and armor, and we have the
score sound effects. So we have added a lot of
things to this environment. Now we are finished
with this currently, but in the future I
want to add more items. For example, we
can add a Bi menu. We can add more weapons
like a rocket launcher. We can add a grenade launcher. We can add grenades. We can add a scoreboard for the player. We can add a main menu
and things like that. And what you can
continue with right now is if you go to
my Youtube channel, And inside of there, actually you can release
this game to Steam. So I will teach you for free how you can convert this game
right now that you have. You can save it, you can convert whatever game you have
right now to Steam. So you can add a main
menu, a server browser. You can add a search bar
and stuff like that. And you can actually
make like host a game on Steam for other
players to join. So I'm going to teach you that inside of my Youtube channel. So make sure to go ahead
and visit that as well. And you can always visit my website as well and
my Discord server. I will help you all 2047. So make sure to go
ahead and do that. The community is really
nice to talk to as well. And yeah, we're just having
fun with game development, so nice having you here. Thank you for watching. And make sure to stay
tuned for more updates. And also make sure to watch my other tutorials and other courses on real
engine and multiplayer. Go ahead and save your progress and I will hope to see you soon.