right we're back once again
and up to this point we've actually accomplished quite a bit if we just do a
really quick play test
we got a character that we can move and rotate
he can shoot his weapon we have an enemy that will chasing down the right now
are projectiles that really do anything are what we want
is for them to damage the enemy and then that eventually destroy him
so that's really do in this video we're going to set up that damaging behavior
between the projectiles and the enemy to start this off we're going to begin
inside the enemy character class we need to basically
expose the ability to transfer damage to talk
to that health value that we set up in C plus plus because accident two things in
C plus plus if you recall
we set up are these variables and then
week also who created the calculates
health function which is really it's gonna take an incoming Delta
added to the existing health and then store whatever that you value is
as the new health which is great what we've Edo
is a way to talk between blueprints
the projectile is one blueprint the a
enemy is another and we need a way to communicate in between them
and the way we do that communication or
one of the ways in which we can do that communication is with and interface
so we're gonna make a blueprint interface and use that
to communicate with that calculate health
function that we set up in C plus plus so too
to set this up actually before we send anything out let me come to describe
because in general terms what and interface is
and interface is a collection I love
on implemented functionality and some licorice
that's really a program re way to explain its let me think a different way
to say it
fired two people in front me was a Bob
and Tom so that these two characters Bob
and Tom and if I tell Bob to tell me a story bob
might tell me about how he walked home
on last night and stop by the grocery store and bought something for dinner
but fertile time to tell me a story he might tell me about something he did
last weekend maybe he went camping
maybe he he but well the point is he did something totally different than bob is
they both
had two different result that they gave back to me even though I gave them
the same command both just told them tell me a story well interface
is how you set up those generic commands like tell me a story
and then within each receiving thing with deep within each thing that knows
what that command is
you can make it define what that really means if it's confusing in any way
just watch will make it all makes sense excellent start building our interface
we're gonna right click and go under the blueprints submenu
and there it is blueprint interface so
click and we're gonna call this all I lower case I
I'm short for interface damage herbal
that is a common code naming convention for
interfaces to I damage will we're gonna double click it now we had
know what has your is a function that will have no implementation
basically it's like kinda declaring that we're gonna do something
with this given name but we don't really know what yet and we're gonna name this
function
is fact health now affect health is gonna need to take in
some value some numeric value that we can use
to affect our health by some amount so under the
input section down here in the details panel I'm sorry under
yeah it is in the detail excuse me click on the new button
and let's set this to you name
love tell top girl
and then take its type and said it too afloat
that's it that's all we had to do were not get reno's we can't even connect
any notes to this because it's all greyed out the purpose 7 interfaces that
you just define
this structure for white AL what functionality want and you define what
that functionality is
within any object implements that interface so
the function could mean different things to different classes so let's compile
and save this and then we're actually done with my damage will
don't have to do anything else to it we can close it however we need to make
sure
that our enemy character implements I damage it'll
now another fun fact just Kenneth
introducing you to some other concept working with interfaces
any class in your game can talk to this interface now
so like right now I could say affect health
and there it is interface message so he can send out
a call through the interface to talk to other things
he doesn't have to have anything special to do that the interface just has to
exist
but if he needs to receive
data worse receive some sort of call from
the interface then he must implement that interface
and here's how you do that if you go under your class
settings not class default class settings
there's a section here called interfaces and there's implemented interfaces:
right now none are implemented
so click the Add button and from the job dropdown you'll see
I damage it'll click on that and they go
that's it that's all you had to do make sure you compile and save once you've
done that
now when you right-click check it out if you type
affect health there is now an event for it
so this event will be fired whenever
any other blueprint calls affect health
on this subject so now you basically just created a pathway
were other blueprints can talk to this guy now what's gonna happen we call this
this is where our C plus plus code becomes handy drag a wire out from this
just say calculate health so we've perfected it from some outside source
now let's calculate and get our new result and Delta
just plugs right into Delta that's it now
let's talk about what happens when this guy dies
so I remember calculate health
is going to take in incoming Delta its gonna
add that to the existing health and then store that has the new health so if you
if the values -20
the new result will be eighty exits counting down
and then is going to run that little helper function we set up
called calculate
it and calculate dead just simply says hate did health make it till
zero or less yet because if it did
them set is dead to true hasn't yet
leave is dead at Falls that's great because what that means is
we can grab is dead and notice something
do you remember actually let me I'm I'm just gonna I'm hoping up and show you
watch this this is pretty awesome
if we open up our base character class which is going to open up Visual Studio
will let it do its thing thank you prepare solutions hi we're back
that was nice and fast if you remember
so there's calculate dead and you can see is just
checking to see if something sorry dad or not and setting the value
but if we take a look when we declared the is dead Boolean property we had
those keywords right
blueprint read only it's not blueprint read/write
we can actually verified check this out by closer to Visual Studio
so we don't need anymore let's go back over to unreal
and we go insider enemy character look at this
I drag is dead in the world noticed that set is greyed out
I cannot set that's because this is Reed only
but I can get it which is all I need to do wanted to point that out
that's how those keywords rex lee doing cool stuff so now we can take is dead
and let's test it boo branch and
if is dead test out to be true
then lights destroy this actor
to the enemy will just cease to exist because that's how destruction tends to
work
now let's just for debugging purposes
I'm gonna set up some temporary II quote-unquote code here
as soon as we calculate health I want to get
our health and i wanna printed out to the screen
steep print string
will connect this into the line and noticed the stakes in a straying
and health is a float value if I try to connect them
on reels like 0 you don't know the difference between a flow in a string
that's fine don't worry I'll convert them for you so call
I'll what this means is we will get a message from some outside source
spoiler alert it's gonna be from the laser pleasers gonna call this
we will calculator health will print out whatever our new health happens to be
then we'll check in see
if the character is dead if it turns out they did I
then we're just gonna destroy themselves disappear was compile
and save now this won't do anything
just yet we had to tell the projectile
the it can talk to the enemy
by way at the interface and here's how we're gonna set that up so
if you take a look at our project I'll we have this nice
collisions fear we're going to use this to our advantage
so let's add start by grabbing
here in art and craft we're gonna begin with event
actor begin overlap and overlap is what happens when
to actor at two actors components are
intersecting the same space to basically that collisions here we set up
that overlapping something then we're gonna get this service event call
also it's a good idea to double check your collision settings so
let's click on our project I'll collision this is currently set to
overlap all dynamic I'm kinda okay with that but
since we're only ever shooting at pawns what surfaced
overlap only pawn it'll probably work better in the long run
so compile and save now
back over here in the event graph as soon as we detect and overlap
what's gonna happen well week we have at we have access to the other actor
this is the other thing that we just overlapped with so check this out
we can check to see if it implements
a given interface does it yes or no and the interface who wanna look for
obviously is I damage people
so I just held on the beach key and click to that created a branch node
super useful shortcut once again I'll show you hold down be
click you get a branch will connect that up
so we just tested to see if whatever we just hit
or whatever we just overlap with implements the I damage will interface
awesome now if it does if it does we could just
damage that whatever it is we had right and that would work just fine
but on one extra spoiler depending on how
you set up your narrow component where you're shooting depending on where
you're
gun is placed it is possible in extreme circumstances
you could end up colliding with overlapping the player
in effect it's kinda like saying you have the ability for the player to shoot
himself
or arm put another way you could shoot
other hero characters if you modify disc in the multiplayer so what I'd like to
do
is established a system where we then check to see if we just
overlap with the player and if we overlap with the player
we're not going to do anything so I would because in the at the end of the
day the reason I'm checking for this
is the player will eventually also implement
I damaged he doesn't right now but he would test true at this point we need to
verify we didn't actually hit him
here's our didn't do it go to the hero character class
so here we are in the euro go over to at the event graph
and I'll we're going to select his class default properties
not settings is defaults an open details panel at the very bottom there's this
actor category expand that and there's this little hidden property called
tags: tags are just like tags: on
a whole lotta different internet activity is right there just
the ability to put some sort %uh name
in place that could mean anything so I like
at least was hits the usual plus beyond at a new
tag and let's call this
friendly awesome
so we have a tad name friendly so now we can look for that tag
but compile in safe and over here in our project I'll
we can take the other actor now I'm any use reroute knows just so it's easy for
you to see what we're doing
we can say has tagged look at there's no to that
actor has tech now what actually looking for
obviously we're looking for friendly now that just reports out a boolean value
didn't find the tag yessir now switch to another branch
will than be in click so if this tested true
with the intestine see if he's got the TAC
now here's the deal whenever I get the result
that I want at a branch I would rather that result be true
basically I would like all of my test to return true
if they can so we're gonna take actor has tagged actually going to attach that
to a
not node just kinda converting it if you read this out
in plain English would say hey does this object not
have the friendly tag which is a little different than how you actually say that
because
turns out you can see that in common everyday
we speak which is kinda annoying okay so
we check in see if they do not have the tag we make sure they don't have the tag
and if they'd don't have to tag then
finally we can affect their health so let's do another reroute node
now to make sure that we're calling
affect health on the right object want to do this with us to say
are affect health
XO now
that is asking for a delta right how much you're affecting the health
let's set this to negative 20 remember our C plus plus code is
adding the values together so who won a detriment health we need to set this to
a negative number
okay so we done that but let's not make this into a variable summit take Delta
Monroe
right click on it and promote that to variable
will call this damage cool
and that's being stored now pretty much no matter what happens
I want ass too destroy
this laser or this projectile when we're done so make it destroy actor node
and after we've affected health we want to destroy the actor
if we hit something that did not
implement the interface also
destroy the actor but if we hit something and it turned out to be the
player
we're gonna do nothing solely false disconnected and no you some reroute
notes to make this a little bit cleaner
okay so if you need to see that whole network again
with stretch this out just a little bit it all
up trying to condense things down as best I can swing fit them all on the
screen for just a moment bear with me
with me week
you know and polis and so there you go so begin overlap
check and see if implement the interface if it does
check and make sure that it doesn't have a friendly tag and if that's true many
doesn't have the friendly tactless go ahead affect its health
alright awesome sort compile and save
what's come out here to our map when he control ass to save everything let it
play
and jury is of check it out you see is health dropping
account only ten to twenty just like that it again
he's gone booms we got it we're doing damage to the enemy
now that we've confirmed that however
just to be on the nice and neat side let's go into our enemy and let's remove
this little portion %uh the graph
that is reporting that out
we don't really need it we know it's working to compile save play one more
time
and now we shoot after five shots
player the enemy goes away which is perfect so we have the ability to damage
the enemy
that's great that is going to wrap things up for this video
thanks a lot for