Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In the last couple of videos, we made a vitality component that can be used for both the enemies and
the player, and we implemented damaging for the enemies.
However, there is still no way for a player to take damage, so we're going to take care of that in
this video.
The first thing we want to do is that if we play, you can see that the crab is blocking us and we can
jump on top of it.
We want to change the collision between pawns to not be blocking, but to just be overlapping.
And instead of blocking this, we then just want to add damage to the player if we touch each other.
To do that, we go to the content, draw blueprints characters, and we use the BP action chart base
because this affects both the players and the enemies.
So we want to go to the capsule component because this is the one actually colliding.
And here we can go down to the collision settings and we can see here the collision preset is --.
We can open this up.
And you can see that pawn and pawn are actually blocking each other.
And we only have to change one simple thing.
So I believe there is no need to make a separate channel and do all of those things.
Again we did for the projectile here.
I think it's fine.
We just go to custom and we simply set the pawn from blocking to overlap.
And that's all we're going to do here.
If you want to manage it a little bit more cleanly, you could go and make another collision preset
again if you wanted to.
But this is so simple I think it's fine.
So what happens now is that if we play well, we can just walk through each other, and now we want
to listen to the event that happens.
If the player overlaps with an enemy.
And this is something we don't want to do in the action base, because this is only for the player,
an enemy doesn't really need to know if it overlaps with another enemy, or if it overlaps with a player,
because nothing is going to happen to it.
So in this case, I think the player is the one who should be checking.
Did I hit an enemy?
And then it applies damage to itself.
But again, this is just personal preference.
You could also make it so all the enemies are always checking for the player and then apply damage to
the player.
However, then you have to check for this event on every single enemy all the time instead of just checking
for it once on the player.
So to do that, we just go to the content draw player and use the BP player.
And yeah, make sure to not mix these up.
We use the BP player and in the capsule component we scroll down.
And of course you can see that our settings have been passed down, right.
The pawn overlap has been passed down from the parent, the action char.
And now at the bottom we want to look for the on component begin overlap event and add it here.
And again just to demonstrate the first thing we can do just print string.
Just to make sure that everything is working.
It's like a sanity check and just print the other actor.
Go in here.
And yeah, you can see we detect the BP enemy crab.
So in this case, we again want to make sure though that this doesn't trigger when we overlap with stage
elements with other things.
This should only happen if we overlap with an enemy.
So other actor we can just cast to enemy base like this.
And now this is not going to happen if we overlap with another player.
In case you have a multiplayer game, for example, or if there's just like objects in the stage, right?
So this is only going to execute if the overlapping actor is actually an enemy.
And here we could also use the faction system.
But to get access to the faction system we would have to cast anyway.
So this is just a nicer shortcut.
And then we can just apply damage to ourselves.
So here just call apply damage.
And for the damage actor, we just pass our self.
Because right now we are in the player and we want to damage ourselves.
If we detect we touched an enemy and for the base damage, let's just turn this into a variable, promote
the variable and just call it overlap damage.
And just put it here, compile and save.
And we can now give it a default value.
And I think one is fine.
I think our character is going to have ten health.
And if you touch another enemy it's going to take away one health bar from you.
For the instigator, damage, cause or damage type.
We don't really care about this now.
Let's just see how this works.
Go in here and you can see we get the damage flashing right.
And if we take all of the damage because I think we have ten health, our character is going to disappear.
And if you exit out now, you're gonna maybe know we actually don't get any error messages.
But something that happens often is if you just destroy the player.
Other things that are referencing the player and expecting at least one player to be active are going
to throw error messages.
So actually just destroying the player is not the best practice.
We want to have a whole like respawn timer and have a delay in all of those things later on, but for
now, this is fine.
One more thing we want to do here, though, is that we want to make sure on the player that we don't
just apply the damage.
If we overlap with anything in the enemy, we actually want to make sure that we overlap with the capsule
component, because later on, we're going to have the fly enemy who has another collision for the aggro
range.
So what happens if we don't add another check here?
We're already going to start taking damage, even if we just overlap with the aggro range.
And that is, of course, not what we want.
So a simple way of doing this is that we actually we don't only check for the other actor, but we can
also check for the other component.
So let's just print this so you can see what this looks like.
Right.
So we can print string.
Here other comp and you're going to see that it says well enemy grab collision cylinder which is the
capsule collision.
And what we can do here now is that we can check if the other comp equals, equals.
And actually I want to plug this in down so we can hold control and change the order.
And here I want to get the capsule component.
And it should be all the way at the bottom and open up some space like this.
So this way we check if the other component that we overlapped with is actually the capsule component
on the enemy, or something else, and only in that case do we want to add a branch here.
And continue the execution.
So if we overlap with anything else in the enemy, we're not going to execute this.
We're just going to stop here at false.
And this is only going to happen if we overlap with the capsule component, which you can see here for
the grab.
And just to show you that this still works right.
We take damage.
It still works.
It's all good.
But we made this more future proof because we know other collisions might be inside of the character
later on.
And the next thing we have to do is that if we touch the enemy, we need to have some time where we
are invincible.
So you probably know from other games the thing where the sprite flashes.
It lets you know that, hey, you cannot take damage right now and we need to implement this invincibility
now.
And another issue we have right now is that we can only take damage from the enemy once.
If we don't walk outside here again, we're not going to trigger the on begin overlap event and we can
just stand inside of the enemy.
So let's actually take care of that first.
In the player blueprint on the event graph, we are just gonna right click somewhere in open space and
add a custom event.
And we want to call this trigger invincibility.
At this year, and the first thing you want to do is to get the capsule component of the player.
And we want to set collision response to channel.
We're still going to need the capsule to check for the floor and everything else.
But after we take damage for a while, we want to disable the capsule when it comes to checking for
other enemies for pawns, so we can just set the channel the pawn to ignore for now.
And what this does is basically it goes into these settings.
Here we have on the collision settings, right.
And it's going to temporarily change this from overlap to ignore.
Just we can do this inside of the blueprint instead of having to click here right like this.
But we also now need to call this trigger invincibility.
And when do we want to call it?
Well, we do want to call it here when we apply the damage to ourselves, right?
When we overlap with an enemy.
But actually we want to trigger this whenever we take any damage.
Because also if we get hit by a projectile, we then also want to not be able to hit enemies again,
right?
So the better way to call this is to actually implement the any damage now, which we're going to need
right.
The event any damage.
And we can then trigger invincibility here from the any damage.
And just doing it like this.
There's going to be one issue which I'm going to show you, right?
Because if I start now, actually, I cannot take damage at all anymore.
And this is related to the whole thing with a parent and child, right?
Because we are now overriding the any damage event on the parent.
So actually what we need to do here, we've done it a couple of times is add call to parent function.
Right.
So we first want to call the whole damage thing on the parent and pass everything through here.
And after that we want to trigger the invincibility.
And now everything should work.
If we compile, save, go in here, right.
We take damage once and we can never take damage again.
Because for now, we only turn it off.
But after a while, we want to turn it on again.
So this is the first step.
It's working right.
So on the trigger invincibility.
Well we want to add a delay here.
And again it's just safer to use a retrigger delay because this will actually reset if we call this
multiple times.
And yeah, let's just turn this into a variable.
The invincibility duration.
Promote variable invincibility duration.
And for now we can just compile and save and just set it to 0.5 for now.
We're gonna tweak this value a little bit later.
But yeah, I think 0.5 is in the right ballpark.
And now this we can just copy control C, control V paste it.
And after 0.5 seconds we want to set the pawn response back to overlap.
Right.
So first we take damage.
We turn off the checking for enemies and then we turn it on again.
Let's try this out.
So I can walk in, I take damage, I walk back, I take damage.
So this is working.
So what happens now?
If I keep on standing inside of the enemy, I take damage and I keep on taking damage, which is what
we want.
Of course, later on we're going to have a knockback and other things.
So this doesn't really happen.
But in terms of mechanics, we want to have this.
And yeah, so this is the thing I talked about with the errors.
If you just delete the player and because you always need to be careful, something is probably running
on the player.
But for now this is fine.
Later on we're going to put in a proper cooldown for respawning, and we're going to take care of these
issues so we can just turn this off.
And yes, so this is working right.
So the invincibility itself is working.
However, it's hard to see like when and how we are invincible because we still don't have the sprite
flickering implemented.
Now back in the player, we want to create a new function for the sprite flicker.
So just add one and it's called toggle sprite flicker.
I have a Big Al here.
Sorry.
Toggle.
Sprite.
Flicker.
And doing this is very simple.
All we have to do is actually just get the sprite, where is it the sprite.
And there is something called visible.
Yes.
So we can simply just turn this on and off in the blueprint to show this sprite flickering.
So back in the function Tog'l sprite flicker.
In here we want to get the sprite and we set visible visibility.
Actually sorry.
And we want to set this to well what do we want to set this to.
We want to set it to what it currently is not.
So if it is visible we want to set it to invisible.
If it is invisible, we want to set it to visible.
So we can just again grab the sprite and we can get visibility.
I get visible in this case and just use the not boolean.
And this is basically just going to turn it into the opposite.
Right.
And if you have multiple sprites attached, maybe you want to use propagate to children.
So the sprites that are below are also going to take this in.
So yeah we can just turn this on even though we don't have any children in this case.
And this is pretty much it.
But we now need to call this at a certain interval and then turn it on, turn it off, turn it on,
turn it off.
So back in the event graph where we have the trigger invincibility right before the delay like here.
We want to call timer.
Sorry.
Timer by event.
Set timer by event like this.
And the event.
Just right event and it's gonna be create event.
And this allows us to pick any function or any custom event.
And here we just want to pick the toggle sprite flicker right.
And can look for it.
Toggle sprite flicker.
If it doesn't show up you might have to compile and save like this.
And this basically is just a node that helps us call this function.
But with a timer.
And we are able to loop it and do things like that.
So first we want to open up a little more space here and we want to set the timer.
So this is in what interval it's going to call this function.
So also just turn this to a variable and just call it sprite flicker.
Interval.
And this is something I've been playing around with to compile, save and find the right value.
And I think 0.12 is a value that looks nice and we want this to loop.
Okay, let's try this out.
Now compile save and let's check it out.
Right.
So it just keeps on flickering.
This is looking nice but it doesn't stop.
It just keeps on flickering forever.
It doesn't matter.
Like how many times we take damage, it just keeps on flickering, even if the invincibility is already
over.
So what we can do here is that after the invincibility duration, we want to cancel this event.
And how can we cancel this?
Well, we need to use the handle.
So the timer creates a handle which we can then use to clear it.
So here we could just call clear right.
But well this is happening in a different timeline.
So I actually want to save this in a variable as well.
So we can promote the variable and just call it Flickr handle.
And to save it here.
And then after this is over, we can just get the Flickr handle and just call clear.
Clear and invalidate.
Timer by handle.
That's a mouthful.
But yeah.
So this is going to work then like this.
But yeah one problem you see now is that there is a chance that we stop flickering while we are invisible.
So that is also something we have to do.
So after this we always want to make sure that the sprite is visible.
So we can just get the sprite set visibility.
And just make sure after we clear the timer it just sets it back to visible one time.
So there's no chance of us just being unlucky and landing on a frame where it is invisible.
So here, now I can go in.
But now this also shows us that 0.5 seconds is actually not enough of invincibility.
So we can just go back to the player and look for our invincibility duration and set it to 1.5, make
it a little bit longer and compile and save.
And let's see this now.
And yeah, this is more reasonable.
It gives you more time to adapt.
It shows the player some time to get out of the way and do things like that.
And yeah, this is what I want.
Now.
There is one small bug though, which I introduced, and if we just keep on standing in here, we keep
on taking damage.
This is working fine, but the flicker is actually not showing up correctly.
And there's a very easy fix for this.
To see what's happening here is that we can just call a print string here after the right trigger invincibility,
where we set the handle, just print, uh, print string.
And just say.
Start Flickr.
Start Flickr.
And then after here, where we clear the handle just to have another print string.
And just call it clear.
Flicker.
And just compile and save.
And now we can have a look what happens here.
And you can see that we call Start Flickr, start Flickr and then clear Flickr.
So we actually have an issue with the order in which we are calling these things, because we call start
Flickr once and we save this handle.
But then before we clear it, we take damage again and we call the second time, and then we actually
cancel the second handle.
So the way we can fix this is to, well, we can get rid of the print strings again because you saw
what happens here.
We just need to change the order here.
So before we set the collision back and before we are able to take damage again, we want to clear the
trigger.
So we just cut this out control X and move this over here.
And we can then drag this up here.
Like this.
And so what happens here is it makes sure that we clear the flicker timer before we allow taking damage
again.
So we cannot have this bug where we call things in the wrong order.
And now even if we just stand in the enemy, we keep on getting damaged and we keep on flickering.
So this is working fine now.
Just a small bug I found right now, but I think this was a good example of how you would go about debugging
something like this with print strings.
Of course, it usually doesn't happen that you just keep on standing in the enemy, but in the next
video we're going to implement a knockback and stun.
So what could happen is that one enemy knocks you into the other enemy.
And that's the reason why we just took care of this flickering issue to make sure that it wouldn't cause
problems in that case.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.