﻿1
00:00:04,460 --> 00:00:05,210
‫Hello and welcome.

2
00:00:05,210 --> 00:00:11,570
‫In this lecture we are going to be fixing those bugs with Raytracing so that we can kill the character.

3
00:00:11,570 --> 00:00:18,290
‫They aren't killing themselves and we can run over the spot where they've been by disabling their capsule.

4
00:00:18,290 --> 00:00:21,050
‫Collider Let's dive in and see how to achieve this.

5
00:00:21,740 --> 00:00:24,500
‫So we've got some weird bugs going on at the moment.

6
00:00:24,500 --> 00:00:31,430
‫So we've got one where the enemy AI essentially seems to be shooting itself in the face, as you can

7
00:00:31,430 --> 00:00:35,930
‫see by the fact that it's soon going to sprawl out dead on the floor like so.

8
00:00:35,930 --> 00:00:40,430
‫But not only that, it carries on shooting as it is dead.

9
00:00:40,430 --> 00:00:43,430
‫So we're going to solve some of those problems progressively.

10
00:00:43,430 --> 00:00:45,290
‫Let's see what is going on.

11
00:00:45,290 --> 00:00:50,900
‫So, first of all, the shooting itself in the face, that could be quite easy to see what's going on.

12
00:00:50,900 --> 00:00:58,100
‫So if we go over into our gun CP and have a look at how this is working, we're currently doing this

13
00:00:58,100 --> 00:01:04,640
‫line Trace single by channel to find the hit result and we're doing it starting from the location that

14
00:01:04,640 --> 00:01:08,000
‫is the player viewport, the viewpoint, sorry.

15
00:01:08,060 --> 00:01:13,370
‫And with the AI we've already discussed this, it's going to be somewhere around the eye level.

16
00:01:13,370 --> 00:01:15,080
‫That's where it's going to be tracing from.

17
00:01:15,080 --> 00:01:17,660
‫And you can see that there might be a little bit of an issue here.

18
00:01:17,660 --> 00:01:21,950
‫If you start tracing from his eyes, you're going to hit this capsule.

19
00:01:21,950 --> 00:01:24,500
‫In fact, we have the problem ourselves as well.

20
00:01:24,500 --> 00:01:29,990
‫The only distinction being that because we have this over the camera view, over the shoulder view,

21
00:01:30,020 --> 00:01:37,550
‫then the we essentially don't get the issue because we circumvent that capsule and don't hit it.

22
00:01:37,550 --> 00:01:42,500
‫But we could be hitting our own capsule just as easily if our camera were in a different location.

23
00:01:42,920 --> 00:01:44,090
‫So how do we stop that?

24
00:01:44,090 --> 00:01:50,030
‫So if we go back and define this, we'll create a struct, the F collision query parameters, I'm going

25
00:01:50,030 --> 00:01:57,140
‫to call params and then we can add some actors that should be ignored as part of our line.

26
00:01:57,140 --> 00:02:04,070
‫Trace We do this by doing params dot add ignore ignored actor and then what are the actors we should

27
00:02:04,070 --> 00:02:04,610
‫ignore?

28
00:02:04,610 --> 00:02:06,590
‫Well, the first one is simply the gun.

29
00:02:06,590 --> 00:02:10,460
‫So this and the second one is the owner --.

30
00:02:10,460 --> 00:02:14,870
‫So params add ignored actor get owner.

31
00:02:14,870 --> 00:02:19,430
‫So basically the owner of the gun should not be hit by his own gun.

32
00:02:19,430 --> 00:02:25,270
‫I mean, obviously, you know, you might want to be able to hit your own pawns with the gun, but then,

33
00:02:25,340 --> 00:02:26,900
‫no, not in this case.

34
00:02:26,900 --> 00:02:35,210
‫So the params we are going to pass in as the last argument to our line trace single by channel and then

35
00:02:35,210 --> 00:02:38,240
‫we're going to save and build and see if this works.

36
00:02:38,240 --> 00:02:44,510
‫So now ideally if we go and hit play, we should see the yep, we're getting the particle effect on

37
00:02:44,510 --> 00:02:50,600
‫our capsule, on our player, and eventually our health should go down to zero and we should end up

38
00:02:50,600 --> 00:02:52,850
‫sprawled out on the floor.

39
00:02:52,910 --> 00:02:53,510
‫There we go.

40
00:02:53,510 --> 00:02:54,830
‫Sprawled out on the floor somewhere.

41
00:02:54,830 --> 00:02:56,420
‫We seem to have fallen through.

42
00:02:56,420 --> 00:03:01,580
‫I don't know where our actual player has gone, but we are still spawned on the floor.

43
00:03:01,580 --> 00:03:03,140
‫But here is another bug.

44
00:03:03,140 --> 00:03:08,840
‫You can see that he's still shooting at us and he's still shooting and hitting a capsule.

45
00:03:08,960 --> 00:03:10,970
‫And the same thing actually happens.

46
00:03:10,970 --> 00:03:15,200
‫If I were to kill this guy, let's go ahead and kill him.

47
00:03:15,200 --> 00:03:15,920
‫There you go.

48
00:03:15,920 --> 00:03:17,060
‫Getting the there.

49
00:03:17,090 --> 00:03:20,450
‫It's much harder without something to point at on the screen.

50
00:03:20,450 --> 00:03:22,250
‫But you're able to get him.

51
00:03:22,670 --> 00:03:25,010
‫But he's still shooting still shooting at me.

52
00:03:25,100 --> 00:03:29,420
‫And what we would have also seen is that his capsule is still active.

53
00:03:29,420 --> 00:03:35,840
‫So there's a couple of things we want to do when our characters get killed, both the AI and the player.

54
00:03:35,840 --> 00:03:42,710
‫So let's go to the shooter character CP and let's find our take damage function.

55
00:03:43,040 --> 00:03:44,870
‫And we basically want to add an if statement in here.

56
00:03:44,870 --> 00:03:47,150
‫We want to say if is dead.

57
00:03:47,240 --> 00:03:49,400
‫So basically we've taken damage for the last time.

58
00:03:49,400 --> 00:03:50,300
‫We're now dead.

59
00:03:50,360 --> 00:03:51,980
‫We need to do some stuff.

60
00:03:52,250 --> 00:03:53,390
‫We need to do some cleanup.

61
00:03:53,660 --> 00:03:56,750
‫The first thing we need to do is detach the controller from this character.

62
00:03:56,750 --> 00:03:58,880
‫The controller is no longer in charge of this character.

63
00:03:58,880 --> 00:03:59,840
‫The character is dead.

64
00:03:59,840 --> 00:04:04,070
‫You can't do anything that's going to stop us from being able to shoot.

65
00:04:04,070 --> 00:04:06,860
‫So the AI will no longer be shooting when it's dead.

66
00:04:06,860 --> 00:04:08,090
‫That sort of makes sense.

67
00:04:08,090 --> 00:04:12,950
‫And furthermore, we're no longer going to be able to try and move around in the world.

68
00:04:12,950 --> 00:04:19,100
‫All of that is being disabled by doing a detach from controller pending destroy.

69
00:04:19,250 --> 00:04:20,360
‫That's what we're going to do.

70
00:04:20,870 --> 00:04:25,010
‫Then the next thing is we want to switch off that capsule collision.

71
00:04:25,460 --> 00:04:31,460
‫So we're going to do the get capsule component and then we're going to need to do a hash include up

72
00:04:31,460 --> 00:04:32,150
‫at the top.

73
00:04:32,680 --> 00:04:34,060
‫For the capsule component.

74
00:04:34,070 --> 00:04:37,720
‫So how to include components and the capsule component over there?

75
00:04:38,760 --> 00:04:40,940
‫Then scroll back down to our take damage.

76
00:04:41,270 --> 00:04:46,310
‫I'm going to do an arrow operator and we're going to do a set collision enabled.

77
00:04:46,490 --> 00:04:48,890
‫So we kind of want to set it not enabled.

78
00:04:48,890 --> 00:04:51,260
‫That's why we're doing a set collision enabled, weirdly enough.

79
00:04:51,260 --> 00:04:55,340
‫So it's going to be E collision enabled, colon, colon, no collision.

80
00:04:55,430 --> 00:05:00,500
‫So we're setting our capsule collider to no collision, which should help us right out.

81
00:05:00,920 --> 00:05:01,250
‫Okay.

82
00:05:01,250 --> 00:05:04,450
‫So we're going to go ahead and build and see if that's helped.

83
00:05:04,460 --> 00:05:06,520
‫Well, the compile at least was successful.

84
00:05:06,520 --> 00:05:07,430
‫Let's go and hit play.

85
00:05:07,430 --> 00:05:09,140
‫And so he's shooting at me.

86
00:05:09,140 --> 00:05:10,910
‫I can shoot him till he's dead.

87
00:05:11,210 --> 00:05:11,840
‫There we go.

88
00:05:11,840 --> 00:05:12,560
‫He's dead.

89
00:05:12,740 --> 00:05:17,240
‫I can go over his capsule and I'm no longer colliding with it.

90
00:05:17,240 --> 00:05:21,800
‫You can also see that he is no longer shooting his gun, which is fantastic.

91
00:05:21,890 --> 00:05:24,050
‫And let's also see if he goes and kills us.

92
00:05:24,050 --> 00:05:24,920
‫What's the behavior?

93
00:05:24,920 --> 00:05:27,140
‫So we just have to wait for the ten shots.

94
00:05:27,140 --> 00:05:32,450
‫And you can see I sprawl out dead just as much as he did and he keeps shooting at me.

95
00:05:32,450 --> 00:05:32,930
‫That's okay.

96
00:05:32,990 --> 00:05:39,200
‫He's no longer hitting an empty collider, and I can no longer control my camera because I am dead.

97
00:05:39,200 --> 00:05:39,530
‫Awesome.

98
00:05:39,530 --> 00:05:41,780
‫So we've got the basics of a first person shooter here.

99
00:05:41,780 --> 00:05:45,620
‫We've got an enemy that follows us, shoots at us, we can shoot at it.

100
00:05:45,620 --> 00:05:46,820
‫Both of us have health.

101
00:05:46,820 --> 00:05:48,830
‫Both of us can die.

102
00:05:48,860 --> 00:05:55,520
‫So the next thing is to actually set up some game end conditions so that we can display a nice message

103
00:05:55,520 --> 00:06:00,680
‫to our player saying that you've lost or that you've won if you killed all of the players in the level.

104
00:06:00,680 --> 00:06:02,300
‫And that will be the subject of the next lecture.

105
00:06:02,300 --> 00:06:02,960
‫So you there.

