﻿1
00:00:04,470 --> 00:00:05,160
‫Hello and welcome.

2
00:00:05,160 --> 00:00:11,220
‫In this lecture, we're going to be architecting our gun such that when we hit the mouse button or the

3
00:00:11,220 --> 00:00:14,550
‫trigger, then we are going to get a log message.

4
00:00:14,550 --> 00:00:19,620
‫And this log message is the first step in getting many other things running off the back of this gun

5
00:00:19,620 --> 00:00:20,370
‫architecture.

6
00:00:20,370 --> 00:00:22,320
‫Let's dive in and see how it's done.

7
00:00:23,060 --> 00:00:28,300
‫So we want this gun ultimately to be able to shoot and that is the core of it.

8
00:00:28,310 --> 00:00:33,000
‫Why are we choosing to have the gun as the core of our shooting architecture?

9
00:00:33,020 --> 00:00:38,840
‫Well, as I've already alluded to a little bit, we want to be able to support different types of methods

10
00:00:38,840 --> 00:00:39,540
‫of shooting.

11
00:00:39,540 --> 00:00:42,480
‫Now, what are the kinds of methods of shooting that we can typically have?

12
00:00:42,500 --> 00:00:48,200
‫There is direct fire, which often uses ray tracing and direct line of sight to ascertain whether or

13
00:00:48,200 --> 00:00:49,700
‫not a victim has been hit.

14
00:00:49,700 --> 00:00:52,630
‫So it would go and say, okay, I can see that enemy.

15
00:00:52,640 --> 00:00:55,610
‫It's that line of sight from the gun to the enemy is clear.

16
00:00:55,610 --> 00:00:57,980
‫It hits him, so we have to do him damage.

17
00:00:57,980 --> 00:01:01,400
‫Otherwise, if I missed and I didn't hit the enemy, it doesn't do damage.

18
00:01:01,400 --> 00:01:02,750
‫That's one very easy way.

19
00:01:02,750 --> 00:01:05,640
‫It doesn't really replicate the physics of a bullet, but there's no need to.

20
00:01:05,660 --> 00:01:10,010
‫So for performance reasons we don't now with a rocket launcher or something like that, it's often a

21
00:01:10,010 --> 00:01:11,030
‫very slow projectile.

22
00:01:11,030 --> 00:01:16,640
‫We want to see the effect of that projectile moving through the air and the time delay can be important,

23
00:01:16,640 --> 00:01:21,830
‫in which case we might spawn that projectile and see whether the projectile hits in 5 seconds time,

24
00:01:21,830 --> 00:01:29,000
‫or we might go down a different route with bullet drop and rifles and sniper rifles over long distances.

25
00:01:29,000 --> 00:01:32,990
‫So all of this could change depending on the implementation of our gun.

26
00:01:32,990 --> 00:01:36,220
‫Now we're going to implement one gun during this section.

27
00:01:36,230 --> 00:01:38,840
‫It's going to be a rifle, a direct shooting type of gun.

28
00:01:38,840 --> 00:01:45,560
‫But in order to leave that architecture open for you to extend, we are going to make the gun responsible

29
00:01:45,560 --> 00:01:46,550
‫for doing shooting.

30
00:01:46,550 --> 00:01:52,010
‫So that means we have to go ahead and introduce some shooting architecture into our gun.

31
00:01:52,010 --> 00:01:52,760
‫So we've got a gun.

32
00:01:53,090 --> 00:02:00,710
‫H We want to create a public function to this that is going to allow us to essentially pull the trigger

33
00:02:00,710 --> 00:02:05,270
‫on the gun from the shooter character or from wherever we're binding input.

34
00:02:05,270 --> 00:02:12,590
‫In the case of the enemy, for example, we're going to be pulling that trigger from the eye.

35
00:02:12,890 --> 00:02:15,590
‫So let's go ahead and create a void.

36
00:02:15,590 --> 00:02:21,020
‫It doesn't have to have a return type pull trigger method and it doesn't need to take anything.

37
00:02:21,020 --> 00:02:24,710
‫All we need to know is that we want to pull the trigger in this frame.

38
00:02:24,710 --> 00:02:31,310
‫So having that is sufficient now I'm going to go ahead and create the implementation with control shift

39
00:02:31,310 --> 00:02:33,950
‫P and create implementation.

40
00:02:34,610 --> 00:02:40,160
‫And then in here, all I'm going to do is I'm going to put a YUI log and I'm just going to make it warning

41
00:02:40,190 --> 00:02:48,560
‫to stand out and change the message to You've been shot like that and that's great.

42
00:02:48,560 --> 00:02:53,120
‫So that's what we're going to call in our character DHCP.

43
00:02:54,080 --> 00:02:56,080
‫So this is going to be a challenge to you.

44
00:02:56,090 --> 00:02:57,470
‫It is some more input binding.

45
00:02:57,470 --> 00:02:58,790
‫We've done lots of input binding here.

46
00:02:58,790 --> 00:03:01,860
‫You've got lots of examples of input binding.

47
00:03:01,880 --> 00:03:02,990
‫Go ahead and do this.

48
00:03:02,990 --> 00:03:08,540
‫To hook up a shoot action, you're going to have to create a new action in the project settings for

49
00:03:08,540 --> 00:03:09,290
‫shooting.

50
00:03:09,290 --> 00:03:17,120
‫Bind that to your key, your right trigger, whatever you want to bind it to, then bind it in the character

51
00:03:17,150 --> 00:03:20,360
‫set up player input component method to do this.

52
00:03:20,360 --> 00:03:27,110
‫And then after binding the character, you should be able to call the pull trigger from within the function

53
00:03:27,200 --> 00:03:30,320
‫that you have created on the character.

54
00:03:30,320 --> 00:03:36,410
‫Remember to put a function in to character in order to set up the binding, rather than trying to bind

55
00:03:36,410 --> 00:03:38,360
‫directly to that gun.

56
00:03:38,360 --> 00:03:40,250
‫Binding directly to the gun isn't going to work.

57
00:03:40,250 --> 00:03:42,920
‫You need to put a little function intermediary in there.

58
00:03:43,370 --> 00:03:48,890
‫So pause the video and I'll give you a little bit of a hint or a little bit of a start if you're struggling

59
00:03:48,890 --> 00:03:53,180
‫with that last part of the challenge of creating the intermediary function.

60
00:03:53,990 --> 00:03:56,840
‫So here comes the hint if you don't want the hint, pause now.

61
00:03:56,840 --> 00:04:03,830
‫But the hint is going to be we're going to do something like this, which is to have a new private function

62
00:04:03,830 --> 00:04:09,110
‫called void, shoot and create the implementation over in C++.

63
00:04:09,110 --> 00:04:14,630
‫And it's going to be in here that we call to the gun's own method.

64
00:04:14,630 --> 00:04:18,620
‫So the gun's pull trigger, we're going to do gun.

65
00:04:19,340 --> 00:04:24,950
‫And then call pull trigger on that from within shoot.

66
00:04:24,950 --> 00:04:26,420
‫And this is what you need to bind.

67
00:04:27,350 --> 00:04:34,370
‫Okay, so pause video again, if that's where you want to take things and then let's go and set up the

68
00:04:34,370 --> 00:04:34,960
‫actions.

69
00:04:34,970 --> 00:04:35,260
‫Okay.

70
00:04:35,270 --> 00:04:38,000
‫So we're going to go over to our project settings.

71
00:04:38,000 --> 00:04:44,960
‫So settings, project settings and we want to dock this and go to our input and we want to add a new

72
00:04:44,960 --> 00:04:47,570
‫action and we're going to call it shoot.

73
00:04:48,300 --> 00:05:00,030
‫And then we're going to bind this to the left mouse button and the right trigger, not the right trigger

74
00:05:00,030 --> 00:05:00,870
‫axis.

75
00:05:01,140 --> 00:05:02,310
‫The right.

76
00:05:02,940 --> 00:05:03,990
‫Just trigger.

77
00:05:04,200 --> 00:05:06,390
‫I thought that's what I'd selected, but I had not.

78
00:05:06,580 --> 00:05:13,260
‫Okay, so we're binding to both controller and mouse and then we're going to go over and bind the axis

79
00:05:13,260 --> 00:05:14,630
‫in our shooter character.

80
00:05:14,640 --> 00:05:17,760
‫CP So copy this bind axis for jump.

81
00:05:17,850 --> 00:05:18,780
‫I mean action.

82
00:05:18,780 --> 00:05:21,150
‫Of course, I'm always going to get those two mixed up.

83
00:05:21,480 --> 00:05:24,930
‫We all call switch over to the shoot axis here.

84
00:05:24,930 --> 00:05:32,040
‫The pressed is what we want and instead of binding to jump, we're going to bind to a character shoot

85
00:05:32,040 --> 00:05:32,790
‫instead.

86
00:05:33,580 --> 00:05:36,340
‫Like so and let's go ahead and build.

87
00:05:37,120 --> 00:05:38,940
‫It looks like that has succeeded.

88
00:05:38,950 --> 00:05:42,580
‫Let's close that on down and see if it works.

89
00:05:42,580 --> 00:05:48,520
‫So let's exit the game and hit play again and have a look at our output log.

90
00:05:48,520 --> 00:05:50,590
‫Crucially, it play.

91
00:05:50,590 --> 00:05:51,250
‫Yeah.

92
00:05:51,280 --> 00:05:54,580
‫So if I hit the mouse button, it is working.

93
00:05:54,580 --> 00:05:58,540
‫Let's see if the same thing happens if I use my right trigger.

94
00:05:58,810 --> 00:05:59,200
‫Yep.

95
00:05:59,200 --> 00:06:01,720
‫Right trigger is working too for firing.

96
00:06:01,720 --> 00:06:07,480
‫So obviously a log message is not the best way of letting your player know that something is going on

97
00:06:07,480 --> 00:06:07,930
‫in the game.

98
00:06:07,930 --> 00:06:12,210
‫So in the next lecture, we're going to look at adding in particle effects to do just that.

99
00:06:12,220 --> 00:06:13,210
‫I'll see you there.

