‫Hello and welcome.
‫In this lecture we're going to be making rotating as well as moving platforms.
‫We're going to do this by learning about the F rotator type in C++ so that we can add a little bit more
‫of a another element to our puzzle.
‫Let's dive in and find out how this works.
‫So let's talk about filling out our rotate platform function.
‫So in order to do rotation, it's very similar to the way we do location and we've got very similar
‫functions.
‫We can call instead of calling, get actor location, we can call, get actor rotation instead.
‫And if I go and put parentheses on the end of this line and just hover over the function, then Visual
‫Studio IntelliSense is going to show us that the return value from this is an F rotator.
‫We've used the F vector when working with locations and we've talked about rotators in the previous
‫sections.
‫So let's have a look at putting this F rotator into a local variable.
‫So the type is going to be F rotator and we're going to call this the current rotation equal to the
‫get actor rotation, put a semicolon at the end of the line.
‫I'm also going to delete the log statement because we no longer need that.
‫And then what we want to do is essentially exactly the same as we've done with the platform velocity,
‫which is a kind of rotational velocity multiplied by the delta time added to the current rotation.
‫So what should that rotational velocity be?
‫Well, that's where we want to go over to the header file and add a new U property.
‫So I'm going to add it underneath the move distance and I'm going to have a U property edit anywhere
‫and then give it a category equal to this time I'm going to call it rotation and I'm going to change
‫the category name from moving platform to moving in both instances.
‫So we're going to have a category for moving, a category for rotation.
‫Then underneath the property we're going to put an F rotator called rotation velocity and we're not
‫going to give it a default value here because by default I don't want any of our platforms to rotate.
‫So the default value is going to be 000, and that's just what we need.
‫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
‫and use that member variable in our rotate platform function.
‫So what we want to do is current rotation equal to the current rotation plus rotation velocity multiplied
‫by Delta time and put a semicolon on the end of the line.
‫And now the final piece of the puzzle is to set our actor to that new rotation.
‫So exactly as you would expect, maybe a little mini challenge for you, in fact, is how would you
‫go ahead and do that yourself?
‫Well, what we would use is the set actor rotation function and we would pass in an argument of current
‫rotation like so and put a semicolon on the end of the line.
‫Now, unfortunately, it doesn't work quite as simply as this.
‫It's come to my attention, some students have pointed out in the teaching assistant.
‫Dan, thank you very much, has pointed out that just adding rotations together like this won't always
‫work because of some of the complications around rotations wrapping around themselves.
‫If you go all the way to -90 degrees of rotation, at some point you need to flip over into plus 90
‫degrees of rotation and so on and so forth.
‫So a better way around this, instead of setting the active rotation, is to call the add actor local
‫rotation.
‫And you can notice here that there are a few add actor local trans form as well and local offset that's
‫for location.
‫So you can use that as well instead of adding location.
‫However, there aren't the same sort of problems that we're going to encounter in the edge cases around
‫rotation.
‫So what I would recommend you do is add actor local rotation here instead and then you just put in the
‫rotation velocity multiplied by the Delta time and it does the rest of this code automatically for you.
‫So we can just go ahead and get rid of those lines.
‫And you've got a straightforward addition to the local rotation going on here, and you can also get
‫rid of this getting the current rotation because we no longer need that either.
‫So let's head over into the editor and hit the compile button.
‫And when that's done, close the log.
‫Let's select one of the platforms in the level any of them will do and have a look at the categories.
‫So we've got moving and we've got rotation and we've got the rotation velocity then.
‫So I want to rotate this platform around its Z axis at probably let's say about 90 degrees per second.
‫So it takes 4 seconds to do a full rotation.
‫Let's go ahead and hit play.
‫And there you go.
‫We've got a rotating and moving platform.
‫So unlike the mechanism of the moving platform, we don't have to worry about our rotating platform
‫actually going backwards and forwards.
‫If you want it to do that, that's a possible extension you could think of.
‫But for me that is enough because we just wanting these things to keep going round and round in the
‫same direction.
‫So let me go and remove the rotation from this particular platform because we don't want this platform
‫to be rotating.
‫So I like to challenge you to make a beep rotating platform, basically yet another variant for us to
‫use and find an appropriate mesh.
‫I would go with something that's vaguely circular so that it makes sense as a rotating platform and
‫give it a default rotation speed and place it in the level to create a bit of a rotating platform puzzle
‫for you to get across.
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫So we're going to go ahead into our content drawer and going to look for the C++ classes, Obstacle
‫Assault and right click the moving platform to create a blueprint class device derived from this.
‫We're going to call it the BP underscore rotating platform and we're going to put it in the route of
‫content and create blueprint class.
‫Once the editor pops up, let's dock it to our main window.
‫I'm going to close my content browser that seems to want to pop up every time, and I'm going to go
‫to our main level and go to the island with all our test assets on right click.
‫Go here and let's see if there's anything that looks good.
‫I like the look of these platforms here.
‫If I right click on it or if I just click on it, then the mesh being used here in the static mesh is
‫SM platform A So let's look for that one.
‫Let's go over to our blueprints, open up the content, draw, go to all and then search for platform
‫underscore M, underscore A and then we've got the mesh, which is this one here.
‫Second one along for me.
‫I'm going to drag it in to our viewport to have our platform.
‫Now let's see where this is centered.
‫Is it centered on the middle?
‫Yes, it is, which is good and important because we do need it to rotate around the middle.
‫Otherwise this circular platform is going to look a little bit strange.
‫We can also scale it up a little bit in the x and Y dimensions to make this platform a bit larger and
‫we can go to the class defaults to remove any platform velocity because we don't want it to move and
‫set the move distance down to zero potentially and then look at the rotation section and set that to
‫about well, we tried 90 degrees per second and that seemed fairly reasonable.
‫So let's go ahead and save this rotating platform.
‫We'll go to our main level and then right click on the little floating island where we've got our level
‫set up our puzzle, click, go here.
‫Then on top of this island, I want to place down our new blueprint.
‫So let's cancel out the search, go to root of content and find our rotating platform and place it in
‫the level.
‫And instantly I'm seeing I actually want it to be a little bit bigger.
‫So let's go ahead and scale it up.
‫A few more units, maybe three times should be good.
‫Let's go and have a look.
‫Now, I think it could be even larger still, so I'm going to scale up a bit more so that essentially
‫in the X and Y it's five times larger than it was originally.
‫Okay, that's a nice wide rotating disk and might be quite challenging for us to get across.
‫So I'm going to duplicate these using alt and drag to make a few of them across the platform and try
‫and place them appropriately and then alt drag a few more.
‫So that we've got a nice little set of puzzles here for us to try and get across.
‫So just wiggled them around a bit until I could get them pretty much edge to edge.
‫And here's where being able to have a game mode really helps because we can right click near the platforms
‫and the click play from here, and here are all of our rotating platforms for us to step upon.
‫And it's a little bit of a challenge now for us to find our way across these moving platforms nice and
‫easy.
‫Now there's this dead zone in the middle which we could try and blank out, but it's actually quite
‫hard to get and stay in the dead zone, so I'm not going to try and put anything in there specifically
‫to try and stop that.
‫But you can see there you go.
‫It's a doable challenge we can get across, but it's a little bit tricky and that is fun.
‫Great stuff.
‫So in this lecture, we've seen how to make rotating platforms by learning about a new type, the F
‫rotator and how we can use it to set the rotation of our actors.
‫I'll see you in the next lecture.