Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,200 --> 00:00:05,060
In this video, we're going to set up the entire input system for our character and very basic movement.
2
00:00:05,700 --> 00:00:07,110
The way inputs are set up.
3
00:00:07,110 --> 00:00:13,620
Drastically changed with Unreal Engine 5.1, but since we are using 5.3, we are already able to use
4
00:00:13,620 --> 00:00:16,740
the Enhanced Input Action System and its active by default.
5
00:00:16,770 --> 00:00:19,200
Let's have a look at the settings first though.
6
00:00:19,230 --> 00:00:26,010
Go to Edit Project Settings and here we can now look for Engine and input.
7
00:00:26,130 --> 00:00:29,970
And you can see here at the top the access and action mappings are now deprecated.
8
00:00:30,000 --> 00:00:33,060
This is the old system we used before 5.1.
9
00:00:33,060 --> 00:00:38,940
However if you scroll down now you can see here under the default classes, the default player input
10
00:00:38,940 --> 00:00:40,890
class is now the enhanced player input.
11
00:00:40,890 --> 00:00:45,300
And we also have the enhanced input component as the default value.
12
00:00:45,300 --> 00:00:50,130
This means that we are using the Enhanced Input Action system, which became the default with Unreal
13
00:00:50,130 --> 00:00:51,420
Engine 5.1.
14
00:00:51,420 --> 00:00:56,430
This system is a little bit complicated and takes some time to set up, but it actually is very powerful
15
00:00:56,430 --> 00:01:00,780
and it gives you many new functions out of the box that we're actually also going to make use of throughout
16
00:01:00,780 --> 00:01:01,500
this course.
17
00:01:01,500 --> 00:01:02,700
Okay, let's set it up.
18
00:01:02,700 --> 00:01:03,270
Now.
19
00:01:03,270 --> 00:01:06,330
We can close out here and we can also close the player.
20
00:01:06,330 --> 00:01:12,540
And in the content drawer we want to go to content and right click to create a new folder and just call
21
00:01:12,540 --> 00:01:13,380
it input.
22
00:01:13,930 --> 00:01:17,620
And in here we want to have another folder called actions.
23
00:01:17,620 --> 00:01:21,610
And the enhanced input system basically has two different asset types.
24
00:01:21,640 --> 00:01:26,020
We can just go into actions here and right click go to input.
25
00:01:26,020 --> 00:01:29,800
And you can see the input action and the input mapping context.
26
00:01:29,800 --> 00:01:33,880
These are the two asset types we're going to use to create this mapping.
27
00:01:34,000 --> 00:01:36,250
First we want to have an input action.
28
00:01:36,250 --> 00:01:41,860
And let's just start with a simple one just called IA for input action underscore jump.
29
00:01:44,720 --> 00:01:47,900
And if you open this up, you can see that there's a couple of settings.
30
00:01:47,900 --> 00:01:50,210
And usually we don't change most of these.
31
00:01:50,240 --> 00:01:52,790
The only important one is the value type.
32
00:01:52,790 --> 00:01:56,150
And you can see by default this is digital bool.
33
00:01:56,150 --> 00:02:00,920
So this basically means that this action is a regular button.
34
00:02:00,920 --> 00:02:05,000
Like maybe the spacebar that can either be pressed or not be pressed.
35
00:02:05,000 --> 00:02:06,860
And that is what a bool means.
36
00:02:07,010 --> 00:02:09,020
Otherwise we have access 1D.
37
00:02:09,050 --> 00:02:11,270
This means it could be either left or right.
38
00:02:11,270 --> 00:02:15,080
For example, it could have a minus one value and a plus one value.
39
00:02:15,110 --> 00:02:18,740
We have access 2D which could be left right up down.
40
00:02:18,740 --> 00:02:22,910
And then we have access 3D which is something more complicated like a motion controller.
41
00:02:22,910 --> 00:02:27,440
So maybe in the smartphone the motion controller or motion controllers for VR games.
42
00:02:27,440 --> 00:02:30,470
And this is what we have to set up for the value type.
43
00:02:30,470 --> 00:02:32,960
But again the jumping is just a very simple button.
44
00:02:32,960 --> 00:02:34,340
It could just be pressed or not.
45
00:02:34,340 --> 00:02:36,890
So this digital bool is fine for here.
46
00:02:37,630 --> 00:02:41,590
Let's go back here and create another input for the movement.
47
00:02:41,590 --> 00:02:49,480
So here again right click input input action IA underscore move and double click to open it up.
48
00:02:49,480 --> 00:02:54,250
And like I just said before if we have something that could have left and right so could have multiple
49
00:02:54,250 --> 00:02:57,370
inputs, we want to use axis 1D.
50
00:02:57,370 --> 00:02:59,470
In our game we can only walk left and right.
51
00:02:59,470 --> 00:03:01,690
We cannot walk up and we cannot walk down.
52
00:03:01,690 --> 00:03:03,700
So we actually don't need the axis 2D.
53
00:03:03,730 --> 00:03:04,840
We just need left and right.
54
00:03:04,840 --> 00:03:07,000
So axis 1D is the correct one here.
55
00:03:07,000 --> 00:03:11,140
Just select it and save and close this down okay.
56
00:03:11,140 --> 00:03:13,810
So now we set up the actions for our jumping and our moving.
57
00:03:13,810 --> 00:03:15,760
And those are the two we want to concentrate on.
58
00:03:15,760 --> 00:03:20,950
Now as we implement the shooting or other actions we can just put them in here as well.
59
00:03:20,950 --> 00:03:24,400
But we also need to bind them now so we can go back to input.
60
00:03:24,400 --> 00:03:26,860
Right click here, go to input.
61
00:03:26,860 --> 00:03:29,890
And now we need the input mapping context.
62
00:03:29,890 --> 00:03:33,010
And we're going to call this IMC underscore action.
63
00:03:33,550 --> 00:03:35,260
For action game.
64
00:03:37,430 --> 00:03:39,140
Double click to open it up.
65
00:03:39,500 --> 00:03:41,690
And I can just move this over here.
66
00:03:41,780 --> 00:03:47,090
And we now need to bind all of the input actions that we created to a button.
67
00:03:47,480 --> 00:03:53,390
So here for the mappings we can just press on plus and need to open this up here and here instead of
68
00:03:53,390 --> 00:03:53,660
none.
69
00:03:53,660 --> 00:03:55,490
We can first start with the jump.
70
00:03:55,490 --> 00:03:57,530
So just select the IA jump.
71
00:03:57,530 --> 00:03:59,180
And we can then open this up here.
72
00:03:59,180 --> 00:04:01,790
And we need to set the button we want.
73
00:04:01,940 --> 00:04:04,790
And I actually want to set this to the spacebar.
74
00:04:05,060 --> 00:04:09,320
But I also want to have this on a different button because spacebar is a little bit hard to use.
75
00:04:09,320 --> 00:04:13,310
Once we also have shooting and other actions implemented so we can just press on.
76
00:04:13,310 --> 00:04:14,300
Plus here again.
77
00:04:14,300 --> 00:04:16,640
And now we have a second input here.
78
00:04:16,640 --> 00:04:18,980
And I like to use K for this.
79
00:04:19,459 --> 00:04:22,460
And yeah I like to use K for jumping and J for shooting.
80
00:04:22,460 --> 00:04:24,860
But the shooting we're going to implement later.
81
00:04:24,860 --> 00:04:28,910
And you can see here we have triggers modifiers, all of these things we don't have to worry about.
82
00:04:28,910 --> 00:04:31,250
Now let's set up the movement as well.
83
00:04:32,360 --> 00:04:33,590
So next mappings.
84
00:04:33,590 --> 00:04:38,480
Click on plus and select the IA move here.
85
00:04:38,480 --> 00:04:42,290
And now we need to have an input for right and an input for left.
86
00:04:42,290 --> 00:04:44,240
So let's start out with the right first.
87
00:04:44,240 --> 00:04:45,380
So click here.
88
00:04:45,380 --> 00:04:50,780
And then on the keyboard press D for right because we want to use the wasD controls.
89
00:04:53,070 --> 00:04:56,580
And here we don't have to change anything for the modifiers triggers.
90
00:04:56,580 --> 00:05:03,060
This is just fine because for an axis mundi, the default direction is right and D is the right direction,
91
00:05:03,060 --> 00:05:04,680
so we don't have to change anything.
92
00:05:04,710 --> 00:05:07,680
Then we press plus again and add a.
93
00:05:07,680 --> 00:05:10,260
So click here, press A on the keyboard for left.
94
00:05:10,260 --> 00:05:16,620
And here we actually do have to change something because A is the left direction which is not the default.
95
00:05:16,620 --> 00:05:20,910
For an axis 1D we have to go to modifiers, click on plus.
96
00:05:20,910 --> 00:05:26,700
And there's a lot of different modifiers here, a lot of them you're not going to use, but the one
97
00:05:26,700 --> 00:05:28,320
you use all the time is negate.
98
00:05:28,320 --> 00:05:32,430
So this means it's going to flip around the input to be left.
99
00:05:32,430 --> 00:05:36,090
So for a and this is all we need to do in the IMC here.
100
00:05:36,090 --> 00:05:38,160
So we can save and exit out.
101
00:05:38,160 --> 00:05:39,810
But this is still not enough.
102
00:05:39,810 --> 00:05:41,040
We just prepared the assets.
103
00:05:41,040 --> 00:05:44,370
But even now again I start the game I still cannot do anything.
104
00:05:44,370 --> 00:05:50,310
We also need to tell this player character, this blueprint to actually use this action mapping.
105
00:05:50,520 --> 00:05:53,550
So we can go to blueprints character.
106
00:05:53,550 --> 00:05:57,510
And again we don't need this for the action chart because the enemies aren't going to use this.
107
00:05:57,510 --> 00:06:03,960
Only the player open up the BP player and on Beginplay, which is either when the game starts or when
108
00:06:03,960 --> 00:06:08,580
this blueprint is being spawned in, we actually want to set up the binding.
109
00:06:10,050 --> 00:06:13,740
Here we want to right click and get controller.
110
00:06:15,050 --> 00:06:20,150
Like this and cast to playercontroller and just connect this.
111
00:06:20,680 --> 00:06:23,530
And this is just a pattern that you have to remember.
112
00:06:23,530 --> 00:06:31,030
And here we can look for subsystem to get enhanced input local player subsystem like this.
113
00:06:31,930 --> 00:06:36,940
And then look for add mapping context and connect this here.
114
00:06:37,330 --> 00:06:42,670
So yeah we get the controller, cast it to a player controller, get the subsystem and then add the
115
00:06:42,670 --> 00:06:44,050
mapping context on it.
116
00:06:45,830 --> 00:06:49,580
And this is just a pattern that you kind of have to remember or just look it up.
117
00:06:49,580 --> 00:06:55,190
And very important here for the mapping context, we have to select our IMC action or nothing is going
118
00:06:55,190 --> 00:06:59,540
to work because you can actually have multiple mapping contexts available at the same time.
119
00:06:59,540 --> 00:07:01,190
And this is why you have the priority.
120
00:07:01,190 --> 00:07:04,400
But for a simple game like this, this is nothing we have to worry about.
121
00:07:05,050 --> 00:07:11,680
And now that this is set up, we can well, we can first delete this action, overlap and tick because
122
00:07:11,680 --> 00:07:13,060
we're not going to use it for now.
123
00:07:13,060 --> 00:07:18,040
And we can just right click and first look for our IA jump.
124
00:07:18,810 --> 00:07:19,320
Right.
125
00:07:19,320 --> 00:07:25,470
This, uh, enhanced action events I a jump and this gives us this whole thing with a triggered action
126
00:07:25,470 --> 00:07:25,770
value.
127
00:07:25,770 --> 00:07:29,880
And you can actually open it up, and it's going to show you much more options.
128
00:07:30,900 --> 00:07:35,400
And there are actually some subtle differences depending on if we use triggered or started.
129
00:07:35,400 --> 00:07:38,280
And for the jump we want to use started.
130
00:07:38,280 --> 00:07:43,500
And from start just drag off and look for jump, which is a pre-made function from Unreal Engine on
131
00:07:43,500 --> 00:07:44,670
the character class.
132
00:07:44,940 --> 00:07:49,380
And now we can just compile and save and go to the map and press play.
133
00:07:50,070 --> 00:07:51,120
And very important.
134
00:07:51,120 --> 00:07:53,730
If I press the button now, nothing happens.
135
00:07:53,850 --> 00:07:57,870
If you want to control the game, you actually have to click inside of the viewport once.
136
00:07:57,870 --> 00:07:59,550
And this is something some beginners forget.
137
00:07:59,550 --> 00:08:02,280
And then they think that the input mapping doesn't work.
138
00:08:02,280 --> 00:08:02,970
Very important.
139
00:08:02,970 --> 00:08:04,590
Click into the viewport.
140
00:08:04,590 --> 00:08:07,800
And now I can press jump and you can see the character jumps.
141
00:08:07,800 --> 00:08:13,290
This is still very floaty and it feels very bad, but it actually recognizes our input and executes
142
00:08:13,290 --> 00:08:14,550
the action we set.
143
00:08:16,290 --> 00:08:20,640
And we want to go here and from canceled, we actually want to stop jumping.
144
00:08:20,640 --> 00:08:24,390
And this becomes very important once we implement the hold jump.
145
00:08:24,390 --> 00:08:26,310
So we can hold to jump longer.
146
00:08:26,310 --> 00:08:30,360
But we already want to set this up because this is the basic setup for jumping.
147
00:08:31,420 --> 00:08:35,049
Let's now set up the IA move so we can go down here.
148
00:08:35,500 --> 00:08:42,039
Now open up some space here and right click look for IA underscore move which is our enhanced input
149
00:08:42,039 --> 00:08:43,539
action event.
150
00:08:43,539 --> 00:08:48,760
And again we can open this up to get all of the options for moving though we don't want to use started
151
00:08:48,760 --> 00:08:51,340
because started only happens when we press the button.
152
00:08:51,340 --> 00:08:54,370
But movement should also happen while we keep holding the button.
153
00:08:54,370 --> 00:08:56,350
So here we actually want to use triggered.
154
00:08:57,020 --> 00:09:00,080
And for this we can again use a function that is available on the character.
155
00:09:00,080 --> 00:09:04,940
So from triggered we can just look for add movement input here.
156
00:09:04,940 --> 00:09:06,080
Input add movement input.
157
00:09:06,080 --> 00:09:07,100
Very simple.
158
00:09:07,770 --> 00:09:12,150
And here for the scale value we just use the action value.
159
00:09:12,150 --> 00:09:15,870
And this is like I said before the float 1D.
160
00:09:15,870 --> 00:09:21,750
So this could either be minus one for left or one for right or zero for nothing on a keyboard.
161
00:09:21,750 --> 00:09:27,090
But if you use a gamepad, it could also be something like 0.2 if you just tilt the stick slightly,
162
00:09:27,090 --> 00:09:32,340
or if you tilt the stick slightly to the left, maybe 0.5 and -0.5 and things like that.
163
00:09:32,340 --> 00:09:36,510
So we can just get this axis value and put it into the scale value.
164
00:09:36,510 --> 00:09:41,430
But very important, we also need to set the world direction because otherwise it doesn't know like
165
00:09:41,430 --> 00:09:43,350
which direction we want to walk into.
166
00:09:44,910 --> 00:09:51,960
And since we make a simple 2D game, we just have to put in one for X because this is the left and right
167
00:09:51,960 --> 00:09:56,760
direction in the world, we can go to the map and you can see the player start here right.
168
00:09:56,760 --> 00:09:58,980
And you can see this red axis.
169
00:09:58,980 --> 00:10:00,480
So this is the x axis.
170
00:10:00,480 --> 00:10:04,140
And we want the character to only be available to walk here left and right.
171
00:10:04,140 --> 00:10:06,150
We don't want to walk up and down right.
172
00:10:06,150 --> 00:10:11,040
So this is why we just put the 1.0 for x and have zero on y and zero on z.
173
00:10:11,830 --> 00:10:13,540
And this is all we need for this.
174
00:10:13,540 --> 00:10:15,160
So we can just compile and save.
175
00:10:15,190 --> 00:10:17,680
Go to the map again click into the viewport.
176
00:10:17,680 --> 00:10:18,550
Very important.
177
00:10:18,550 --> 00:10:23,110
And now click on A for left D for right.
178
00:10:23,110 --> 00:10:24,910
And yeah we can move around.
179
00:10:24,910 --> 00:10:25,900
We can jump.
180
00:10:25,900 --> 00:10:28,000
We can jump while moving as well.
181
00:10:28,000 --> 00:10:29,920
And this is how we set this up.
182
00:10:29,920 --> 00:10:34,030
But of course we want the character to turn into the direction we're walking.
183
00:10:34,030 --> 00:10:36,820
And this is actually also very easy to set up.
184
00:10:37,310 --> 00:10:42,500
And we only need to worry about turning left and right while we are using an input, right?
185
00:10:42,500 --> 00:10:48,710
So we just want to check what's the last input, a right input or a left input and then turn the character
186
00:10:48,710 --> 00:10:50,000
around depending on that.
187
00:10:50,650 --> 00:10:56,290
And for deciding if we turn the character left or right, we simply have to check for this action value,
188
00:10:56,290 --> 00:11:01,090
and we have to check if it is greater or equal than zero.
189
00:11:01,090 --> 00:11:06,160
And this would mean yes, we want to go right, and if this is not the case, then we want to go left.
190
00:11:06,160 --> 00:11:07,630
But how do we do that.
191
00:11:07,630 --> 00:11:10,300
So we can get controller.
192
00:11:11,110 --> 00:11:13,450
And this is specific for players only.
193
00:11:13,450 --> 00:11:14,710
This does not work on MPC.
194
00:11:14,710 --> 00:11:17,290
So for the NPCs we're going to use a different method later.
195
00:11:18,680 --> 00:11:22,100
And here we can just set control rotation.
196
00:11:22,730 --> 00:11:25,280
Like this and connect.
197
00:11:26,660 --> 00:11:28,850
And we then want to use this.
198
00:11:28,850 --> 00:11:30,230
Uh, well, we could use a branch.
199
00:11:30,230 --> 00:11:30,440
Right.
200
00:11:30,440 --> 00:11:35,060
So here we can use a branch, which is like a true or false statement.
201
00:11:35,060 --> 00:11:35,270
Right.
202
00:11:35,270 --> 00:11:40,160
So we could have true and go into certain direction and on false go in a different direction.
203
00:11:40,160 --> 00:11:42,860
But there's actually a cleaner way of doing this.
204
00:11:42,890 --> 00:11:48,410
We can just drag off here from the new rotation and select and get the utility select.
205
00:11:48,410 --> 00:11:55,040
And this basically if we connect here to the wild card, uh lets us make a shortcut so we don't have
206
00:11:55,040 --> 00:11:55,700
to use a branch.
207
00:11:55,700 --> 00:11:57,530
We can simply put the values here.
208
00:11:57,530 --> 00:12:01,880
And well both methods are fine, but I just prefer this one personally.
209
00:12:01,880 --> 00:12:08,720
And we can then decide which value we want to use if we're, uh, going to the right and which value
210
00:12:08,720 --> 00:12:09,950
we want to use if we go to the left.
211
00:12:09,950 --> 00:12:13,850
So here we can just drag off and make rotator.
212
00:12:14,590 --> 00:12:15,850
All the way at the bottom.
213
00:12:17,410 --> 00:12:22,060
And well, if we are looking to the right, we don't have to change the rotation.
214
00:12:22,060 --> 00:12:28,240
000 is the default, so this is fine, but if we want to go to the left, we can just control C control
215
00:12:28,240 --> 00:12:29,860
V copy and paste this.
216
00:12:30,310 --> 00:12:37,780
We want to change the yaw to 180 to turn in the other direction.
217
00:12:38,340 --> 00:12:39,270
Right.
218
00:12:39,600 --> 00:12:44,610
So again we just check for the action value if the last input was bigger or equal than zero.
219
00:12:44,640 --> 00:12:46,500
This means we are going to the right.
220
00:12:46,500 --> 00:12:49,080
This means we also want to turn towards the right.
221
00:12:49,080 --> 00:12:51,330
If this is not the case, we're going towards the left.
222
00:12:51,330 --> 00:12:54,720
We want to turn towards the left and we execute this on the set.
223
00:12:54,720 --> 00:12:58,830
Control rotation can just compile and save and check this out.
224
00:12:58,830 --> 00:13:03,150
I go right, the character looks right, I go left, the character flips around.
225
00:13:03,150 --> 00:13:03,960
So this is fine.
226
00:13:03,960 --> 00:13:09,210
The character flips around, but the camera also flips around, which is something we don't want.
227
00:13:09,270 --> 00:13:11,460
And there's actually an easy fix for this.
228
00:13:11,460 --> 00:13:14,970
But first, we confirmed that this works properly.
229
00:13:14,970 --> 00:13:21,420
So we can just select all of these, select these, hold shift, select the other ones and we can just
230
00:13:21,420 --> 00:13:22,350
collapse them.
231
00:13:23,410 --> 00:13:30,610
So here we can just right click one of these and collapse to function and just call it update rotation.
232
00:13:31,720 --> 00:13:33,520
I just had a typo update rotation.
233
00:13:34,050 --> 00:13:35,610
And drag this up here.
234
00:13:36,990 --> 00:13:40,860
Double click the line here to create a reroute node.
235
00:13:41,280 --> 00:13:42,510
Yeah, just keep it clean.
236
00:13:43,250 --> 00:13:48,230
And we don't want this to be called a we want this to be called direction.
237
00:13:48,350 --> 00:13:53,660
Well, direction in the sense of its if its minus its left if its plus its right.
238
00:13:53,960 --> 00:13:54,770
And yeah.
239
00:13:54,770 --> 00:13:56,690
So all of the stuff is still in here.
240
00:13:56,990 --> 00:13:58,910
But we just finished this.
241
00:13:58,910 --> 00:14:00,410
We never have to worry about this again.
242
00:14:00,410 --> 00:14:01,250
This is completed.
243
00:14:01,250 --> 00:14:03,410
So we just collapse it into a function.
244
00:14:03,470 --> 00:14:05,480
It's also available on the left side here now.
245
00:14:05,480 --> 00:14:08,510
And this just makes it look cleaner and more manageable.
246
00:14:08,960 --> 00:14:12,410
But let's now take care of the camera so we can go to the viewport.
247
00:14:12,410 --> 00:14:14,540
We can look at the spring arm.
248
00:14:14,540 --> 00:14:21,740
And we want the spring arm to basically ignore the rotation of the capsule component and of the actor
249
00:14:21,740 --> 00:14:22,550
as a whole.
250
00:14:22,550 --> 00:14:24,770
And this is actually very easy to do.
251
00:14:25,600 --> 00:14:32,800
We can just go to the transform rotation and set this from relative to world, which will then be shown
252
00:14:32,800 --> 00:14:34,540
as absolute rotation.
253
00:14:34,540 --> 00:14:37,780
And this just means it is always going to keep this rotation.
254
00:14:37,780 --> 00:14:42,220
It's going to ignore what the capsule, what the actor and everything else does.
255
00:14:42,220 --> 00:14:43,570
So just compile and save.
256
00:14:43,600 --> 00:14:46,900
Go back I go right, it's fine, I go left.
257
00:14:46,900 --> 00:14:47,680
It is also fine.
258
00:14:47,680 --> 00:14:51,970
I'm turning around, but the camera is ignoring whatever the character is doing.
259
00:14:52,060 --> 00:14:55,780
And this is the basic setup for our input system.
260
00:14:55,780 --> 00:14:57,700
So congrats on coming this far.
261
00:14:57,700 --> 00:15:02,560
This is a little bit hard to wrap your head around at first, but you're going to use this in all of
262
00:15:02,560 --> 00:15:03,190
your projects.
263
00:15:03,190 --> 00:15:04,300
You're going to get more used to it.
264
00:15:04,300 --> 00:15:08,800
You're going to start to understand the amazing features this gives us, even if it's a little bit of
265
00:15:08,800 --> 00:15:10,540
a pain to set up in the first place.
266
00:15:11,610 --> 00:15:16,140
However, you also notice that even if we can walk around and jump, it doesn't really look that way
267
00:15:16,140 --> 00:15:18,780
because we're just playing the idle animation on the character.
268
00:15:18,780 --> 00:15:23,700
So the next chapter is going to be very interesting, because we're going to use paper 3D to set up
269
00:15:23,700 --> 00:15:28,260
the animation tree to make the character animate, depending on if we're walking, if we're jumping,
270
00:15:28,260 --> 00:15:29,190
if we're falling.
271
00:15:29,190 --> 00:15:31,560
So please look forward to that lesson.
25571
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.