﻿1
00:00:04,430 --> 00:00:06,020
‫Hello and welcome this lecture.

2
00:00:06,020 --> 00:00:11,810
‫We're going to be using those functionality nodes to manipulate the objects in our scene on request.

3
00:00:11,810 --> 00:00:17,270
‫So if I hit a spacebar, I can make this cube bunny hop up and down.

4
00:00:17,270 --> 00:00:19,700
‫Let's dive in and see how this works.

5
00:00:21,290 --> 00:00:24,320
‫So it's all very well being able to get data out of objects in the scene.

6
00:00:24,320 --> 00:00:26,710
‫But what about making them do stuff?

7
00:00:26,720 --> 00:00:33,830
‫Well, what I would like to do is use our physics system here to add a force to an cube and make it

8
00:00:33,830 --> 00:00:39,230
‫jump up in the air or be the first thing that we do with our programming that actually allows it to

9
00:00:39,230 --> 00:00:41,570
‫act in response to something.

10
00:00:41,990 --> 00:00:48,500
‫Now, the way I want to do this is so that it does it in response to actually pressing a key.

11
00:00:48,860 --> 00:00:51,590
‫We've used this Begin Play event in the past.

12
00:00:51,590 --> 00:00:54,140
‫I want to introduce you to some new events here.

13
00:00:54,440 --> 00:00:59,300
‫What we're going to do is we're going to right click in the level blueprint and we're going to search

14
00:00:59,300 --> 00:01:01,730
‫for Space Bar.

15
00:01:02,180 --> 00:01:06,830
‫And you can see that gives us a keyboard event under the category keyboard event space bar.

16
00:01:06,830 --> 00:01:11,840
‫We can click on that and we're going to bring in a new event node that's this red one that tells us

17
00:01:11,840 --> 00:01:13,010
‫when something should happen.

18
00:01:13,100 --> 00:01:18,440
‫And you can see it has two execution pins, one for when the space bar is pressed and one for when the

19
00:01:18,440 --> 00:01:19,820
‫space bar is released.

20
00:01:20,060 --> 00:01:26,960
‫So let's use this, shall we, to actually print the mass of our cube so I can do this by selecting

21
00:01:26,960 --> 00:01:29,900
‫all these nodes, and I can shift click to select more.

22
00:01:29,900 --> 00:01:38,420
‫I can drag them down into place and I can drag from the pressed execution pin to the input pin of our

23
00:01:38,420 --> 00:01:39,680
‫print string node.

24
00:01:40,310 --> 00:01:46,130
‫And you can see that that's going to actually have two execution pins go into print string, which means

25
00:01:46,130 --> 00:01:51,080
‫that this can be executed either when the spacebar is pressed or when we begin play.

26
00:01:51,080 --> 00:01:54,260
‫So let's go ahead and hit play and see that actually works.

27
00:01:54,260 --> 00:02:00,320
‫So we've got the thousand that comes up when we begin play space bar and thousand comes up again.

28
00:02:01,220 --> 00:02:05,180
‫What I want to do is for this to actually apply a force upwards.

29
00:02:05,570 --> 00:02:10,700
‫Now in actual fact, we don't want it to apply a force, but we want to have it apply something called

30
00:02:10,700 --> 00:02:11,750
‫an impulse.

31
00:02:11,750 --> 00:02:17,870
‫Now, the difference between the two, in physics parlance, is that a force happens over a certain

32
00:02:17,870 --> 00:02:22,040
‫amount of time, whereas an impulse is instantaneous.

33
00:02:22,040 --> 00:02:27,200
‫So what we're going to do is we're going to delete our print string node and we're going to delete the

34
00:02:27,200 --> 00:02:29,540
‫get mass and the conversion node as well.

35
00:02:29,630 --> 00:02:34,130
‫But we're going to leave the cube and static mesh nodes.

36
00:02:34,130 --> 00:02:35,660
‫So we've got our static mesh reference.

37
00:02:35,660 --> 00:02:41,900
‫So if we pull off of this, we're going to look for something that can add an impulse to our cube.

38
00:02:41,900 --> 00:02:48,620
‫Now notice that when I'm doing this, the search menu here has got context sensitive switched on.

39
00:02:48,950 --> 00:02:56,270
‫And that's quite important because this means it filters down the nodes available to the ones that use

40
00:02:56,270 --> 00:02:58,700
‫the static mesh component object.

41
00:02:58,700 --> 00:03:05,570
‫So if I look for impulse in here and type in impulse, you can see there is an add impulse node here.

42
00:03:05,570 --> 00:03:08,180
‫There's a few of them, but there's an ad impulse one.

43
00:03:08,180 --> 00:03:09,830
‫Let's go ahead and get that.

44
00:03:10,250 --> 00:03:15,980
‫You can see it's got execution pins that tell us when we should add the impulse so we can go ahead and

45
00:03:15,980 --> 00:03:20,720
‫instantly connect this up to the space bar pressed execution node.

46
00:03:20,720 --> 00:03:27,560
‫So this should mean that the impulse will get added when the space bar is pressed.

47
00:03:27,980 --> 00:03:35,360
‫So we're doing this we're adding this impulse to the static mesh component, but there are other properties

48
00:03:35,360 --> 00:03:42,260
‫here on the node that we need to fill out, particularly the value of the impulse itself.

49
00:03:42,260 --> 00:03:47,600
‫Now this has three parts to it an X, Y and a Z.

50
00:03:47,600 --> 00:03:54,500
‫In fact, when we have these three parts, it's said to be a vector, but we'll get on to vectors in

51
00:03:54,500 --> 00:03:56,720
‫much more detail in a later lecture.

52
00:03:56,990 --> 00:04:05,030
‫Notice this X, Y and z actually corresponds to the x, y and z we get on our movement widget, on our

53
00:04:05,030 --> 00:04:10,040
‫cube, and also in the bottom left hand corner of our viewport.

54
00:04:10,040 --> 00:04:11,450
‫You can see there's an X, Y and Z.

55
00:04:11,480 --> 00:04:17,390
‫They're showing us which directions these values basically relate to.

56
00:04:17,630 --> 00:04:20,990
‫So what we can do is we can add in a value.

57
00:04:20,990 --> 00:04:27,590
‫If I wanted it to go up, I would use the Z direction and we can put in a value into here, such as,

58
00:04:27,590 --> 00:04:29,360
‫I don't know, 100,000 like this.

59
00:04:29,360 --> 00:04:30,680
‫Let's try that out.

60
00:04:30,680 --> 00:04:33,980
‫We'll go and hit play and hit our spacebar.

61
00:04:34,400 --> 00:04:37,160
‫Then at the moment nothing is happening.

62
00:04:37,160 --> 00:04:42,500
‫And the reason for that is that the value I've entered here is too small.

63
00:04:42,770 --> 00:04:49,970
‫So I'd like you to take the challenge to tweak the impulse to a value that actually jumps it up into

64
00:04:49,970 --> 00:04:50,660
‫the air.

65
00:04:51,020 --> 00:04:55,100
‫So try multiplying the mass by 100.

66
00:04:55,100 --> 00:05:02,300
‫You may find that that is in the right ballpark and at least gets the cube to move, then play around.

67
00:05:02,330 --> 00:05:08,150
‫With this value to get something that you like the look of and that acts in a way that's enjoyable to

68
00:05:08,150 --> 00:05:08,570
‫you.

69
00:05:08,690 --> 00:05:12,950
‫And what if you had added it to X and Y instead?

70
00:05:12,950 --> 00:05:15,360
‫What different effects do you get there?

71
00:05:15,380 --> 00:05:17,450
‫Pause the video and have a go.

72
00:05:20,870 --> 00:05:21,580
‫Okay.

73
00:05:21,590 --> 00:05:22,420
‫Welcome back.

74
00:05:22,430 --> 00:05:25,220
‫So we're going to try this out.

75
00:05:25,220 --> 00:05:30,530
‫I'm saying 1000 and I can actually do the multiplication right from within here using asterisk multiplied

76
00:05:30,530 --> 00:05:36,500
‫by 100 should give us the rough ballpark we play and hit our spacebar.

77
00:05:36,500 --> 00:05:38,720
‫You can see it's doing tiny little bunny hops.

78
00:05:38,750 --> 00:05:39,680
‫Not a great deal.

79
00:05:39,680 --> 00:05:44,390
‫And if I hit spacebar repeatedly, it starts to go a little bit higher in the air.

80
00:05:44,630 --> 00:05:50,570
‫So I'm actually going to multiply this whole value again by asterisk four.

81
00:05:50,570 --> 00:05:55,010
‫So four times the value hit play and then make it jump in the air.

82
00:05:55,010 --> 00:05:59,090
‫And that's a little bit more of a decent bunny hop that we're getting there now.

83
00:05:59,090 --> 00:06:04,490
‫The reason we had to multiply by the mass is because of this formula.

84
00:06:04,490 --> 00:06:09,320
‫That force is actually equal to a mass times and acceleration.

85
00:06:09,320 --> 00:06:15,380
‫So if we want a certain acceleration, we need to multiply it by the mass and that gives us the force

86
00:06:15,380 --> 00:06:16,340
‫required.

87
00:06:16,460 --> 00:06:22,700
‫There's also a similar equation for an impulse where actually if what you want is a change in velocity

88
00:06:22,700 --> 00:06:27,560
‫rather than an acceleration, then you essentially multiply that by the mass.

89
00:06:27,560 --> 00:06:34,970
‫So what I was saying is that I wanted to increase the velocity by 400, which in this case is four meters

90
00:06:34,970 --> 00:06:41,900
‫per second because Unreal uses centimeters as its main unit, then 400 multiplied by the mass of the

91
00:06:41,900 --> 00:06:44,240
‫cube, gives us the impulse required.

92
00:06:44,540 --> 00:06:48,320
‫However, I don't actually have to do that maths if I don't want to.

93
00:06:48,320 --> 00:06:54,170
‫If my desire is a change in velocity, then you see there's this little checkbox down at the bottom

94
00:06:54,170 --> 00:06:58,670
‫of the node which is labelled Velocity Change or val change for short.

95
00:06:58,670 --> 00:07:05,360
‫And if I check that it basically ignores the mass entirely and just applies whatever velocity I want

96
00:07:05,360 --> 00:07:14,030
‫so I can just type in 400 directly into the Z and that will apply a velocity of 400 in the upwards direction,

97
00:07:14,030 --> 00:07:15,620
‫400 centimeters per second.

98
00:07:15,620 --> 00:07:20,600
‫So if I go ahead and play, you can see that the impact is exactly the same.

99
00:07:20,600 --> 00:07:27,680
‫However, now, no matter what mass I set on the cube, it's still going to jump by the same amount.

100
00:07:28,220 --> 00:07:33,320
‫And the final part of the puzzle here is what if I had put this on the X or the Y instead?

101
00:07:33,320 --> 00:07:41,330
‫So if I cut it out of the Z and I put it into Z, Y and I maybe I cancel out Z to zero entirely, if

102
00:07:41,330 --> 00:07:48,230
‫I hit play and hit the spacebar, then you can see it's shifting it over to the side, over to the left,

103
00:07:48,230 --> 00:07:49,700
‫which is the Y direction.

104
00:07:49,700 --> 00:07:54,530
‫If I'd done it in the X, it would shift it forward, which is the X direction.

105
00:07:54,530 --> 00:07:59,660
‫So I'm just going to put that back so that it's just 400 in the Z direction.

106
00:07:59,660 --> 00:08:04,220
‫We can hit play to make sure that that's the case and we've got our bunny hopping.

107
00:08:04,220 --> 00:08:09,290
‫So in this lecture we've seen how we can use nodes to actually do something.

108
00:08:09,290 --> 00:08:15,860
‫We've also looked at vectors and forces and impulses a little bit to understand the physics of those

109
00:08:15,860 --> 00:08:16,700
‫systems.

110
00:08:16,700 --> 00:08:18,140
‫I'll see you in the next lecture.

