﻿1
00:00:04,500 --> 00:00:05,580
‫Hello and welcome.

2
00:00:05,580 --> 00:00:11,220
‫In this lecture, we're going to be firing off the cannibals in the forward direction of the camera

3
00:00:11,220 --> 00:00:13,170
‫and the cannonball itself.

4
00:00:13,170 --> 00:00:19,980
‫So if I hit space, you can see that I can actually start to aim this ball at objects and try and hit

5
00:00:19,980 --> 00:00:23,010
‫objects in the distance, which is a lot more fun.

6
00:00:23,010 --> 00:00:24,120
‫Yes, I got that chair.

7
00:00:24,390 --> 00:00:26,940
‫It's a lot more fun than it was previously.

8
00:00:26,940 --> 00:00:28,860
‫Let's dive in and see how to do this.

9
00:00:29,220 --> 00:00:33,270
‫So we're going to be using something called a forward vector, but what is it?

10
00:00:33,270 --> 00:00:40,950
‫So I've just, on the sake of argument on this slide, puts in an X and y directions just like we would

11
00:00:40,950 --> 00:00:45,120
‫have in the viewport to keep things grounded in that reality.

12
00:00:45,120 --> 00:00:50,910
‫And we can imagine we've got our camera here, that is the player's camera that when we rotate the mouse,

13
00:00:50,910 --> 00:00:53,880
‫it's turning around and we spawning it.

14
00:00:53,880 --> 00:01:00,090
‫Now our projectile and the newly spawned projectile is getting the correct rotation from the camera.

15
00:01:00,090 --> 00:01:03,030
‫So you can see this as I've depicted it on the slide.

16
00:01:03,030 --> 00:01:09,720
‫Now, the forward vector would be essentially the rotated X direction.

17
00:01:09,720 --> 00:01:16,470
‫So it is basically a vector that points in the forward direction after you have rotated it.

18
00:01:16,470 --> 00:01:20,790
‫So you can see this projector has been rotated around and its forward direction is over here rather

19
00:01:20,790 --> 00:01:28,050
‫than being off back towards the back of the camera because of the rotation that we've given it from

20
00:01:28,050 --> 00:01:36,090
‫the Player Pawns Control rotation, now we can actually get a right vector as well, which is essentially

21
00:01:36,090 --> 00:01:38,640
‫the Y axis that's been rotated.

22
00:01:38,640 --> 00:01:43,140
‫But we're not going to be using that because all we're interested in is sending the projectile in that

23
00:01:43,140 --> 00:01:44,580
‫forward direction.

24
00:01:44,580 --> 00:01:51,840
‫And what's interesting about the vectors that come back from Get Forward vector and from get write vector

25
00:01:51,840 --> 00:01:55,020
‫is that they have a length of one.

26
00:01:55,080 --> 00:01:56,130
‫Less can be guaranteed.

27
00:01:56,130 --> 00:01:57,900
‫They're always going to have a length of one.

28
00:01:57,900 --> 00:02:03,840
‫And this is really useful because if we want to apply a certain amount of impulse in this direction,

29
00:02:03,840 --> 00:02:11,340
‫all we need to do is multiply this vector to give us the direction by the value that we want, such

30
00:02:11,340 --> 00:02:14,730
‫as 400, if that's the velocity you want to give it.

31
00:02:14,730 --> 00:02:18,600
‫So enough torque, how do we actually achieve this in blueprint?

32
00:02:18,600 --> 00:02:23,880
‫So what we need to do is query that newly spawned projectile.

33
00:02:23,880 --> 00:02:29,070
‫We've given it the correct rotation over here before we spawned it, and it's been spawned with the

34
00:02:29,070 --> 00:02:29,730
‫correct rotation.

35
00:02:29,730 --> 00:02:32,670
‫We could see that when we play the game.

36
00:02:32,670 --> 00:02:35,700
‫So we need to get its forward vector.

37
00:02:35,700 --> 00:02:41,160
‫So to do that we can either pull off of the actor reference itself.

38
00:02:41,160 --> 00:02:46,950
‫So the reference to the beep projectile which comes out of the spawn actor node, or we could do it

39
00:02:46,950 --> 00:02:48,150
‫from the static component.

40
00:02:48,150 --> 00:02:49,590
‫Either one would work just fine.

41
00:02:49,590 --> 00:02:54,240
‫I'm going to do it from the actor just to save on nodes and keep things a little bit tidier.

42
00:02:54,240 --> 00:03:01,260
‫So what we're going to do here is type in, get forward vector and we can see two options here.

43
00:03:01,260 --> 00:03:03,540
‫I'm going to be using the get active forward vector.

44
00:03:03,540 --> 00:03:08,670
‫Both would actually give you the same result and then we've got ourselves the vector value.

45
00:03:08,670 --> 00:03:13,860
‫Now if we plug this directly into the impulse, we aren't going to see much of an effect.

46
00:03:13,860 --> 00:03:18,990
‫If we go ahead and hit play and we spawn a projectile, you can see it just drops straight down.

47
00:03:18,990 --> 00:03:25,620
‫And the reason for that is that the length of this vector is going to be one which, as we know, because

48
00:03:25,620 --> 00:03:28,200
‫of unreal units, that's in centimeters.

49
00:03:28,200 --> 00:03:33,270
‫So it's giving us one centimeter per second, which is a pretty puny velocity.

50
00:03:33,270 --> 00:03:38,520
‫So what we need to be able to do is multiply this vector by a float.

51
00:03:38,520 --> 00:03:41,220
‫Fortunately, we can do that fairly straightforwardly in blueprint.

52
00:03:41,220 --> 00:03:48,540
‫We can drag off of the return value for this forward vector and we can type multiply and that gives

53
00:03:48,540 --> 00:03:54,540
‫us this multiply operator node and you see by default what it wants to do is it wants to multiply a

54
00:03:54,540 --> 00:03:57,840
‫vector by a vector, but that's not what we want to achieve.

55
00:03:57,840 --> 00:04:02,730
‫And fortunately we can change that by right clicking on the second input node.

56
00:04:02,730 --> 00:04:09,780
‫We can click convert pin and we can convert the pin to a float and that gives us the correct type of

57
00:04:09,780 --> 00:04:11,610
‫multiplication that we want.

58
00:04:11,610 --> 00:04:16,470
‫So I'd like to challenge you to do this multiply vector for yourself.

59
00:04:16,470 --> 00:04:24,330
‫So plug in the multiplication node to both the input and the output to the impulse.

60
00:04:24,330 --> 00:04:30,060
‫And how much do you need to multiply by to get a force that you are happy with?

61
00:04:30,090 --> 00:04:32,130
‫Pause the video and have a go.

62
00:04:35,200 --> 00:04:37,070
‫Hello and welcome back.

63
00:04:37,090 --> 00:04:45,520
‫So we're going to I've already been using a value of about I think we said about 400 and then I'm going

64
00:04:45,520 --> 00:04:49,780
‫to plug in the output from the multiplication into the input for the impulse.

65
00:04:49,780 --> 00:04:58,540
‫So what we're getting is a vector that is 400 units long and is pointing in the direction, the forward

66
00:04:58,540 --> 00:05:03,040
‫direction of our BP projectile, the way it's rotating.

67
00:05:03,040 --> 00:05:05,620
‫And that is also at the same direction as our camera.

68
00:05:05,620 --> 00:05:07,930
‫So let's go ahead and hit play.

69
00:05:07,930 --> 00:05:12,580
‫And when we fire, you can see that it is firing off in the right direction, but with not quite enough

70
00:05:12,580 --> 00:05:13,150
‫force.

71
00:05:13,150 --> 00:05:17,770
‫So I'm going to increase this by make it 1000.

72
00:05:17,770 --> 00:05:19,240
‫Let's try with 1000.

73
00:05:19,240 --> 00:05:19,630
‫Okay.

74
00:05:19,630 --> 00:05:23,280
‫We're getting something a lot better now that we can actually start to enjoy.

75
00:05:23,290 --> 00:05:25,120
‫I think we had actually 4000.

76
00:05:25,120 --> 00:05:31,180
‫I think I'm just misremembering, if we go ahead and play now with 4000, you can see a projectile that's

77
00:05:31,180 --> 00:05:32,920
‫a lot more fun to fire.

78
00:05:32,920 --> 00:05:37,990
‫And the final thing that I want to do is because we don't need to know it's rotation anymore.

79
00:05:37,990 --> 00:05:41,680
‫And it kind of looks weird that it's this elongated shape.

80
00:05:41,680 --> 00:05:43,480
‫I want to go back into the beep.

81
00:05:43,480 --> 00:05:48,430
‫Projectile editor selecting the static measure component, go into the details pane and I'm just going

82
00:05:48,430 --> 00:05:54,520
‫to set the scale back to 0.5 like all of the other elements there, which gives us the ball back to

83
00:05:54,520 --> 00:05:55,720
‫being spherical.

84
00:05:55,720 --> 00:06:01,450
‫And if we go ahead and hit play now, we've got a nice little cannonball, which is actually a lot of

85
00:06:01,450 --> 00:06:05,440
‫fun to fire an objects and cause a little bit of destruction.

86
00:06:05,440 --> 00:06:06,070
‫Great stuff.

87
00:06:06,070 --> 00:06:11,260
‫We've achieved a lot in this lecture by applying that get forward vector node.

88
00:06:11,260 --> 00:06:12,730
‫I'll see you in the next one.

