‫Hello and welcome.
‫In this lecture we are going to be fixing those bugs with Raytracing so that we can kill the character.
‫They aren't killing themselves and we can run over the spot where they've been by disabling their capsule.
‫Collider Let's dive in and see how to achieve this.
‫So we've got some weird bugs going on at the moment.
‫So we've got one where the enemy AI essentially seems to be shooting itself in the face, as you can
‫see by the fact that it's soon going to sprawl out dead on the floor like so.
‫But not only that, it carries on shooting as it is dead.
‫So we're going to solve some of those problems progressively.
‫Let's see what is going on.
‫So, first of all, the shooting itself in the face, that could be quite easy to see what's going on.
‫So if we go over into our gun CP and have a look at how this is working, we're currently doing this
‫line Trace single by channel to find the hit result and we're doing it starting from the location that
‫is the player viewport, the viewpoint, sorry.
‫And with the AI we've already discussed this, it's going to be somewhere around the eye level.
‫That's where it's going to be tracing from.
‫And you can see that there might be a little bit of an issue here.
‫If you start tracing from his eyes, you're going to hit this capsule.
‫In fact, we have the problem ourselves as well.
‫The only distinction being that because we have this over the camera view, over the shoulder view,
‫then the we essentially don't get the issue because we circumvent that capsule and don't hit it.
‫But we could be hitting our own capsule just as easily if our camera were in a different location.
‫So how do we stop that?
‫So if we go back and define this, we'll create a struct, the F collision query parameters, I'm going
‫to call params and then we can add some actors that should be ignored as part of our line.
‫Trace We do this by doing params dot add ignore ignored actor and then what are the actors we should
‫ignore?
‫Well, the first one is simply the gun.
‫So this and the second one is the owner --.
‫So params add ignored actor get owner.
‫So basically the owner of the gun should not be hit by his own gun.
‫I mean, obviously, you know, you might want to be able to hit your own pawns with the gun, but then,
‫no, not in this case.
‫So the params we are going to pass in as the last argument to our line trace single by channel and then
‫we're going to save and build and see if this works.
‫So now ideally if we go and hit play, we should see the yep, we're getting the particle effect on
‫our capsule, on our player, and eventually our health should go down to zero and we should end up
‫sprawled out on the floor.
‫There we go.
‫Sprawled out on the floor somewhere.
‫We seem to have fallen through.
‫I don't know where our actual player has gone, but we are still spawned on the floor.
‫But here is another bug.
‫You can see that he's still shooting at us and he's still shooting and hitting a capsule.
‫And the same thing actually happens.
‫If I were to kill this guy, let's go ahead and kill him.
‫There you go.
‫Getting the there.
‫It's much harder without something to point at on the screen.
‫But you're able to get him.
‫But he's still shooting still shooting at me.
‫And what we would have also seen is that his capsule is still active.
‫So there's a couple of things we want to do when our characters get killed, both the AI and the player.
‫So let's go to the shooter character CP and let's find our take damage function.
‫And we basically want to add an if statement in here.
‫We want to say if is dead.
‫So basically we've taken damage for the last time.
‫We're now dead.
‫We need to do some stuff.
‫We need to do some cleanup.
‫The first thing we need to do is detach the controller from this character.
‫The controller is no longer in charge of this character.
‫The character is dead.
‫You can't do anything that's going to stop us from being able to shoot.
‫So the AI will no longer be shooting when it's dead.
‫That sort of makes sense.
‫And furthermore, we're no longer going to be able to try and move around in the world.
‫All of that is being disabled by doing a detach from controller pending destroy.
‫That's what we're going to do.
‫Then the next thing is we want to switch off that capsule collision.
‫So we're going to do the get capsule component and then we're going to need to do a hash include up
‫at the top.
‫For the capsule component.
‫So how to include components and the capsule component over there?
‫Then scroll back down to our take damage.
‫I'm going to do an arrow operator and we're going to do a set collision enabled.
‫So we kind of want to set it not enabled.
‫That's why we're doing a set collision enabled, weirdly enough.
‫So it's going to be E collision enabled, colon, colon, no collision.
‫So we're setting our capsule collider to no collision, which should help us right out.
‫Okay.
‫So we're going to go ahead and build and see if that's helped.
‫Well, the compile at least was successful.
‫Let's go and hit play.
‫And so he's shooting at me.
‫I can shoot him till he's dead.
‫There we go.
‫He's dead.
‫I can go over his capsule and I'm no longer colliding with it.
‫You can also see that he is no longer shooting his gun, which is fantastic.
‫And let's also see if he goes and kills us.
‫What's the behavior?
‫So we just have to wait for the ten shots.
‫And you can see I sprawl out dead just as much as he did and he keeps shooting at me.
‫That's okay.
‫He's no longer hitting an empty collider, and I can no longer control my camera because I am dead.
‫Awesome.
‫So we've got the basics of a first person shooter here.
‫We've got an enemy that follows us, shoots at us, we can shoot at it.
‫Both of us have health.
‫Both of us can die.
‫So the next thing is to actually set up some game end conditions so that we can display a nice message
‫to our player saying that you've lost or that you've won if you killed all of the players in the level.
‫And that will be the subject of the next lecture.
‫So you there.