﻿1
00:00:04,390 --> 00:00:05,560
‫Hello and welcome.

2
00:00:05,560 --> 00:00:11,230
‫In this lecture we're going to be making rotating as well as moving platforms.

3
00:00:11,230 --> 00:00:17,560
‫We're going to do this by learning about the F rotator type in C++ so that we can add a little bit more

4
00:00:17,560 --> 00:00:20,950
‫of a another element to our puzzle.

5
00:00:20,950 --> 00:00:23,950
‫Let's dive in and find out how this works.

6
00:00:24,280 --> 00:00:28,300
‫So let's talk about filling out our rotate platform function.

7
00:00:28,510 --> 00:00:34,930
‫So in order to do rotation, it's very similar to the way we do location and we've got very similar

8
00:00:34,930 --> 00:00:35,350
‫functions.

9
00:00:35,350 --> 00:00:43,240
‫We can call instead of calling, get actor location, we can call, get actor rotation instead.

10
00:00:43,240 --> 00:00:49,270
‫And if I go and put parentheses on the end of this line and just hover over the function, then Visual

11
00:00:49,270 --> 00:00:55,630
‫Studio IntelliSense is going to show us that the return value from this is an F rotator.

12
00:00:55,630 --> 00:01:02,110
‫We've used the F vector when working with locations and we've talked about rotators in the previous

13
00:01:02,110 --> 00:01:02,830
‫sections.

14
00:01:02,830 --> 00:01:07,090
‫So let's have a look at putting this F rotator into a local variable.

15
00:01:07,090 --> 00:01:14,920
‫So the type is going to be F rotator and we're going to call this the current rotation equal to the

16
00:01:14,920 --> 00:01:17,680
‫get actor rotation, put a semicolon at the end of the line.

17
00:01:17,680 --> 00:01:20,260
‫I'm also going to delete the log statement because we no longer need that.

18
00:01:20,260 --> 00:01:25,450
‫And then what we want to do is essentially exactly the same as we've done with the platform velocity,

19
00:01:25,450 --> 00:01:31,810
‫which is a kind of rotational velocity multiplied by the delta time added to the current rotation.

20
00:01:31,810 --> 00:01:35,470
‫So what should that rotational velocity be?

21
00:01:35,470 --> 00:01:39,520
‫Well, that's where we want to go over to the header file and add a new U property.

22
00:01:39,520 --> 00:01:48,760
‫So I'm going to add it underneath the move distance and I'm going to have a U property edit anywhere

23
00:01:49,300 --> 00:01:55,900
‫and then give it a category equal to this time I'm going to call it rotation and I'm going to change

24
00:01:55,900 --> 00:02:00,100
‫the category name from moving platform to moving in both instances.

25
00:02:00,100 --> 00:02:03,850
‫So we're going to have a category for moving, a category for rotation.

26
00:02:03,850 --> 00:02:11,800
‫Then underneath the property we're going to put an F rotator called rotation velocity and we're not

27
00:02:11,800 --> 00:02:16,780
‫going to give it a default value here because by default I don't want any of our platforms to rotate.

28
00:02:16,780 --> 00:02:21,190
‫So the default value is going to be 000, and that's just what we need.

29
00:02:21,280 --> 00:02:26,470
‫So I'm going to put a semicolon on the end of the line here and now we can go back over to the C++ file

30
00:02:26,470 --> 00:02:31,330
‫and use that member variable in our rotate platform function.

31
00:02:31,330 --> 00:02:42,610
‫So what we want to do is current rotation equal to the current rotation plus rotation velocity multiplied

32
00:02:42,610 --> 00:02:46,750
‫by Delta time and put a semicolon on the end of the line.

33
00:02:46,900 --> 00:02:52,660
‫And now the final piece of the puzzle is to set our actor to that new rotation.

34
00:02:52,660 --> 00:02:58,300
‫So exactly as you would expect, maybe a little mini challenge for you, in fact, is how would you

35
00:02:58,300 --> 00:03:00,130
‫go ahead and do that yourself?

36
00:03:01,970 --> 00:03:10,430
‫Well, what we would use is the set actor rotation function and we would pass in an argument of current

37
00:03:10,430 --> 00:03:14,930
‫rotation like so and put a semicolon on the end of the line.

38
00:03:14,960 --> 00:03:19,160
‫Now, unfortunately, it doesn't work quite as simply as this.

39
00:03:19,310 --> 00:03:22,190
‫It's come to my attention, some students have pointed out in the teaching assistant.

40
00:03:22,190 --> 00:03:27,920
‫Dan, thank you very much, has pointed out that just adding rotations together like this won't always

41
00:03:27,920 --> 00:03:32,710
‫work because of some of the complications around rotations wrapping around themselves.

42
00:03:32,720 --> 00:03:38,870
‫If you go all the way to -90 degrees of rotation, at some point you need to flip over into plus 90

43
00:03:38,870 --> 00:03:41,070
‫degrees of rotation and so on and so forth.

44
00:03:41,090 --> 00:03:49,580
‫So a better way around this, instead of setting the active rotation, is to call the add actor local

45
00:03:49,580 --> 00:03:50,540
‫rotation.

46
00:03:50,540 --> 00:03:57,110
‫And you can notice here that there are a few add actor local trans form as well and local offset that's

47
00:03:57,110 --> 00:03:57,830
‫for location.

48
00:03:57,830 --> 00:04:00,920
‫So you can use that as well instead of adding location.

49
00:04:00,920 --> 00:04:05,840
‫However, there aren't the same sort of problems that we're going to encounter in the edge cases around

50
00:04:05,840 --> 00:04:06,380
‫rotation.

51
00:04:06,380 --> 00:04:12,800
‫So what I would recommend you do is add actor local rotation here instead and then you just put in the

52
00:04:12,800 --> 00:04:19,670
‫rotation velocity multiplied by the Delta time and it does the rest of this code automatically for you.

53
00:04:19,670 --> 00:04:22,100
‫So we can just go ahead and get rid of those lines.

54
00:04:22,100 --> 00:04:27,560
‫And you've got a straightforward addition to the local rotation going on here, and you can also get

55
00:04:27,560 --> 00:04:31,670
‫rid of this getting the current rotation because we no longer need that either.

56
00:04:31,850 --> 00:04:35,450
‫So let's head over into the editor and hit the compile button.

57
00:04:35,450 --> 00:04:37,520
‫And when that's done, close the log.

58
00:04:37,640 --> 00:04:42,530
‫Let's select one of the platforms in the level any of them will do and have a look at the categories.

59
00:04:42,530 --> 00:04:46,970
‫So we've got moving and we've got rotation and we've got the rotation velocity then.

60
00:04:46,970 --> 00:04:54,890
‫So I want to rotate this platform around its Z axis at probably let's say about 90 degrees per second.

61
00:04:54,890 --> 00:04:57,920
‫So it takes 4 seconds to do a full rotation.

62
00:04:57,950 --> 00:04:59,990
‫Let's go ahead and hit play.

63
00:04:59,990 --> 00:05:00,620
‫And there you go.

64
00:05:00,620 --> 00:05:03,590
‫We've got a rotating and moving platform.

65
00:05:03,590 --> 00:05:11,270
‫So unlike the mechanism of the moving platform, we don't have to worry about our rotating platform

66
00:05:11,270 --> 00:05:13,040
‫actually going backwards and forwards.

67
00:05:13,040 --> 00:05:16,310
‫If you want it to do that, that's a possible extension you could think of.

68
00:05:16,310 --> 00:05:22,400
‫But for me that is enough because we just wanting these things to keep going round and round in the

69
00:05:22,400 --> 00:05:23,420
‫same direction.

70
00:05:23,630 --> 00:05:29,270
‫So let me go and remove the rotation from this particular platform because we don't want this platform

71
00:05:29,270 --> 00:05:30,200
‫to be rotating.

72
00:05:30,200 --> 00:05:37,640
‫So I like to challenge you to make a beep rotating platform, basically yet another variant for us to

73
00:05:37,640 --> 00:05:40,220
‫use and find an appropriate mesh.

74
00:05:40,220 --> 00:05:45,980
‫I would go with something that's vaguely circular so that it makes sense as a rotating platform and

75
00:05:45,980 --> 00:05:52,640
‫give it a default rotation speed and place it in the level to create a bit of a rotating platform puzzle

76
00:05:52,640 --> 00:05:54,380
‫for you to get across.

77
00:05:54,380 --> 00:05:56,300
‫Pause the video and have a go.

78
00:05:59,400 --> 00:05:59,700
‫Okay.

79
00:05:59,700 --> 00:06:00,660
‫Welcome back.

80
00:06:00,690 --> 00:06:08,610
‫So we're going to go ahead into our content drawer and going to look for the C++ classes, Obstacle

81
00:06:08,610 --> 00:06:14,270
‫Assault and right click the moving platform to create a blueprint class device derived from this.

82
00:06:14,280 --> 00:06:21,060
‫We're going to call it the BP underscore rotating platform and we're going to put it in the route of

83
00:06:21,060 --> 00:06:23,430
‫content and create blueprint class.

84
00:06:23,430 --> 00:06:27,180
‫Once the editor pops up, let's dock it to our main window.

85
00:06:27,180 --> 00:06:33,180
‫I'm going to close my content browser that seems to want to pop up every time, and I'm going to go

86
00:06:33,180 --> 00:06:39,390
‫to our main level and go to the island with all our test assets on right click.

87
00:06:40,260 --> 00:06:44,490
‫Go here and let's see if there's anything that looks good.

88
00:06:44,490 --> 00:06:48,600
‫I like the look of these platforms here.

89
00:06:48,600 --> 00:06:55,710
‫If I right click on it or if I just click on it, then the mesh being used here in the static mesh is

90
00:06:55,740 --> 00:06:59,760
‫SM platform A So let's look for that one.

91
00:06:59,760 --> 00:07:07,620
‫Let's go over to our blueprints, open up the content, draw, go to all and then search for platform

92
00:07:07,620 --> 00:07:14,710
‫underscore M, underscore A and then we've got the mesh, which is this one here.

93
00:07:15,270 --> 00:07:16,890
‫Second one along for me.

94
00:07:16,980 --> 00:07:21,480
‫I'm going to drag it in to our viewport to have our platform.

95
00:07:21,480 --> 00:07:24,090
‫Now let's see where this is centered.

96
00:07:24,090 --> 00:07:25,860
‫Is it centered on the middle?

97
00:07:25,860 --> 00:07:30,840
‫Yes, it is, which is good and important because we do need it to rotate around the middle.

98
00:07:30,840 --> 00:07:34,560
‫Otherwise this circular platform is going to look a little bit strange.

99
00:07:34,770 --> 00:07:43,680
‫We can also scale it up a little bit in the x and Y dimensions to make this platform a bit larger and

100
00:07:43,680 --> 00:07:51,180
‫we can go to the class defaults to remove any platform velocity because we don't want it to move and

101
00:07:51,360 --> 00:07:57,480
‫set the move distance down to zero potentially and then look at the rotation section and set that to

102
00:07:57,480 --> 00:08:01,440
‫about well, we tried 90 degrees per second and that seemed fairly reasonable.

103
00:08:01,440 --> 00:08:04,050
‫So let's go ahead and save this rotating platform.

104
00:08:04,170 --> 00:08:12,270
‫We'll go to our main level and then right click on the little floating island where we've got our level

105
00:08:12,270 --> 00:08:14,360
‫set up our puzzle, click, go here.

106
00:08:14,880 --> 00:08:21,930
‫Then on top of this island, I want to place down our new blueprint.

107
00:08:21,930 --> 00:08:28,050
‫So let's cancel out the search, go to root of content and find our rotating platform and place it in

108
00:08:28,050 --> 00:08:28,410
‫the level.

109
00:08:28,410 --> 00:08:31,050
‫And instantly I'm seeing I actually want it to be a little bit bigger.

110
00:08:31,200 --> 00:08:33,630
‫So let's go ahead and scale it up.

111
00:08:33,630 --> 00:08:37,500
‫A few more units, maybe three times should be good.

112
00:08:37,500 --> 00:08:38,850
‫Let's go and have a look.

113
00:08:38,850 --> 00:08:44,940
‫Now, I think it could be even larger still, so I'm going to scale up a bit more so that essentially

114
00:08:44,940 --> 00:08:48,630
‫in the X and Y it's five times larger than it was originally.

115
00:08:48,660 --> 00:08:54,330
‫Okay, that's a nice wide rotating disk and might be quite challenging for us to get across.

116
00:08:54,330 --> 00:09:02,190
‫So I'm going to duplicate these using alt and drag to make a few of them across the platform and try

117
00:09:02,190 --> 00:09:07,860
‫and place them appropriately and then alt drag a few more.

118
00:09:08,550 --> 00:09:14,320
‫So that we've got a nice little set of puzzles here for us to try and get across.

119
00:09:14,340 --> 00:09:18,570
‫So just wiggled them around a bit until I could get them pretty much edge to edge.

120
00:09:18,570 --> 00:09:24,540
‫And here's where being able to have a game mode really helps because we can right click near the platforms

121
00:09:24,540 --> 00:09:30,450
‫and the click play from here, and here are all of our rotating platforms for us to step upon.

122
00:09:30,450 --> 00:09:37,320
‫And it's a little bit of a challenge now for us to find our way across these moving platforms nice and

123
00:09:37,320 --> 00:09:37,620
‫easy.

124
00:09:37,620 --> 00:09:41,370
‫Now there's this dead zone in the middle which we could try and blank out, but it's actually quite

125
00:09:41,370 --> 00:09:47,190
‫hard to get and stay in the dead zone, so I'm not going to try and put anything in there specifically

126
00:09:47,190 --> 00:09:48,930
‫to try and stop that.

127
00:09:49,350 --> 00:09:50,280
‫But you can see there you go.

128
00:09:50,280 --> 00:09:55,080
‫It's a doable challenge we can get across, but it's a little bit tricky and that is fun.

129
00:09:55,080 --> 00:09:55,590
‫Great stuff.

130
00:09:55,590 --> 00:10:01,270
‫So in this lecture, we've seen how to make rotating platforms by learning about a new type, the F

131
00:10:01,290 --> 00:10:05,940
‫rotator and how we can use it to set the rotation of our actors.

132
00:10:05,940 --> 00:10:07,530
‫I'll see you in the next lecture.

