1
00:00:03,050 --> 00:00:07,250
In this lecture, we're going to set up our new input system so that when we push left or right or up

2
00:00:07,250 --> 00:00:12,890
or down, we're printing to the screen the -1 to 1 on the x and y axis.

3
00:00:12,890 --> 00:00:15,920
For our controller input, I'm going to jump over to Package Manager.

4
00:00:15,920 --> 00:00:19,850
So making sure I'm on Unity Registry, I'm going to search for input system.

5
00:00:19,850 --> 00:00:22,220
If you don't have it installed already, then click install.

6
00:00:22,220 --> 00:00:24,050
That will give you this fancy warning click.

7
00:00:24,050 --> 00:00:29,330
Yes, we're okay with all that stuff and that will cause unity to reboot, restart itself and go through

8
00:00:29,330 --> 00:00:30,410
a setup process.

9
00:00:30,440 --> 00:00:37,580
Now with the input system set up first step, click on player, add component input player inputs.

10
00:00:37,580 --> 00:00:40,130
What we're looking for here, why have we got all this noise going on?

11
00:00:40,130 --> 00:00:42,050
It feels like there's a lot of words on my screen at the moment.

12
00:00:42,050 --> 00:00:43,580
Let me just shuffle things around a little bit.

13
00:00:43,580 --> 00:00:44,000
Okay.

14
00:00:44,000 --> 00:00:46,190
So the first thing we need to do here is create actions.

15
00:00:46,190 --> 00:00:46,790
Click on that.

16
00:00:46,790 --> 00:00:48,770
That will ask, where would you like to save it?

17
00:00:48,770 --> 00:00:50,510
I don't have a photo for this at the moment.

18
00:00:50,510 --> 00:00:54,590
So new folder, I'm going to put this into input system.

19
00:00:54,590 --> 00:00:55,100
I think so.

20
00:00:55,100 --> 00:00:57,500
Nifty place for that double click on the folder.

21
00:00:57,500 --> 00:00:58,550
Save.

22
00:00:58,610 --> 00:00:59,510
We'll get an error.

23
00:00:59,510 --> 00:01:00,110
That's okay.

24
00:01:00,110 --> 00:01:01,580
That'll go away shortly.

25
00:01:01,580 --> 00:01:03,770
Let's have a look and see if we can find where that end up.

26
00:01:03,770 --> 00:01:05,150
So we have our input system.

27
00:01:05,150 --> 00:01:05,510
There we go.

28
00:01:05,510 --> 00:01:06,560
We've got our tail.

29
00:01:06,560 --> 00:01:09,140
Vania, I didn't do a very good job of renaming it, did I?

30
00:01:09,140 --> 00:01:09,920
I just clicked enter.

31
00:01:09,920 --> 00:01:11,420
But Tony is okay.

32
00:01:11,450 --> 00:01:15,140
It could probably rename it input actions, but I'm just going to have the one here so it doesn't matter

33
00:01:15,140 --> 00:01:15,830
so much.

34
00:01:15,830 --> 00:01:17,000
Back over to the player now.

35
00:01:17,000 --> 00:01:21,590
We need to make sure we drag that over into the action so it knows what we are actually doing.

36
00:01:21,590 --> 00:01:24,320
I'm going to double click on that to open it up to see what's going on here.

37
00:01:24,320 --> 00:01:25,250
The action is already set up.

38
00:01:25,250 --> 00:01:26,750
Move, look and fire.

39
00:01:26,750 --> 00:01:29,450
We're going to be using move a bunch in the next couple of videos.

40
00:01:29,450 --> 00:01:33,170
And then after that, we'll also be wanting to to be able to use jump.

41
00:01:33,170 --> 00:01:34,430
We have a fire in here.

42
00:01:34,430 --> 00:01:38,360
I'm not going to use fire for jumping because it's well, you know, fire is fire and jump is jump.

43
00:01:38,360 --> 00:01:40,700
We might wish to do fire at some point later on.

44
00:01:40,700 --> 00:01:42,770
So let's set ourselves up a jump action.

45
00:01:42,770 --> 00:01:44,480
I'm going to click on the plus button here.

46
00:01:44,600 --> 00:01:48,710
I'm going to add in the word jump and you can see it's of action type button.

47
00:01:48,710 --> 00:01:49,400
That's what we want.

48
00:01:49,400 --> 00:01:52,190
We don't want to have a value for our move.

49
00:01:52,190 --> 00:01:56,300
Let's see here we have a value which is a vector two on the left, right up here, down here, which

50
00:01:56,300 --> 00:01:57,590
is X and Y.

51
00:01:57,590 --> 00:01:58,400
But here, jump.

52
00:01:58,400 --> 00:01:58,970
That's cool.

53
00:01:58,970 --> 00:01:59,720
It's a button.

54
00:01:59,720 --> 00:02:05,180
Let's change the binding to let's see here on the keyboard and mouse scheme, I'm going to click on

55
00:02:05,180 --> 00:02:06,740
the pull down selector thing here.

56
00:02:06,740 --> 00:02:09,770
So one thing that's really cool, you can click on the listen button.

57
00:02:09,770 --> 00:02:13,520
It's not literally listening for what you're saying spacebar.

58
00:02:13,520 --> 00:02:14,360
It's not quite like that.

59
00:02:14,360 --> 00:02:15,740
It's listening to the keyboard input.

60
00:02:15,740 --> 00:02:20,300
So if I tap on the keyboard, it will show me that I just push space and I have space as the option.

61
00:02:20,300 --> 00:02:21,500
So I'll add that there.

62
00:02:21,500 --> 00:02:27,860
It's also let's see if we go next to jump and add another one, add a binding by clicking the plus button,

63
00:02:27,860 --> 00:02:28,970
click on the binding.

64
00:02:28,970 --> 00:02:31,970
We will make this the gamepad set up.

65
00:02:31,970 --> 00:02:33,830
We'll click on our little select thing here.

66
00:02:33,830 --> 00:02:38,150
Listen, and I don't have my controller turned on, but if I did have it turned on, then it would also

67
00:02:38,150 --> 00:02:38,930
listen for that.

68
00:02:38,930 --> 00:02:42,140
But I'm going to find GamePad and then just find buttons south.

69
00:02:42,140 --> 00:02:44,930
That's the button down the bottom of the four buttons on our gamepad.

70
00:02:44,930 --> 00:02:49,670
So now we've set up jump, which we'll use later on in this section when we're setting up jump for the

71
00:02:49,670 --> 00:02:50,360
character.

72
00:02:50,390 --> 00:02:51,500
Okay, we can close that out.

73
00:02:51,500 --> 00:02:52,370
We don't need it anymore.

74
00:02:52,370 --> 00:02:53,690
Back over to Player.

75
00:02:53,690 --> 00:02:59,900
I need to also open input settings and create a settings asset and that should be good to go with all

76
00:02:59,900 --> 00:03:01,190
the settings as they are in there.

77
00:03:01,190 --> 00:03:05,510
Now we have this input system settings asset that can sit down there and do what it's going to do.

78
00:03:05,510 --> 00:03:11,240
And you'll see we're using send messages and here are all the messages that are available to us, very

79
00:03:11,240 --> 00:03:15,440
similar to the way we've used on Trigger Enter or we've used on collision.

80
00:03:15,440 --> 00:03:19,790
These are the same sorts of things you can see on move is in there already and because we've created

81
00:03:19,790 --> 00:03:22,220
Jump, it's sitting here as an on jump.

82
00:03:22,220 --> 00:03:27,620
Now just to illustrate this super, super clearly if I was to double click on my actually while I'm

83
00:03:27,620 --> 00:03:31,550
here, I'm just going to grab my input system and pop it into the input system folder.

84
00:03:31,550 --> 00:03:32,240
So there we go.

85
00:03:32,240 --> 00:03:33,560
That was the input system.

86
00:03:33,560 --> 00:03:34,760
Dot asset.

87
00:03:34,790 --> 00:03:35,810
No, yes, dot asset.

88
00:03:35,810 --> 00:03:36,680
It is great.

89
00:03:37,280 --> 00:03:42,200
I'm going to open up my input actions again and input actions in here.

90
00:03:42,200 --> 00:03:47,990
If I was to go and create a new action and I called this donkey, blah, blah, why donkey?

91
00:03:47,990 --> 00:03:51,620
Well, you tend not to have donkey anywhere in your programming, in your coding.

92
00:03:51,620 --> 00:03:54,620
So if you search for donkey, you'll be able to find this pretty easily.

93
00:03:55,160 --> 00:03:56,360
It's a Ben Tristram thing.

94
00:03:56,360 --> 00:04:00,530
Thank you, Ben, for giving me that habit of using Donkey as your word to search for.

95
00:04:00,560 --> 00:04:06,260
Now, when I click back on here in Behavior, you can see that we have on donkey blah blah that is now

96
00:04:06,260 --> 00:04:09,380
an option that if we had that bound to something in here.

97
00:04:09,380 --> 00:04:10,760
So currently it's not bound to anything.

98
00:04:10,760 --> 00:04:15,410
But if it were to bind that to something, then when that particular binding is executed, when a button

99
00:04:15,410 --> 00:04:21,320
is pushed or a keyboard key is pressed, then it will send the message that we want it to send over

100
00:04:21,320 --> 00:04:24,530
and here to send the on donkey blah blah message.

101
00:04:24,530 --> 00:04:27,110
And then we can set up whatever code we want within that.

102
00:04:27,110 --> 00:04:30,500
So I just wanted to illustrate for me, when I was first playing around with this, I was thinking,

103
00:04:30,500 --> 00:04:33,380
how do I, how do I access jump if there's no on jump?

104
00:04:33,380 --> 00:04:37,610
But it gets created for you when you create that new action, which is pretty nifty.

105
00:04:37,610 --> 00:04:43,490
Let me just very quickly get rid of Donkey Delete, right click delete just so it's not lingering around

106
00:04:43,490 --> 00:04:43,820
there.

107
00:04:43,940 --> 00:04:44,170
Okay.

108
00:04:44,210 --> 00:04:46,610
Now the other step is to create our script.

109
00:04:46,610 --> 00:04:51,200
So I'm going to click on assets, give ourselves a little bit more space here.

110
00:04:51,200 --> 00:04:52,520
It's getting running out of space, isn't it?

111
00:04:52,520 --> 00:04:53,720
These animated windows.

112
00:04:54,410 --> 00:04:55,670
We need a scripts folder.

113
00:04:55,670 --> 00:04:58,230
So right click, create a C-sharp script.

114
00:04:58,250 --> 00:04:59,750
Oh, I did that in the wrong order.

115
00:04:59,750 --> 00:05:00,920
Okay, well, fine.

116
00:05:00,920 --> 00:05:02,060
My brain's not quite working.

117
00:05:02,060 --> 00:05:02,540
We'll make this.

118
00:05:02,840 --> 00:05:06,220
Player movement script.

119
00:05:06,320 --> 00:05:06,850
Okay.

120
00:05:06,920 --> 00:05:09,560
And now we'll create the photo create folder.

121
00:05:09,590 --> 00:05:11,190
I was too hasty with my clicking, wasn't I?

122
00:05:11,210 --> 00:05:13,490
And I'll call this scripts.

123
00:05:15,010 --> 00:05:18,280
Scripts and drag my play and movement into scripts.

124
00:05:18,310 --> 00:05:20,680
It's a little bit of back to front with my order there.

125
00:05:21,010 --> 00:05:26,230
We'll find the player and I'm going to drag over the player movement script onto the player.

126
00:05:26,260 --> 00:05:32,380
While I'm here, I've been working in the instance, so I need to make sure I jump up to the prefab

127
00:05:32,380 --> 00:05:37,180
under overrides, apply all and then the player input and the player movement script will be applied

128
00:05:37,180 --> 00:05:37,990
to the prefab.

129
00:05:38,020 --> 00:05:40,000
Now let's open up our player movement script.

130
00:05:40,000 --> 00:05:43,450
We'll just do one or two very quick things here to get ourselves set up and ready.

131
00:05:43,450 --> 00:05:46,620
And then in the next lecture we'll actually be making him move.

132
00:05:46,630 --> 00:05:49,120
But for now, let's just remove our comments.

133
00:05:49,150 --> 00:05:55,000
And because we're using the new input system, we need to first of all access the namespace using unity

134
00:05:55,000 --> 00:05:59,440
engine dot input system semicolon.

135
00:05:59,440 --> 00:06:02,170
Now the cool thing we're trying to do here is within update.

136
00:06:02,170 --> 00:06:07,600
We want to say move the character, make the character run based upon what input the player is pressing

137
00:06:07,600 --> 00:06:09,640
and how do we know what the player is pressing?

138
00:06:09,640 --> 00:06:14,410
Well, as I pointed out before, we've got a message over in here, message, which is hopefully you

139
00:06:14,410 --> 00:06:14,830
can see that.

140
00:06:14,830 --> 00:06:17,110
Okay, on, move on.

141
00:06:17,110 --> 00:06:23,200
Move is going to be called when the player changes what they're what they're doing on the keyboard or

142
00:06:23,200 --> 00:06:25,150
keypad based upon our bindings.

143
00:06:25,150 --> 00:06:29,320
So if you're pushing left or pushing right or if you let go of pushing left or let go of pushing right.

144
00:06:29,320 --> 00:06:34,900
But because it's a message, it's saying the player push down left, there's a change, the player let

145
00:06:34,900 --> 00:06:35,950
go of the left arrow.

146
00:06:35,980 --> 00:06:36,550
That's a change.

147
00:06:36,550 --> 00:06:39,070
The player pushed right on the gamepad.

148
00:06:39,070 --> 00:06:46,120
So we need to grab that input at the moment that it happens and then store it into a variable that we

149
00:06:46,120 --> 00:06:52,270
can then use within update to say on every single frame, whatever is currently the setting or currently

150
00:06:52,270 --> 00:06:57,190
the input value, then continue to use that to update our player's action.

151
00:06:57,190 --> 00:06:57,440
Okay.

152
00:06:57,460 --> 00:06:59,230
So that's a bit of a wordy explanation.

153
00:06:59,230 --> 00:07:00,310
Hopefully it helps a little bit.

154
00:07:00,310 --> 00:07:03,640
I'm going to start with a vector too, because we need the X and the Y.

155
00:07:03,640 --> 00:07:08,110
We're looking at the character movement and I'm going to call this move input and this corresponds to

156
00:07:08,110 --> 00:07:10,480
whether you're pushing right or left up or down.

157
00:07:10,480 --> 00:07:12,130
We want to store it in to move input.

158
00:07:12,130 --> 00:07:13,840
How do we find what move input is?

159
00:07:13,840 --> 00:07:18,250
Well, we can put some information in our on move method.

160
00:07:18,250 --> 00:07:23,050
That's a message and is going to be getting cold when the player makes a change to to the key binding

161
00:07:23,050 --> 00:07:23,680
that we've got.

162
00:07:23,680 --> 00:07:26,950
And we need to get some information when that is called.

163
00:07:26,950 --> 00:07:29,770
And the information we need is an input value.

164
00:07:29,770 --> 00:07:32,140
We need a particular value and we'll just name this value.

165
00:07:32,140 --> 00:07:33,670
So the type is input value.

166
00:07:33,700 --> 00:07:39,040
We're giving it the name of value, and then we want to store our value that we're receiving from the

167
00:07:39,040 --> 00:07:45,550
input and store it in our vector too that we can use throughout our class in any of our different methods

168
00:07:45,790 --> 00:07:46,990
within update, etc..

169
00:07:46,990 --> 00:07:53,650
So the way we're going to do that is very simply move input equals value, dot get.

170
00:07:53,650 --> 00:07:55,510
And then what do we need to get here?

171
00:07:55,510 --> 00:08:02,890
We need to get the vector to parentheses semicolon so there'll be a particular value and we want to

172
00:08:02,890 --> 00:08:05,830
assign that value to our move input variable.

173
00:08:06,040 --> 00:08:07,360
Now there's the last step in here.

174
00:08:07,360 --> 00:08:08,830
Let's check that this is working.

175
00:08:08,830 --> 00:08:11,650
I'm going to just do a debug log and what do you think?

176
00:08:11,650 --> 00:08:12,880
We're going to log out.

177
00:08:12,940 --> 00:08:17,470
We're going to log out, move input and save that up back over into unity.

178
00:08:17,470 --> 00:08:18,550
Let's see how that worked.

179
00:08:18,550 --> 00:08:19,960
We'll see if it did or didn't work.

180
00:08:19,960 --> 00:08:21,220
Clear some errors here.

181
00:08:21,250 --> 00:08:23,740
There's always going to be something that Rick has done wrong.

182
00:08:23,740 --> 00:08:25,240
Method must have a return type.

183
00:08:25,240 --> 00:08:26,080
Oh, Rick.

184
00:08:26,080 --> 00:08:27,460
Oh, Rick, what have you done here?

185
00:08:27,460 --> 00:08:29,020
We need to have void in front.

186
00:08:29,020 --> 00:08:29,740
My apologies.

187
00:08:29,740 --> 00:08:34,059
If you were yelling at the screen while I was doing that a little bit rusty today, not paying attention.

188
00:08:34,059 --> 00:08:35,710
That should clear things up.

189
00:08:35,740 --> 00:08:39,580
Okay, we'll click on play back into our game and let's see if that's going to work.

190
00:08:39,580 --> 00:08:41,049
Left Arrow Yeah, right.

191
00:08:41,049 --> 00:08:41,740
Arrow Cool.

192
00:08:41,740 --> 00:08:46,090
So it's showing that there's some change when we lift up or push down, lift up, push down.

193
00:08:46,090 --> 00:08:50,560
As we've done in previous lectures, we now have our input for up, down and left, right, and in the

194
00:08:50,560 --> 00:08:53,470
next lecture we can get our character running left and right.

195
00:08:53,470 --> 00:08:53,980
So good stuff.

196
00:08:53,980 --> 00:08:54,940
I'll see you in the next lecture.

