﻿1
00:00:04,590 --> 00:00:05,580
‫Hello and welcome.

2
00:00:05,580 --> 00:00:11,610
‫In this lecture, we are going to be sorting out the angle of our blind space, hooking that up to our

3
00:00:11,610 --> 00:00:12,240
‫gameplay.

4
00:00:12,240 --> 00:00:17,550
‫And in the process we're going to have to learn a lot of maths, a lot of transforms and vectors.

5
00:00:17,550 --> 00:00:20,610
‫So let's dive in and figure out how that works.

6
00:00:22,870 --> 00:00:27,280
‫So we want to be able to get the angle at which we should be moving.

7
00:00:27,730 --> 00:00:34,690
‫However, before we do that, we need to do a little bit of maths because we want to understand how

8
00:00:34,690 --> 00:00:38,020
‫we can get this angle which is local to the player.

9
00:00:38,440 --> 00:00:45,070
‫And I'll explain what I mean by local and global and how we can get that from a global velocity and

10
00:00:45,070 --> 00:00:46,870
‫what those terms mean anyway.

11
00:00:47,080 --> 00:00:48,070
‫So let's have a look.

12
00:00:48,070 --> 00:00:53,770
‫First of all, we need to have a bit of a basic primer on transforms and what transforms are we've seen

13
00:00:53,770 --> 00:00:56,560
‫them or you have seen them a little bit before.

14
00:00:56,710 --> 00:01:00,850
‫When you look at any of the scene components, that's these ones in the hierarchy.

15
00:01:01,270 --> 00:01:02,890
‫You can see they have a transform here.

16
00:01:02,890 --> 00:01:07,660
‫So location, rotation, scale properties, that's basically what a transform is.

17
00:01:08,050 --> 00:01:13,000
‫But one thing that you're not seeing here is that also part of this transform is the fact that these

18
00:01:13,000 --> 00:01:19,450
‫same components are in a hierarchy, meaning that their transformer also has a parent or, you know,

19
00:01:19,660 --> 00:01:21,010
‫basically hierarchical.

20
00:01:21,460 --> 00:01:23,380
‫So how does that work?

21
00:01:23,380 --> 00:01:26,440
‫Well, here's a kind of toy example.

22
00:01:26,440 --> 00:01:31,030
‫We've got the cube here which say is our base, it's the center of our world or something.

23
00:01:31,450 --> 00:01:33,730
‫So that's going to be our world space.

24
00:01:33,940 --> 00:01:39,910
‫We've got this character here, the little smiley face, and he's got a position in the world relative

25
00:01:39,910 --> 00:01:41,590
‫to his home base.

26
00:01:42,040 --> 00:01:47,710
‫And then this character has a gun and the gun has a position relative to the character.

27
00:01:47,710 --> 00:01:53,800
‫So the way this hierarchy works is that the parent of the gun is the character, the parent, or the

28
00:01:53,800 --> 00:01:56,620
‫character is his home base or the world.

29
00:01:57,610 --> 00:02:01,780
‫And then we have some local coordinate systems within these.

30
00:02:01,780 --> 00:02:06,610
‫So the worlds coordinate system is the, the world system, the global system.

31
00:02:06,970 --> 00:02:12,430
‫Then the coordinates of our character are then local to its position.

32
00:02:12,430 --> 00:02:15,910
‫So the gun is positioned relative to its character.

33
00:02:15,910 --> 00:02:16,870
‫What does that mean?

34
00:02:16,870 --> 00:02:22,720
‫That means that if the character decides to go off on a little escapade, then the gun moves with it,

35
00:02:22,720 --> 00:02:28,120
‫because the position of the gun relative to the character has remained the same, but because the character's

36
00:02:28,120 --> 00:02:31,120
‫moved, its position in the world has moved.

37
00:02:31,810 --> 00:02:33,790
‫Same happens with rotation.

38
00:02:33,790 --> 00:02:37,690
‫If the character turns around, the gun must turn around as well.

39
00:02:38,170 --> 00:02:42,340
‫That's how Transformers work essentially is also scaled, but we're not going to look at scale.

40
00:02:42,340 --> 00:02:46,870
‫It's the same, but it's just complicating things and we don't need to do.

41
00:02:46,870 --> 00:02:47,560
‫Have a look at that.

42
00:02:47,560 --> 00:02:49,000
‫It's not relevant to us.

43
00:02:49,870 --> 00:02:52,300
‫So let's have a look, a different look at this.

44
00:02:52,300 --> 00:02:54,730
‫We've got global space and local space.

45
00:02:54,730 --> 00:03:02,560
‫So the global space has the base at the center of the world and the character has gone off and to the

46
00:03:02,560 --> 00:03:03,160
‫right.

47
00:03:03,460 --> 00:03:07,000
‫The local space, on the other hand, sees things in the opposite light.

48
00:03:07,000 --> 00:03:13,990
‫It says that the character is the center of the world and that the base has gone over to the left has

49
00:03:13,990 --> 00:03:14,740
‫gone backwards.

50
00:03:14,740 --> 00:03:17,260
‫You know, that's the difference between global and local.

51
00:03:17,260 --> 00:03:19,240
‫It all depends on your point of view.

52
00:03:19,240 --> 00:03:20,590
‫Everything is relative.

53
00:03:20,590 --> 00:03:28,150
‫So this is what we mean when we talk about transforming between global and local space and which one

54
00:03:28,150 --> 00:03:29,290
‫are we interested in?

55
00:03:29,290 --> 00:03:35,020
‫For our angle, we're interested in a local angle relative to where the player is looking.

56
00:03:35,020 --> 00:03:38,770
‫We're saying, you know, are we moving over to the right?

57
00:03:38,770 --> 00:03:42,190
‫That's what we're saying that not globally, but locally.

58
00:03:42,190 --> 00:03:45,340
‫Are we moving to the right locally to our player?

59
00:03:45,340 --> 00:03:50,530
‫Because if our players turned around 180 degrees, he shouldn't play a left animation just because he

60
00:03:50,530 --> 00:03:51,550
‫turned around.

61
00:03:51,970 --> 00:03:59,320
‫So one more important distinction is how we do transformations for vectors of different sorts.

62
00:03:59,770 --> 00:04:04,390
‫The first example I want to look at is a position vector.

63
00:04:04,600 --> 00:04:13,090
‫So a position vector basically is a vector that gives us the difference between the current location

64
00:04:13,210 --> 00:04:19,750
‫or the zero point in our coordinate system, which when we are focused on the character, is the character

65
00:04:19,750 --> 00:04:24,850
‫himself, and then it gives us an arrow that points to where something should be.

66
00:04:24,850 --> 00:04:28,600
‫So in this case, it is the gun location vector.

67
00:04:28,870 --> 00:04:34,180
‫Now, if we transform this in to our world space, this is what happens.

68
00:04:34,180 --> 00:04:40,570
‫The arrow now points from the center of our new world, the global space, and it points to the gun.

69
00:04:41,050 --> 00:04:45,100
‫So that's what happens if you transform a position vector.

70
00:04:45,310 --> 00:04:49,480
‫Now, if you do a direction vector, things look a little bit different.

71
00:04:49,480 --> 00:04:57,460
‫A direction vector is one that says This is the way I should point, not necessarily where a thing is

72
00:04:58,060 --> 00:05:06,340
‫and this transforms rather differently because we now aren't interested in it pointing to the same location.

73
00:05:06,340 --> 00:05:10,060
‫So that position doesn't really get updated.

74
00:05:10,060 --> 00:05:18,220
‫Instead it get the a vector gets rotated and scaled or whatever it is and we end up with it looking

75
00:05:18,220 --> 00:05:19,360
‫a little bit like this.

76
00:05:19,690 --> 00:05:21,730
‫So that's actually the kind of transforming.

77
00:05:21,770 --> 00:05:27,470
‫Nation that we want to be doing because we're dealing with a velocity which is a direction vector rather

78
00:05:27,470 --> 00:05:31,400
‫than a position vector or velocity doesn't tell us anything about where we should be.

79
00:05:31,400 --> 00:05:36,740
‫It tells us about what direction we should be going in and how fast we should be going in that direction.

80
00:05:38,540 --> 00:05:45,320
‫So with that theory out of the way, let's go ahead and calculate our direction from this velocity.

81
00:05:45,320 --> 00:05:52,110
‫So we know that velocity is in global space and we want to convert it to local space.

82
00:05:52,130 --> 00:05:58,010
‫Now that means that generally speaking, we're always trying to do things the other way round, usually

83
00:05:58,010 --> 00:06:02,870
‫because we're saying, well, we've got the position, the local position of a gun, it's local transform.

84
00:06:02,870 --> 00:06:10,220
‫We want to figure out what it is in world space so that we can render it relative to everything else.

85
00:06:10,430 --> 00:06:12,650
‫Now, that's not what we're trying to do here.

86
00:06:12,650 --> 00:06:13,880
‫We're trying to do the opposite.

87
00:06:13,880 --> 00:06:17,330
‫So what we actually want is called an inverse transform.

88
00:06:17,330 --> 00:06:20,090
‫The transform goes this way from local to global.

89
00:06:20,120 --> 00:06:23,090
‫The inverse transform goes from global to local.

90
00:06:23,600 --> 00:06:27,980
‫So because we've got this global velocity, we want to inverse transform.

91
00:06:27,980 --> 00:06:32,270
‫So let's take off here and look for inverse transform.

92
00:06:32,270 --> 00:06:34,880
‫And you can see that we've got these two options.

93
00:06:34,880 --> 00:06:36,830
‫We don't care about these matrix ones.

94
00:06:36,830 --> 00:06:39,980
‫We've got the two options of for direction and location.

95
00:06:39,980 --> 00:06:45,050
‫And as I said, the difference is that a location will move that position around.

96
00:06:45,050 --> 00:06:49,610
‫The direction is just going to apply the rotation and scale.

97
00:06:49,610 --> 00:06:51,200
‫So we want the direction.

98
00:06:51,870 --> 00:06:54,030
‫We need a transform to rotate it by.

99
00:06:54,030 --> 00:06:57,900
‫We're going to have to get that transform of the pawn itself, of the character.

100
00:06:57,900 --> 00:07:00,000
‫Where is that -- in the world.

101
00:07:00,120 --> 00:07:05,040
‫So let's go ahead and grab off the -- owner and look for the transform.

102
00:07:06,120 --> 00:07:08,070
‫Property get actor transform.

103
00:07:08,070 --> 00:07:09,090
‫That would be the one.

104
00:07:09,270 --> 00:07:16,440
‫We'll pipe that in to our inverse transform direction and we've got ourselves a new vector out of this.

105
00:07:17,790 --> 00:07:22,110
‫So the next step would be to get the rotation of this vector.

106
00:07:22,110 --> 00:07:25,420
‫So we'll look going to look for rotation.

107
00:07:25,440 --> 00:07:27,030
‫See what we can find.

108
00:07:27,330 --> 00:07:31,530
‫We've got find look rotation, make rotation from axes to cotangent.

109
00:07:31,560 --> 00:07:35,340
‫Now, let's have a look at rotation from X vector.

110
00:07:36,340 --> 00:07:42,670
‫If you read the documentation here it says it's going to set the your and pitch from this vector but

111
00:07:42,670 --> 00:07:45,790
‫it won't set the role because it can't get that information from a vector.

112
00:07:45,820 --> 00:07:46,590
‫That's fine.

113
00:07:46,600 --> 00:07:48,700
‫We don't care about the role in this case.

114
00:07:48,700 --> 00:07:53,200
‫All we care about is the user because we want to see how far we're turning to the right or left.

115
00:07:53,200 --> 00:07:59,080
‫So rotation from X vector, that's the one that we want is going to return us a rotator.

116
00:07:59,500 --> 00:08:05,980
‫And for us to get just the user from that rotator, we're going to right click on the pin and hit split

117
00:08:05,980 --> 00:08:10,870
‫struct pin, which goes ahead and splits that struct into the roll pitch.

118
00:08:10,870 --> 00:08:12,750
‫And your you could do that on a vector as well.

119
00:08:12,760 --> 00:08:18,220
‫By the way, I think you can right click and let's see, I think I'd have to break the link to do it.

120
00:08:18,220 --> 00:08:19,150
‫So I'm not going to show you.

121
00:08:19,510 --> 00:08:23,200
‫But basically we've now got a user here and that's what we want to set.

122
00:08:23,200 --> 00:08:28,090
‫So again, many challenge set up the user to be the angle and test it out.

123
00:08:28,920 --> 00:08:36,240
‫So again, mini challenge set up the year to be an annual variable that goes into the blend space and

124
00:08:36,240 --> 00:08:40,080
‫test it out, try it out in the game and see if you're able to run around successfully.

125
00:08:41,250 --> 00:08:41,430
‫Okay.

126
00:08:41,430 --> 00:08:41,900
‫Welcome back.

127
00:08:41,910 --> 00:08:48,750
‫So we're going to drag in again angle, variable set angle, going to set the angle from the yaw and

128
00:08:48,750 --> 00:08:51,540
‫we're going to get the execution pin from the end of speed.

129
00:08:51,900 --> 00:08:56,820
‫I'm going to compile and save that and we're going to go over to the sandbox and hit play.

130
00:08:58,160 --> 00:08:59,780
‫And now let's try moving around.

131
00:08:59,780 --> 00:09:05,270
‫A controller would be ideal so you can test out the different gradients and the nuances.

132
00:09:05,270 --> 00:09:10,280
‫And sure enough, you can see if I start moving around now, I'm able to move backwards, I'm able to

133
00:09:10,280 --> 00:09:14,840
‫move forward, sprinting and sideways and 45 degrees.

134
00:09:14,840 --> 00:09:20,510
‫All of that works based on the maths that we've calculated to calculate our angle.

135
00:09:21,640 --> 00:09:22,120
‫Great stuff.

136
00:09:22,120 --> 00:09:28,930
‫So we've learned a lot about transforms and vectors and how you can transform vectors, both inverse

137
00:09:28,930 --> 00:09:30,400
‫and forward transforming.

138
00:09:30,490 --> 00:09:36,680
‫And in the next lecture, we're going to look at fixing this foot sliding that we are seeing here.

139
00:09:36,700 --> 00:09:37,690
‫I'll see you there.

